Kehittäjäportaali

Kehittäjäportaali / Operaattorin opas

Tekninen dokumentaatio englanniksi

OPERATOR GUIDE

Signing

The same one-line recipe in both directions:

Text
X-Spilvon-Operator:  <operator id>
X-Spilvon-Timestamp: <unix time in milliseconds>
X-Spilvon-Signature: hex( HMAC-SHA256( secret, timestamp + "." + METHOD + "." + path_and_query + "." + raw_body ) )
  • The timestamp is exactly 13 digits; the signature is lower-case hex.
  • METHOD is upper-case. path_and_query is exactly what was requested, e.g. /wallet/bet or /api/v1/operator/reports/daily?from=2026-12-01&to=2026-12-31.
  • raw_body is the exact bytes of the body (an empty string for GET). Verify before you parse, and never re-serialise the JSON to check a signature.
  • Reject a request whose timestamp is more than 5 minutes from your clock. Keep your servers on NTP.
  • Compare signatures in constant time.
  • Your requests to us use the API secret. Our requests to you use the wallet secret.

Authentication is the signature, not the IP address. Our wallet calls leave from Cloudflare's shared network: there is no small fixed set of addresses you could allowlist, and allowlisting all of Cloudflare protects nothing. Verify every call's signature (or choose Ed25519, section 1.1, so that nothing you store can forge our calls). You may still restrict your calls to us by IP (we can allowlist your egress addresses).

About the signed string. The four parts are joined with .. Because a . may also occur in a query string or a body, the boundary between path_and_query and raw_body is not marked unambiguously. Our paths are fixed and both sides sign the exact bytes sent, so this ambiguity on its own cannot be used to forge a call, and changing the format would break every integration, so v1 stays as it is.

The v1 string does not name the operator. X-Spilvon-Operator is a header and is not signed. With HMAC that is harmless, because each operator has its own wallet secret. With Ed25519 it is not: one SPILVON key signs the calls of every operator, so a call signed for casino A also verifies at casino B (same path, within the 5-minute window). An earlier version of this guide called the v1 format "not exploitable today"; that was wrong for Ed25519 (security audit 2026-12, finding AUD2-01). Since 2026-12 every wallet call carries operator_id inside the signed body, and every wallet must refuse a call whose operator_id is not its own (section 1.2). For Ed25519 there is also a v2 signature that names the operator inside the signed string (section 1.3); it runs next to v1, and v1 will not be retired without at least 6 months' notice in the changelog (section 10).

Test vectors: docs/signature-test-vectors.json. One of them:

Text
secret     test-secret-do-not-use-0123456789abcdef
string     1767225602000.GET./api/v1/operator/reports/daily?from=2026-12-01&to=2026-12-31.
signature  5a3530ab26f5db2a6fb06c4fba8981a57fe29aa3841d628deab0be676502d4c1
js
// Node.js
const crypto = require("node:crypto");
const sign = (secret, ts, method, path, body) => crypto.createHmac("sha256", secret).update(`${ts}.${method}.${path}.${body}`, "utf8").digest("hex");
const verify = (secret, ts, method, path, body, sig) => {
  const a = Buffer.from(sign(secret, ts, method, path, body));
  const b = Buffer.from(String(sig));
  return a.length === b.length && crypto.timingSafeEqual(a, b) && Math.abs(Date.now() - Number(ts)) <= 300_000;
};
python
# Python
import hmac, hashlib, time
def sign(secret, ts, method, path, body):
    return hmac.new(secret.encode(), f"{ts}.{method}.{path}.{body}".encode("utf-8"), hashlib.sha256).hexdigest()
def verify(secret, ts, method, path, body, sig):
    return hmac.compare_digest(sign(secret, ts, method, path, body), sig) and abs(time.time() * 1000 - int(ts)) <= 300_000
