ReelbitDocs

Authentication and signing

After this page you can sign calls to Reelbit and verify the calls Reelbit makes to your wallet.

#The rule

Every call in both directions is signed with HMAC-SHA256. The string to sign is four parts joined by a newline (\n):

METHOD
path with query
timestamp
raw body bytes

#Headers

HeaderValue
X-Reelbit-Key-IdWhich secret signed the request.
X-Reelbit-TimestampUnix seconds.
X-Reelbit-SignatureLowercase hex HMAC-SHA256 of the string to sign.

#Rules for the receiver

#Separate secrets

There is one secret for calls you make to Reelbit (inbound) and another for calls Reelbit makes to you (outbound). Sandbox and production have different secrets. Two keys can be active at once, so a secret can be rotated without downtime: Reelbit issues the new key, you switch to it, then the old key is retired.

#Worked example

These inputs give one fixed signature. Use them to check your code.

InputValue
Secretrb_test_secret_do_not_use
MethodPOST
Path/balance
Timestamp1764633600
Body{"player_id":"player-1001","currency":"SC","session_id":"ses_example"}
Signaturecca69955ebd91c532a1b3923a7c30140e4b389e443f638343d66994a2611c653

Every sample below prints this signature. Each one is run in Reelbit's CI on every change, so it cannot go stale.

#Node

// Reelbit request signing: Node.js 18+ (no dependencies).
import { createHmac, timingSafeEqual } from 'node:crypto';

// The string to sign is METHOD, path with query, timestamp, then the raw body bytes, joined by "\n".
export function sign(secret, method, pathWithQuery, timestamp, rawBody) {
  return createHmac('sha256', secret)
    .update(`${method.toUpperCase()}\n${pathWithQuery}\n${timestamp}\n`)
    .update(rawBody)
    .digest('hex');
}

// Verify a request Reelbit sent to your wallet. Use the raw bytes, before parsing JSON.
export function verify(secret, method, pathWithQuery, headers, rawBody, nowSeconds = Math.floor(Date.now() / 1000)) {
  const ts = headers['x-reelbit-timestamp'];
  const given = headers['x-reelbit-signature'] ?? '';
  if (!/^\d+$/.test(ts ?? '') || Math.abs(Number(ts) - nowSeconds) > 60) return false;
  const expected = Buffer.from(sign(secret, method, pathWithQuery, ts, rawBody), 'hex');
  const actual = Buffer.from(/^[0-9a-f]{64}$/i.test(given) ? given : '', 'hex');
  return actual.length === expected.length && timingSafeEqual(actual, expected);
}

// The worked example from the docs.
const secret = 'rb_test_secret_do_not_use';
const body = Buffer.from('{"player_id":"player-1001","currency":"SC","session_id":"ses_example"}', 'utf8');
console.log(sign(secret, 'POST', '/balance', '1764633600', body));

#Python

# Reelbit request signing: Python 3.8+ (standard library only).
import hashlib
import hmac
import time


def sign(secret: str, method: str, path_with_query: str, timestamp: str, raw_body: bytes) -> str:
    """The string to sign is METHOD, path with query, timestamp, then the raw body bytes, joined by "\\n"."""
    prefix = f"{method.upper()}\n{path_with_query}\n{timestamp}\n".encode("utf-8")
    return hmac.new(secret.encode("utf-8"), prefix + raw_body, hashlib.sha256).hexdigest()


def verify(secret: str, method: str, path_with_query: str, headers: dict, raw_body: bytes, now: int = None) -> bool:
    """Verify a request Reelbit sent to your wallet. Use the raw bytes, before parsing JSON."""
    ts = headers.get("x-reelbit-timestamp", "")
    given = headers.get("x-reelbit-signature", "")
    now = int(time.time()) if now is None else now
    if not ts.isdigit() or abs(int(ts) - now) > 60:
        return False
    return hmac.compare_digest(sign(secret, method, path_with_query, ts, raw_body), given.lower())


if __name__ == "__main__":
    # The worked example from the docs.
    secret = "rb_test_secret_do_not_use"
    body = b'{"player_id":"player-1001","currency":"SC","session_id":"ses_example"}'
    print(sign(secret, "POST", "/balance", "1764633600", body))

#PHP

<?php
// Reelbit request signing: PHP 7.4+ (no extensions beyond the standard hash functions).

// The string to sign is METHOD, path with query, timestamp, then the raw body bytes, joined by "\n".
function reelbit_sign(string $secret, string $method, string $pathWithQuery, string $timestamp, string $rawBody): string
{
    $toSign = strtoupper($method) . "\n" . $pathWithQuery . "\n" . $timestamp . "\n" . $rawBody;
    return hash_hmac('sha256', $toSign, $secret);
}

