Info
Securing requests
Every request of this API, ours to your wallet and yours to us, carries an HMAC-SHA256 signature made with one client key.
One key for both directions#
You get one client id and one client secret. We sign every call we make to your wallet with them; you sign every call you make to us with the same pair. The id looks like acme-client-0123456789ab (your operator code, -client- and 12 hex characters). The secret is 32 random bytes written as base64url; it is shown once, when the key is created or rotated, and we store it encrypted. Keep it out of logs and source code.
Headers#
| Header | Value |
|---|---|
X-OE-Client-ID | The client id. Tells the receiver which secret to use. |
X-OE-Client-TS | The time of signing: unix seconds, UTC, decimal digits only (1–12 digits). |
X-OE-Client-Signature | The signature: 64 hex characters. We send lower case and accept either case. |
Content-Type | application/json; charset=utf-8 |
The string to sign#
signature = hex( HMAC-SHA256( key = UTF-8 bytes of the client secret,
message = TS + request-target + body ) )- TS is the exact text of the
X-OE-Client-TSheader. - request-target is the path and, if there is one,
?and the query string of the URL the sender called: everything after the host, byte for byte. Nothing is decoded, re-encoded, sorted or normalised. - body is the raw body bytes exactly as sent. A request without a body signs
TS + request-targetalone (this API has no such request: every call is aPOSTwith a JSON body). - The parts are joined with nothing in between.
For the calls we make, the request-target is the path of your wallet URL followed by /<method>: with {wallet-url} = https://wallet.example.com/oe, a withdraw is signed over /oe/withdraw. We send no query string. If a proxy in front of your wallet rewrites paths, verify against the path we called, not the one your application sees.
A worked example#
Vector A below, taken apart. These are the exact inputs; the signature is what our servers compute for them.
| Part | Value |
|---|---|
| Client secret | oe-test-secret-0123456789abcdef |
TS (X-OE-Client-TS) | 1767225600 |
| request-target | /wallet/withdraw |
| body | the compact JSON below, exactly these bytes |
{"user_id":"u_829301","currency":"USD","amount":5320,"provider":"oe_originals","provider_tx_id":"0192f3c1-7a5b-7cc3-9d2e-1f2a3b4c5d6e:debit","game":"dice","action":"bet","action_id":"0192f3c1-7a5b-7cc3-9d2e-1f2a3b4c5d6e","session_token":"5f2b8c1d9e3a4f60718293a4b5c6d7e8f9012345678901234567890123456789","platform":"mobile"}The message is the three parts joined:
1767225600/wallet/withdraw{"user_id":"u_829301","currency":"USD","amount":5320,"provider":"oe_originals","provider_tx_id":"0192f3c1-7a5b-7cc3-9d2e-1f2a3b4c5d6e:debit","game":"dice","action":"bet","action_id":"0192f3c1-7a5b-7cc3-9d2e-1f2a3b4c5d6e","session_token":"5f2b8c1d9e3a4f60718293a4b5c6d7e8f9012345678901234567890123456789","platform":"mobile"}and its HMAC-SHA256 with the secret, as hex, is the header value:
X-OE-Client-ID: acme-client-0123456789ab
X-OE-Client-TS: 1767225600
X-OE-Client-Signature: 40e931ac46e4bd4641a7860fccaa62a42ddd9fdd6c6909f9b903616d8232567aNode.js sample#
Signing, checking our calls, and calling one of our methods. Our test suite runs this exact code against the test vectors.
// Signing and verifying requests of the Operator API. Node.js 18 or later; no dependencies.
import { Buffer } from 'node:buffer';
import { createHmac, timingSafeEqual } from 'node:crypto';
/**
* The X-OE-Client-Signature value: hex HMAC-SHA256 over TS, the request target and the body.
* secret your client secret (a string; its UTF-8 bytes are the key)
* ts the X-OE-Client-TS value you send (unix seconds)
* target the path and query of the URL you call, exactly as sent: '/v4/freebets/create'
* body the exact body string or bytes you send; null for a request without a body
*/
export function sign(secret, ts, target, body) {
const hmac = createHmac('sha256', Buffer.from(secret, 'utf8'));
hmac.update(String(ts));
hmac.update(target);
if (body !== null) hmac.update(typeof body === 'string' ? Buffer.from(body, 'utf8') : body);
return hmac.digest('hex');
}
/**
* Checks a call we make to your wallet. Use the raw body bytes as received (before any JSON
* parsing) and the path you serve the call on, e.g. '/wallet/withdraw'.
* Returns false for anything wrong: answer such a call with {"code": 413}.
*/
export function verify(secret, headers, target, rawBody, nowSec = Math.floor(Date.now() / 1000)) {
const ts = headers['x-oe-client-ts'];
const signature = headers['x-oe-client-signature'];
if (typeof ts !== 'string' || !/^\d{1,12}$/.test(ts)) return false;
if (typeof signature !== 'string' || !/^[0-9a-fA-F]{64}$/.test(signature)) return false;
if (Math.abs(nowSec - Number(ts)) > 300) return false;
const expected = Buffer.from(sign(secret, ts, target, rawBody), 'hex');
return timingSafeEqual(Buffer.from(signature, 'hex'), expected);
}
/**
* Calls one of our free-bet methods. apiUrl is the {api-url} you were given (it may include a
* path, e.g. 'https://api.example.com/rgs'); path is e.g. '/v4/freebets/create'.
*/
export async function callApi(apiUrl, path, clientId, secret, payload) {
const url = new URL(apiUrl.replace(/\/$/, '') + path);
const target = url.pathname + url.search;
const body = JSON.stringify(payload);
const ts = String(Math.floor(Date.now() / 1000));
const res = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8',
'X-OE-Client-ID': clientId,
'X-OE-Client-TS': ts,
'X-OE-Client-Signature': sign(secret, ts, target, body),
},
body,
});
return res.json(); // always HTTP 200: read the outcome from `code`
}Checking the calls we make#
- Read the raw body bytes before any JSON parsing; a parsed and printed body is not the same bytes.
- Find the secret by
X-OE-Client-ID. During a key rotation you hold two (see below). - Recompute the signature over the TS header, the path we called and the raw body, and compare it with
X-OE-Client-Signatureas bytes, in constant time. - Refuse a TS more than 300 seconds away from your clock.
- On any failure answer
{"code": 413}with HTTP status 200. We treat a 413 as a configuration fault and raise an alert on our side.
What we answer to a wrong signature#
We check the calls you make in this order, before the body is parsed:
| Check | Code if it fails |
|---|---|
All three headers present once and well-formed: X-OE-Client-ID 1–128 characters, X-OE-Client-TS 1–12 digits, X-OE-Client-Signature 64 hex characters. | 401. Nothing was looked up yet. |
The key exists, is a client key, is active or still inside a rotation's overlap, and your IP address is on its allowlist (if it has one); X-OE-Client-TS is within 300 seconds of our clock; the signature matches. | 413, one answer for every cause, so that a caller cannot probe key ids, clocks or allowlists. |
Our answers are not signed: TLS protects them. Your answers to our calls are not signature-checked either.
Test vectors#
Use these to test your implementation. signature is the header value for a request with that target (uri), body (the exact characters of the JSON string, UTF-8 encoded; null means no body), TS and secret. The client id is not part of the signed message. Their bodies carry provider oe_originals: test data, not the provider key of this deployment (banzaro).
[
{
"name": "A: a call we make (withdraw), no query",
"clientId": "acme-client-0123456789ab",
"secret": "oe-test-secret-0123456789abcdef",
"ts": 1767225600,
"uri": "/wallet/withdraw",
"body": "{\"user_id\":\"u_829301\",\"currency\":\"USD\",\"amount\":5320,\"provider\":\"oe_originals\",\"provider_tx_id\":\"0192f3c1-7a5b-7cc3-9d2e-1f2a3b4c5d6e:debit\",\"game\":\"dice\",\"action\":\"bet\",\"action_id\":\"0192f3c1-7a5b-7cc3-9d2e-1f2a3b4c5d6e\",\"session_token\":\"5f2b8c1d9e3a4f60718293a4b5c6d7e8f9012345678901234567890123456789\",\"platform\":\"mobile\"}",
"signature": "40e931ac46e4bd4641a7860fccaa62a42ddd9fdd6c6909f9b903616d8232567a"
},
{
"name": "B: a call we receive, with a query string signed exactly as sent",
"clientId": "acme-client-0123456789ab",
"secret": "oe-test-secret-0123456789abcdef",
"ts": 1767225600,
"uri": "/v4/freebets?trace=a%20b&n=1",
"body": "{\"operator_freebet_id\":\"promo-7:u_829301\"}",
"signature": "73d2d6bc2e1597b5970c1223ec3ca9a3bf3131c7aec59491fc318a30eeafc472"
},
{
"name": "C: a body with non-ASCII text (UTF-8 bytes are signed)",
"clientId": "acme-client-0123456789ab",
"secret": "oe-test-secret-0123456789abcdef",
"ts": 1767225600,
"uri": "/wallet/deposit",
"body": "{\"message\":\"Виграш ₴\"}",
"signature": "bf53782af175b188b7b4404bdf8f797cbcc7f1a6419a6f30b661a53dd0e252cc"
},
{
"name": "D: no body (GET or DELETE; not used by the API today)",
"clientId": "acme-client-0123456789ab",
"secret": "oe-test-secret-0123456789abcdef",
"ts": 1767225600,
"uri": "/v4/freebets",
"body": null,
"signature": "fb670435a702d101eb33c8ccdfdf875e95481008132ba94e2b739e01c6d07ac7"
}
]Rotating the key#
A rotation creates a new client id and secret. The old key stays valid for an overlap (0 to 168 hours, 24 by default) that covers both directions:
| Direction | During the overlap | From the end of the overlap |
|---|---|---|
| Calls you make to us | Both client ids are accepted; we pick the secret by the id you send. | The old id gets 413. |
| Calls we make to you | We keep signing with the old key, so you need nothing new to keep verifying. | We sign with the new key, switching exactly when the overlap ends. |
- Install the new id and secret beside the old ones, and accept both on our calls, choosing the secret by the id we send.
- Start signing your own calls with the new key whenever you like.
- Remove the old key after the overlap.
- A second rotation during an overlap is refused: finish one first.
- Revoking a key takes effect at once for the calls you make, and within 60 seconds for the calls we make.
- Revoking the last client key stops the API for your operator in both directions: launches fail, withdraws are rolled back, and deposits are retried until a key works again.
- An IP allowlist on the key applies to the calls you make to us.