php
// PHP
function sign($secret, $ts, $method, $path, $body) { return hash_hmac('sha256', "$ts.$method.$path.$body", $secret); }
function verify($secret, $ts, $method, $path, $body, $sig) {
  return hash_equals(sign($secret, $ts, $method, $path, $body), $sig) && abs(microtime(true) * 1000 - (int)$ts) <= 300000;
}
// raw body: file_get_contents('php://input')
go
// Go
func sign(secret, ts, method, path, body string) string {
	m := hmac.New(sha256.New, []byte(secret))
	m.Write([]byte(ts + "." + method + "." + path + "." + body))
	return hex.EncodeToString(m.Sum(nil))
}
// compare with hmac.Equal([]byte(expected), []byte(received))

1.1 Ed25519 for our wallet calls (optional, per operator)

With HMAC, whoever holds the wallet secret could sign a call that looks like ours. With Ed25519 our calls to your wallet are signed with SPILVON's private key, which never leaves our servers, and you verify them with our public key: nothing you store can forge them. Your requests to us are always HMAC-signed with your API secret.

Ask us to switch your account to ed25519 (or to both while you migrate: every call then carries both signatures). Our calls then carry:

Text
X-Spilvon-Operator:          <operator id>
X-Spilvon-Timestamp:         <unix time in milliseconds>
X-Spilvon-Key-Id:            <id of the key that signed>
X-Spilvon-Signature-Ed25519: base64( Ed25519-sign( our private key, timestamp + "." + METHOD + "." + path_and_query + "." + raw_body ) )

The signed string is exactly the HMAC one. The signature is standard base64 (with padding) of the 64-byte signature.

Our public keys are published at GET https://<spilvon-host>/.well-known/spilvon-wallet-keys.json (no authentication, also at /api/v1/public/wallet-keys). It is a JWKS (kty: OKP, crv: Ed25519, x) with the raw key (public_key_base64) and a PEM (public_key_pem) next to each entry, and a status:

statusMeaning
activeSigns every call now.
nextWill become active at the next rotation. Trust it already.
retiredSigned calls until the last rotation. Kept for a while so late retries still verify.

Key rotation. Cache the document; refetch it at least once a day, and when a call names a X-Spilvon-Key-Id you do not know (at most once a minute). Trust every key in the document; verify each call with the key its X-Spilvon-Key-Id names. We publish a new key as next at least 7 days before it becomes active.

Rules are the same as for HMAC: verify over the raw bytes before parsing, reject a timestamp more than 5 minutes from your clock, and check X-Spilvon-Operator is your own id. Then check the body's operator_id is your own id (section 1.2): with Ed25519 this is what stops a call signed for another casino. Since 2026-12 every Ed25519 call also carries X-Spilvon-Signature-Ed25519-V2 (section 1.3).

Test key and vectors: docs/signature-test-vectors.json, section ed25519 (the public RFC 8032 test key; never trust it in production). One of them:

Text
public key (base64)  11qYAYKxCrfVS/7TyWQHOg7hcvPapiMlrwIaaPcHURo=
string               1767225603000.POST./wallet/balance.{"player_id":"oyuncu-ş","currency":"TRY","token":"çğıöşü"}
signature            ItY2aGB+57fEIXsEGc6JgSjpmvHTwubUMBaiVpt9hZ2D9L6+uPo/+6z3i5yybXsatNNwU+vDN3OkUbvjAnb8DA==
js
// Node.js (built in): publicKeyPem = the key's public_key_pem
const crypto = require("node:crypto");
function verifyEd25519(publicKeyPem, ts, method, path, body, sigB64) {
  const ok = crypto.verify(null, Buffer.from(`${ts}.${method}.${path}.${body}`, "utf8"), publicKeyPem, Buffer.from(sigB64, "base64"));
  return ok && Math.abs(Date.now() - Number(ts)) <= 300_000;
}
python
# Python (pip install cryptography): public_key_b64 = the key's public_key_base64
import base64, time
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey
from cryptography.exceptions import InvalidSignature
def verify_ed25519(public_key_b64, ts, method, path, body, sig_b64):
    key = Ed25519PublicKey.from_public_bytes(base64.b64decode(public_key_b64))
    try:
        key.verify(base64.b64decode(sig_b64), f"{ts}.{method}.{path}.{body}".encode("utf-8"))
    except (InvalidSignature, ValueError):
        return False
    return abs(time.time() * 1000 - int(ts)) <= 300_000
