개발자 포털

개발자 포털 / 참고 자료

영문 기술 문서

INTEGRATION KIT

Request signing samples

These are the actual signing functions from the sample applications. Each full file also includes a wallet implementation and session launch. Keep production secrets on your server.

The sample wallets use a limited currency table. Before enabling a currency or unit, configure its actual precision; do not infer it from a similar code.

Node.js node/spilvon.mjs
Node.js
export const signingString = (ts, method, pathAndQuery, body) => `${ts}.${method.toUpperCase()}.${pathAndQuery}.${body}`;
export const hmacHex = (secret, s) => createHmac("sha256", secret).update(s, "utf8").digest("hex");
Signed session request
Node.js
export async function createSession({ playerId, gameCode, currency = "USD", lang = "en", token, mode = "real" }) {
  const path = "/api/v1/operator/sessions";
  const body = JSON.stringify({ player_id: playerId, game_code: gameCode, currency, lang, token, mode, lobby_url: "https://casino.example/lobby", deposit_url: "https://casino.example/cashier" });
  const ts = String(Date.now());
  const res = await fetch(env("SPILVON_URL") + path, {
    method: "POST",
    headers: {
      "content-type": "application/json",
      "x-spilvon-operator": env("SPILVON_OPERATOR"),
      "x-spilvon-timestamp": ts,
      "x-spilvon-signature": hmacHex(env("SPILVON_API_SECRET"), signingString(ts, "POST", path, body)),
    },
    body, // send exactly the string you signed
  });
  const json = await res.json();
  if (res.status !== 201) throw new Error(`${json.error?.code}: ${json.error?.message} (request_id ${json.request_id})`);
  return json; // { session_id, player_id, launch_url, expires_in: 120 } -> put launch_url in an iframe now
}
Download full sample
Python python/spilvon.py
Python
def signing_string(ts: str, method: str, path_and_query: str, body: str) -> str:
    return f"{ts}.{method.upper()}.{path_and_query}.{body}"


def hmac_hex(secret: str, s: str) -> str:
    return hmac.new(secret.encode(), s.encode("utf-8"), hashlib.sha256).hexdigest()
Signed session request
Python
def create_session(player_id: str, game_code: str, currency="USD", lang="en", token=None, mode="real") -> dict:
    path = "/api/v1/operator/sessions"
    body = json.dumps({"player_id": player_id, "game_code": game_code, "currency": currency, "lang": lang, "token": token, "mode": mode,
                       "lobby_url": "https://casino.example/lobby", "deposit_url": "https://casino.example/cashier"})
    ts = str(int(time.time() * 1000))
    req = urllib.request.Request(env("SPILVON_URL") + path, data=body.encode("utf-8"), method="POST", headers={
        "Content-Type": "application/json",
        "X-Spilvon-Operator": env("SPILVON_OPERATOR"),
        "X-Spilvon-Timestamp": ts,
        "X-Spilvon-Signature": hmac_hex(env("SPILVON_API_SECRET"), signing_string(ts, "POST", path, body)),
    })
    try:
        with urllib.request.urlopen(req, timeout=10) as res:
            return json.load(res)  # {session_id, player_id, launch_url, expires_in: 120}
    except urllib.error.HTTPError as e:
        err = json.load(e)
        raise RuntimeError(f"{err['error']['code']}: {err['error']['message']} (request_id {err.get('request_id')})")
Download full sample
Go go/main.go
Go
func signingString(ts, method, pathAndQuery, body string) string {
	return ts + "." + strings.ToUpper(method) + "." + pathAndQuery + "." + body
}

func hmacHex(secret, s string) string {
	m := hmac.New(sha256.New, []byte(secret))
	m.Write([]byte(s))
	return hex.EncodeToString(m.Sum(nil))
}
Signed session request
Go
func createSession(playerID, gameCode, currency string) (map[string]any, error) {
	path := "/api/v1/operator/sessions"
	body, _ := json.Marshal(map[string]any{"player_id": playerID, "game_code": gameCode, "currency": currency, "lang": "en",
		"token": "casino-session-" + playerID, "lobby_url": "https://casino.example/lobby", "deposit_url": "https://casino.example/cashier"})
	ts := strconv.FormatInt(time.Now().UnixMilli(), 10)
	rq, _ := http.NewRequest("POST", os.Getenv("SPILVON_URL")+path, bytes.NewReader(body))
	rq.Header.Set("Content-Type", "application/json")
	rq.Header.Set("X-Spilvon-Operator", os.Getenv("SPILVON_OPERATOR"))
	rq.Header.Set("X-Spilvon-Timestamp", ts)
	rq.Header.Set("X-Spilvon-Signature", hmacHex(os.Getenv("SPILVON_API_SECRET"), signingString(ts, "POST", path, string(body))))
	res, err := (&http.Client{Timeout: 10 * time.Second}).Do(rq)
	if err != nil {
		return nil, err
	}
	defer res.Body.Close()
	var out map[string]any
	_ = json.NewDecoder(res.Body).Decode(&out)
	if res.StatusCode != 201 {
		return nil, fmt.Errorf("launch failed: %v", out)
	}
	return out, nil // session_id, player_id, launch_url, expires_in (120)
}
Download full sample · go.mod
PHP php/spilvon.php
PHP
function signing_string(string $ts, string $method, string $pathAndQuery, string $body): string {
    return $ts . '.' . strtoupper($method) . '.' . $pathAndQuery . '.' . $body;
}

function hmac_hex(string $secret, string $s): string {
    return hash_hmac('sha256', $s, $secret);
}
Signed session request
PHP
function create_session(string $playerId, string $gameCode, string $currency = 'USD'): array {
    $path = '/api/v1/operator/sessions';
    $body = json_encode(['player_id' => $playerId, 'game_code' => $gameCode, 'currency' => $currency, 'lang' => 'en',
        'token' => "casino-session-$playerId", 'lobby_url' => 'https://casino.example/lobby', 'deposit_url' => 'https://casino.example/cashier'], JSON_UNESCAPED_SLASHES);
    $ts = (string) (int) floor(microtime(true) * 1000);
    $ch = curl_init(getenv('SPILVON_URL') . $path);
    curl_setopt_array($ch, [CURLOPT_POST => true, CURLOPT_POSTFIELDS => $body, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 10, CURLOPT_HTTPHEADER => [
        'Content-Type: application/json',
        'X-Spilvon-Operator: ' . getenv('SPILVON_OPERATOR'),
        "X-Spilvon-Timestamp: $ts",
        'X-Spilvon-Signature: ' . hmac_hex(getenv('SPILVON_API_SECRET'), signing_string($ts, 'POST', $path, $body)),
    ]]);
    $out = json_decode(curl_exec($ch), true);
    if (curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 201) throw new RuntimeException(($out['error']['code'] ?? '?') . ' request_id ' . ($out['request_id'] ?? '?'));
    return $out; // session_id, player_id, launch_url, expires_in (120)
}
Download full sample

Reviewed, not executed by the sample authors.