A three-party commit-reveal RNG for casino and game operators. Your server and the RAIN node each lock in a secret before either sees the other’s, and the player adds their own seed to every round. The result exists only once all three meet, so even the casino and RAIN together can’t predict or steer it. Every spin ships with a /verify link the player checks in their own browser.
import { NodeClient } from "./rain-rng.mjs"; // rainrng.xyz/sdk const rng = new NodeClient({ baseUrl: "https://api.rainrng.xyz", apiKey: process.env.RAIN_API_KEY, // server-side only operatorPubKey: NODE_PUBKEY, // pin it }); // one call per bet — the player's own seed goes in const r = await rng.round(JSON.stringify({ bet: 1 }), 37, { clientSeed: player.seed }); // typed or generated on their device r.value; // → 25n (0..36, roulette) rng.verifyUrl(r.k, r.sessionId); // → public proof link
Read live from api.rainrng.xyz when this page loads. These endpoints are public and need no key.
Operator and node each commit to a secret before they can see the other’s. The player then adds a seed of their own to each round. The result is fixed only when all three meet: the node can’t pick a favourable seed, your server can’t, and since the player’s seed arrives after both are locked, the two of them together can’t either.
The node publishes houseSeedCommit and the root of a hash chain of 4,096 rounds, all signed with its ed25519 key.
After seeing the terms, your server sends its own seed and chain root. The session seed mixes both: keccak(houseSeed, playerSeed, sessionId).
Your server sends its chain link for round k together with the player’s seed. The node checks the link, persists both to Postgres before replying, then reveals its own link.
The round value r_k seeds an SP 800-90A HMAC-DRBG (or ChaCha20). Outcomes use unbiased rejection sampling. Every round gets a public proof.
Its chain is committed and signed before the session. A wrong hRev fails the chain check in your SDK and in the player’s browser.
Its chain is committed too, and each round is written to Postgres before the node reveals. A round can’t be replayed with a different bet or seed: the node answers 409.
They still don’t know the player’s seed when the chains are locked. Once the seed is in, the result is fixed and the player recomputes it.
You generate the API key yourself and send us only its SHA-256 fingerprint. The node stores fingerprints only, so the key itself never leaves your servers.
# generate on YOUR server — keep $KEY in your secret store KEY=$(openssl rand -hex 32) # send RAIN only the fingerprint (64 hex chars) echo -n "$KEY" | sha256sum # → f2e9…5fb3 (cannot be reversed into the key)
# once RAIN confirms your fingerprint is loaded: curl -s -o /dev/null -w "%{http_code}\n" \ -X POST https://api.rainrng.xyz/v2/terms \ -H "authorization: Bearer $KEY" \ -H "content-type: application/json" -d '{}' # 200 → connected 401 → key/fingerprint mismatch
# one file, no npm, Node ≥ 20 curl -O https://rainrng.xyz/sdk/rain-rng.mjs import { NodeClient } from "./rain-rng.mjs"; const rng = new NodeClient({ baseUrl: "https://api.rainrng.xyz", apiKey: process.env.RAIN_API_KEY, operatorPubKey: "0x0e2fa44c…0e3d", // pin onRecovered: (r) => settleBet(r), // lost reveal, recovered }); // clientSeed: the player's string for this round const r = await rng.round(betJson, 37, { clientSeed }); r.clientSeed; // echoed back, shown on /verify
# every protected call carries the same header Authorization: Bearer <RAIN_API_KEY> # WebSocket: header on upgrade, or first frame wss://api.rainrng.xyz/v2/ws {"type":"auth","key":"<RAIN_API_KEY>"} # order per session (the SDK does this for you) POST /v2/terms → POST /v2/open/:termsId → POST /v2/reveal k=1,2,3… # reveal body (clientSeed: 1–256 chars, the player's) {"v":2,"sessionId":"0x…","k":1,"decision":"…","pRev":"0x…", "clientSeed":"player-chosen string"} # errors 401 unauthorized 403 other operator's session 400 client_seed_required (node in trustless-only mode) 404 session_not_found → open a new session 409 conflict → same k re-sent with another bet/seed 429 rate limited (honor Retry-After) 503 self-test failed
crypto.randomUUID() in their browser), let them edit it, and pass it as clientSeed. Changing it is allowed between rounds; it is bound to each round the moment it is sent./verify is public.round() opens one; after 4,096 rounds, or if the node forgot it, the SDK opens a fresh one by itself. No gas, no checkpoint.round() fetches the same result first and hands it to onRecovered./verify/:sid/:k under a “Powered by RAIN RNG” badge.JSON over HTTPS, with the same envelopes over WebSocket. Base URL https://api.rainrng.xyz.
| method | path | access | description |
|---|---|---|---|
| POST | /v2/terms | api key | Node-signed terms: houseSeedCommit, houseChainRoot, chain length. |
| POST | /v2/open/:termsId | api key | Operator seed and chain root; opens the session and binds it to your operator id. |
| POST | /v2/reveal | api key | Commit for round k with optional clientSeed (the player’s). The node persists both, then returns hRev_k. Idempotent on an identical replay; a different bet or seed → 409. |
| GET | /v2/reveal/:sid/:k | api key | Re-fetch an already-revealed round, e.g. after a client crash. |
| WS | /v2/ws | api key | The same operations as JSON envelopes over one connection, for the lowest latency. |
| GET | /verify/:sid/:k | public | Proof for one round: both reveals, the session seed and r_k. CORS *. |
| GET | /healthz | public | Liveness, store, auth mode, rate limit, self-test state. |
| GET | /selftest | public | Runs known-answer tests now. Any failure switches output off (503) until fixed. |
| GET | /metrics | public | Prometheus text: rounds, latency, 401/403/429 per operator. |
| GET | / | public | Node identity: operator id, ed25519 public key, chain length, endpoint list. |
Paste a proof link, or a session id and round number. The page fetches the public data from the node, then recomputes the result in your browser with rain-verify.mjs: both hash chains, your seed, the outcome. It does not take the node’s word for anything.
Built so that a bug, a crash or a bad actor on either side shows up in the proof and can’t pass silently.
Node and operator each draw 256 bits from the OS CSPRNG and commit first. The player’s seed is mixed into every round on top. No seed comes from the clock or a fixed value, and no party sets the result alone, or with one other.
Every reveal is written to Postgres before the node answers. After a restart or a client crash, each round re-fetches identically and can never be redrawn.
Terms are signed with the node’s ed25519 key. Clients pin the public key, so a spoofed node is rejected.
Keys are stored as SHA-256 hashes only and compared in constant time. A session belongs to the operator that opened it. Any other operator gets 403.
Each operator gets its own token bucket, 429 with Retry-After, and its own metrics.
Known-answer tests for keccak, SHA-256, HMAC-DRBG and ChaCha20 run at startup, every 24 h and on demand. If one fails, the node stops issuing rounds.
Our own pre-testing, run on the same code the node runs, and organised to the GLI-19 v3.0 structure.
Dieharder 3.31.1 full battery, stream input. ChaCha20 90 passed / 5 weak; HMAC-DRBG 83 passed / 3 weak.
NIST SP 800-22 result lines in range, for each mechanism (1,000 × 10⁶ bits).
TestU01 SmallCrush statistics passed, for both mechanisms.
Scaled game outcomes per game (dice, roulette, coin, reels) checked with χ², KS, serial correlation and runs tests.
One spin over WAN, sequential, coast-to-coast path (~95 ms RTT). 0 errors in 4,000 rounds.
Same path with WebSocket and pipelining, at a harsh 60 ms animation.
With a real reel animation of 1 s or more, the reveal is already waiting when the player looks.