php
// PHP 7.2+ (libsodium, built in)
function verify_ed25519($publicKeyB64, $ts, $method, $path, $body, $sigB64) {
  $pk = base64_decode($publicKeyB64, true);
  $sig = base64_decode($sigB64, true);
  if ($pk === false || $sig === false || strlen($pk) !== SODIUM_CRYPTO_SIGN_PUBLICKEYBYTES || strlen($sig) !== SODIUM_CRYPTO_SIGN_BYTES) return false;
  return sodium_crypto_sign_verify_detached($sig, "$ts.$method.$path.$body", $pk) && abs(microtime(true) * 1000 - (int)$ts) <= 300000;
}
go
// Go (standard library): pub = base64-decoded public_key_base64
func verifyEd25519(pub ed25519.PublicKey, ts, method, path, body, sigB64 string) bool {
	sig, err := base64.StdEncoding.DecodeString(sigB64)
	if err != nil || len(sig) != ed25519.SignatureSize || len(pub) != ed25519.PublicKeySize {
		return false
	}
	if !ed25519.Verify(pub, []byte(ts+"."+method+"."+path+"."+body), sig) {
		return false
	}
	t, err := strconv.ParseInt(ts, 10, 64)
	d := time.Now().UnixMilli() - t
	return err == nil && d <= 300000 && d >= -300000
}

The Node.js, Python and Go snippets are checked against the published vectors.

1.2 Every call names your operator: check it (mandatory)

Every wallet call body carries operator_id, the operator the call was signed for. It is inside the signed bytes; the X-Spilvon-Operator header is not. After you have verified the signature and parsed the body, and before you move any money:

Refuse the call with HTTP 401 and {"error":{"code":"INVALID_SIGNATURE"}} unless operator_id is exactly your own operator id. A call without operator_id is refused too.

This is mandatory for every wallet, HMAC and Ed25519 alike, and the conformance test checks it (signature.operator): we send a correctly signed jackpot credit whose body names another operator, and your wallet must refuse it and move no money. Going live requires that check to pass (section 9).

Why. With Ed25519, one SPILVON key signs the calls of every operator, and the v1 signed string does not name the operator. Any casino receiving our calls (including a sandbox account pointed at a server it controls) could take a signed call, set X-Spilvon-Operator to your id and send the identical bytes to your wallet within 5 minutes: the signature verifies with our published key. The most valuable call to replay is a jackpot credit, which by contract (section 3) needs no bet, round or session. The only thing that tells the replay apart is the signed operator_id. With HMAC the replay fails on the signature already, but the check is still required: it costs one comparison, it keeps your wallet safe if you switch to ed25519 or both later, and it protects a wallet endpoint that serves several operator accounts (a sandbox and a production account, or several brands).

js
// Node.js, after verifySpilvon(...) and JSON.parse(raw)
if (body.operator_id !== MY_OPERATOR_ID) return reply(401, { error: { code: "INVALID_SIGNATURE" } });
python
# Python
if body.get("operator_id") != MY_OPERATOR_ID:
    return reply(401, {"error": {"code": "INVALID_SIGNATURE"}})
php
// PHP
if (($body['operator_id'] ?? null) !== MY_OPERATOR_ID) { http_response_code(401); echo '{"error":{"code":"INVALID_SIGNATURE"}}'; exit; }
go
// Go: add OperatorID string `json:"operator_id"` to your request struct
if b.OperatorID != myOperatorID { send(401, fail("INVALID_SIGNATURE")); return }

The samples in docs/integration/samples/ (Node, Python, Go, PHP), the demo casino and our hosted reference wallet all do this.