// Verify a request Reelbit sent to your wallet. Use file_get_contents('php://input') for the raw body.
function reelbit_verify(string $secret, string $method, string $pathWithQuery, array $headers, string $rawBody, ?int $now = null): bool
{
    $ts = $headers['x-reelbit-timestamp'] ?? '';
    $given = strtolower($headers['x-reelbit-signature'] ?? '');
    $now = $now ?? time();
    if (!ctype_digit($ts) || abs((int)$ts - $now) > 60) {
        return false;
    }
    return hash_equals(reelbit_sign($secret, $method, $pathWithQuery, $ts, $rawBody), $given);
}

// The worked example from the docs.
$secret = 'rb_test_secret_do_not_use';
$body = '{"player_id":"player-1001","currency":"SC","session_id":"ses_example"}';
echo reelbit_sign($secret, 'POST', '/balance', '1764633600', $body), "\n";

#Java

// Reelbit request signing: Java 11+ (standard library only). Run with: java Sign.java
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.Map;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

public class Sign {
    // The string to sign is METHOD, path with query, timestamp, then the raw body bytes, joined by "\n".
    public static String sign(String secret, String method, String pathWithQuery, String timestamp, byte[] rawBody) throws Exception {
        Mac mac = Mac.getInstance("HmacSHA256");
        mac.init(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256"));
        mac.update((method.toUpperCase() + "\n" + pathWithQuery + "\n" + timestamp + "\n").getBytes(StandardCharsets.UTF_8));
        mac.update(rawBody);
        StringBuilder hex = new StringBuilder();
        for (byte b : mac.doFinal()) hex.append(String.format("%02x", b));
        return hex.toString();
    }

    // Verify a request Reelbit sent to your wallet. Use the raw bytes, before parsing JSON.
    public static boolean verify(String secret, String method, String pathWithQuery, Map<String, String> headers, byte[] rawBody, long nowSeconds) throws Exception {
        String ts = headers.getOrDefault("x-reelbit-timestamp", "");
        String given = headers.getOrDefault("x-reelbit-signature", "").toLowerCase();
        if (!ts.matches("\\d{1,12}") || Math.abs(Long.parseLong(ts) - nowSeconds) > 60) return false;
        byte[] expected = sign(secret, method, pathWithQuery, ts, rawBody).getBytes(StandardCharsets.UTF_8);
        return MessageDigest.isEqual(expected, given.getBytes(StandardCharsets.UTF_8));
    }

    public static void main(String[] args) throws Exception {
        // The worked example from the docs.
        String secret = "rb_test_secret_do_not_use";
        byte[] body = "{\"player_id\":\"player-1001\",\"currency\":\"SC\",\"session_id\":\"ses_example\"}".getBytes(StandardCharsets.UTF_8);
        System.out.println(sign(secret, "POST", "/balance", "1764633600", body));
    }
}

#C#

// Reelbit request signing: C# / .NET 6+ (standard library only). Run with: dotnet run
using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;

public static class ReelbitSigning
{
    // The string to sign is METHOD, path with query, timestamp, then the raw body bytes, joined by "\n".
    public static string Sign(string secret, string method, string pathWithQuery, string timestamp, byte[] rawBody)
    {
        var prefix = Encoding.UTF8.GetBytes($"{method.ToUpperInvariant()}\n{pathWithQuery}\n{timestamp}\n");
        var toSign = new byte[prefix.Length + rawBody.Length];
        Buffer.BlockCopy(prefix, 0, toSign, 0, prefix.Length);
        Buffer.BlockCopy(rawBody, 0, toSign, prefix.Length, rawBody.Length);
        using var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(secret));
        return Convert.ToHexString(hmac.ComputeHash(toSign)).ToLowerInvariant();
    }

    // Verify a request Reelbit sent to your wallet. Use the raw bytes, before parsing JSON.
    public static bool Verify(string secret, string method, string pathWithQuery, IDictionary<string, string> headers, byte[] rawBody, long nowSeconds)
    {
        headers.TryGetValue("x-reelbit-timestamp", out var ts);
        headers.TryGetValue("x-reelbit-signature", out var given);
        if (!long.TryParse(ts, out var t) || Math.Abs(t - nowSeconds) > 60) return false;
        var expected = Encoding.UTF8.GetBytes(Sign(secret, method, pathWithQuery, ts!, rawBody));
        var actual = Encoding.UTF8.GetBytes((given ?? "").ToLowerInvariant());
        return CryptographicOperations.FixedTimeEquals(expected, actual);
    }

    public static void Main()
    {
        // The worked example from the docs.
        var secret = "rb_test_secret_do_not_use";
        var body = Encoding.UTF8.GetBytes("{\"player_id\":\"player-1001\",\"currency\":\"SC\",\"session_id\":\"ses_example\"}");
        Console.WriteLine(Sign(secret, "POST", "/balance", "1764633600", body));
    }
}

#IP allowlists

Allowlisting is optional, in each direction. Reelbit's wallet calls in production come from 209.71.122.206 (IPv6 2a09:8280:e618:1:0:236:20da:0). The sandbox has no fixed address; ask if your test wallet needs one. To limit the addresses that may call Reelbit, send your list to support.