DocsStart here
Installation
Add @galabet/fair to a Node, browser or TypeScript project and confirm it produces the published roll.
1. Install
npm install @galabet/fair
pnpm add and yarn add work the same way. The package has no dependencies of its own, so that one line is the whole install, and nothing runs a postinstall script.
You need Node 18 or newer. Signing records with Ed25519 needs 18.4.
2. Verify the Install
Save this as check.mjs and run node check.mjs.
import { SPEC_VERSION, play } from '@galabet/fair';
const { result } = await play({
game: 'dice',
serverSeed: '5c1f7d3e8a2b4c6d9e0f1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d',
clientSeed: 'galabet',
nonce: 42,
});
console.log(SPEC_VERSION, result);
GFS/1.0 56.12
If you see 56.12, you're done. That number is the same in every runtime the library supports, which is the point of it. Anything else means something between you and the package is broken, and the Dice page walks through the calculation one step at a time so you can find where.
CommonJS
The package ships both module formats. require works, though every function that touches crypto still returns a promise.
const { play } = require('@galabet/fair');
play({
game: 'roulette',
serverSeed: '5c1f7d3e8a2b4c6d9e0f1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d',
clientSeed: 'galabet',
nonce: 42,
}).then(({ result }) => console.log(result));
20
Entry Points
| Import from | What's in it |
|---|---|
@galabet/fair | Seeds, commitments, derivation, play, records, verification, signing, the crash profile |
@galabet/fair/games | The mappers on their own, such as dice, limbo, plinko, mines, deck and shuffle. The full list is in the API reference |
Most servers only need the first. The second is for when you already have floats and want a mapper without the rest, or you're building a visualisation and want to feed it numbers by hand.
TypeScript
Types are in the package. There's no @types package to add. A CommonJS TypeScript project needs one extra step, described under require() of the Package.
import type { FairRecord, GameName, GameParams, SeedPair } from '@galabet/fair';
Browsers
It's the same import, through whatever bundler you use. Two things to know first.
Web Crypto only exists on secure origins. https:// is fine and so is http://localhost, but open your page over plain http:// on a LAN address and crypto.subtle is undefined, so every call fails. That's the browser's rule, not ours.
Your bundler may also print a warning that the module crypto was externalised for browser compatibility. The library carries a fallback import for old Node versions that lack a global crypto, and bundlers notice it. Browsers never reach that line. The Galabet site's own build prints the same warning and its verifier runs entirely in the browser.
| Runtime | Minimum |
|---|---|
| Node | 18 (18.4 for signing) |
| Chrome, Edge | 113 for signing; anything current otherwise |
| Firefox | 130 for signing |
| Safari | 17 for signing |
| Bun, Deno, Cloudflare Workers | Supported |
Those minimums come from Ed25519, which reached Web Crypto late. Everything other than sign, verifySignature and the two record-signature helpers needs only HMAC and SHA-256.