Existing integrations (migration). Calls have carried operator_id since 2026-12; your wallet ignored it until now (unknown fields are ignored, section 3), so nothing broke. Add the check, deploy, then run the conformance test again. Until it passes, a new run reports signature.operator as the one failing check, with this fix and a note that it is a new requirement: sandbox play is unaffected, but the run cannot be used to go live. A passing run recorded before the check existed no longer counts for going live; run the test again. Accounts that are already live: add the check now. Ed25519 accounts are exposed until they do; ask us to switch you to hmac in the meantime if you cannot deploy it quickly.

Since 2026-12 every Ed25519 call (signing ed25519 or both) carries a second signature, made with the same key (X-Spilvon-Key-Id):

Text
X-Spilvon-Signature-Ed25519-V2: base64( Ed25519-sign( our private key,
    "SPILVON-WALLET-V2" + LF + operator_id + LF + timestamp + LF + METHOD + LF + path_and_query + LF + raw_body ) )

LF is a single line feed (\n). When you verify it, put your own operator id into the string, never one taken from the request: a call signed for another operator then simply fails verification, so the binding cannot be forgotten in the business logic. The parts are unambiguous (none of the first five can contain a line feed; the body is last), which also removes the v1 boundary ambiguity. The SPILVON-WALLET-V2 prefix keeps the two formats apart: a v1 string starts with digits, so no signature can be valid as both.

  • It is optional. Verifying v1 plus the operator_id check (section 1.2) is enough, and section 1.2 stays mandatory either way.
  • Once your wallet verifies v2, refuse calls that lack it (otherwise someone could strip the header and fall back to v1).
  • HMAC calls do not carry it: each operator's HMAC secret is its own, so an HMAC signature is already bound to one operator.

Test vectors: docs/signature-test-vectors.json, section ed25519_v2 (with a negative vector: the first signature checked as another operator must fail).

js
// Node.js (built in)
function verifyEd25519V2(publicKeyPem, myOperatorId, ts, method, path, body, sigB64) {
  const s = ["SPILVON-WALLET-V2", myOperatorId, ts, method, path].join("\n") + "\n" + body;
  return crypto.verify(null, Buffer.from(s, "utf8"), publicKeyPem, Buffer.from(sigB64, "base64"));
}
python
# Python (pip install cryptography)
def verify_ed25519_v2(public_key_b64, my_operator_id, ts, method, path, body, sig_b64):
    s = "\n".join(["SPILVON-WALLET-V2", my_operator_id, ts, method, path, body])
    try:
        Ed25519PublicKey.from_public_bytes(base64.b64decode(public_key_b64)).verify(base64.b64decode(sig_b64), s.encode("utf-8"))
        return True
    except (InvalidSignature, ValueError):
        return False
php
// PHP 7.2+ (libsodium)
function verify_ed25519_v2($publicKeyB64, $myOperatorId, $ts, $method, $path, $body, $sigB64) {
  $sig = base64_decode($sigB64, true);
  $pk = base64_decode($publicKeyB64, true);
  if ($sig === false || $pk === false || strlen($sig) !== 64 || strlen($pk) !== 32) return false;
  return sodium_crypto_sign_verify_detached($sig, "SPILVON-WALLET-V2\n$myOperatorId\n$ts\n$method\n$path\n$body", $pk);
}
go
// Go (standard library)
func verifyEd25519V2(pub ed25519.PublicKey, myOperatorID, ts, method, path, body, sigB64 string) bool {
	sig, err := base64.StdEncoding.DecodeString(sigB64)
	if err != nil || len(sig) != ed25519.SignatureSize || len(pub) != ed25519.PublicKeySize {
		return false
	}
	return ed25519.Verify(pub, []byte("SPILVON-WALLET-V2\n"+myOperatorID+"\n"+ts+"\n"+method+"\n"+path+"\n"+body), sig)
}

The Node.js, Python and Go v2 snippets are checked against the published vectors. Check the timestamp exactly as for v1.

Why not one Ed25519 key per operator? We considered it. Published in the shared key document, per-operator keys would protect nobody (you trust every key in the document) and would make that public document a list of all our casinos; published per operator, they would need every Ed25519 casino to change where it fetches keys, and multiply key rotation by the number of operators. The signed operator_id (section 1.2) and the v2 signature give the same binding without either cost.