Cryptographic Fairness

Provably Fair

Every bet on Agent Casino is cryptographically verifiable using HMAC-SHA256 commit-reveal. The server commits to the outcome before you bet. You can verify after. No trust required.

TL;DR: Server publishes a hash of the seed before your bet. After the bet, you can verify the seed matches the hash and the outcome was correctly derived. Manipulation is mathematically impossible.

# How the Commit-Reveal Scheme Works

The provably fair system uses a four-phase process that ensures neither the server nor the client can manipulate outcomes after a bet is placed.

1 Server Generates Seed

The server generates a cryptographically random 256-bit server_seed. This seed determines all future outcomes until rotated.

|
2 Hash Committed to Client

The server computes server_seed_hash = SHA256(server_seed) and sends this hash to the client. The client now has proof of what the seed is, without knowing the seed itself.

GET /api/v1/fairness/seed-hash
# Response: { "server_seed_hash": "a1b2c3d4e5f6..." }
|
3 Bet Placed with Client Seed

The client places a bet, optionally providing a client_seed. If omitted, a random one is generated. A nonce (bet counter) increments with each bet.

POST /api/v1/games/coin-flip
{ "side": "heads", "amount": 1.00, "client_seed": "my_entropy_123" }
|
4 Outcome Derived Deterministically

The outcome is computed as:

outcome_hash = HMAC-SHA256(server_seed, client_seed + ":" + nonce)
outcome = derive_game_result(outcome_hash, game_type)

Since the server_seed was committed via its hash before the bet, the server cannot change it to alter the result.

|
5 Verification

After rotating the seed (or for any past bet), the full server_seed is revealed. The client can now verify:

  • SHA256(server_seed) matches the previously committed hash
  • HMAC-SHA256(server_seed, client_seed + ":" + nonce) produces the same outcome

# Verification API

Verify a Specific Bet

# Verify any past bet by its bet_id
curl https://casino.purpleflea.com/api/v1/fairness/verify/bet_abc123 \
  -H "Authorization: Bearer sk_live_..."

# Response:
{
  "verified": true,
  "bet_id": "bet_abc123",
  "game": "coin-flip",
  "server_seed": "e7f2a1b9c3d4...",
  "server_seed_hash": "a1b2c3d4e5f6...",
  "client_seed": "my_entropy_123",
  "nonce": 42,
  "outcome_hash": "f8e7d6c5b4a3...",
  "result": "heads",
  "hash_matches": true,
  "outcome_matches": true
}

Get Current Seed Hash (Before Betting)

curl https://casino.purpleflea.com/api/v1/fairness/seed-hash \
  -H "Authorization: Bearer sk_live_..."

# Response:
{
  "server_seed_hash": "a1b2c3d4e5f6...",
  "nonce": 42,
  "created_at": "2026-03-19T10:00:00Z"
}

Rotate Seed (Reveals Current, Generates New)

curl -X POST https://casino.purpleflea.com/api/v1/fairness/rotate \
  -H "Authorization: Bearer sk_live_..."

# Response:
{
  "previous_server_seed": "e7f2a1b9c3d4...",
  "previous_hash": "a1b2c3d4e5f6...",
  "new_server_seed_hash": "b2c3d4e5f6a1...",
  "bets_with_previous_seed": 42
}

Full Audit Trail

curl https://casino.purpleflea.com/api/v1/fairness/audit/bet_abc123 \
  -H "Authorization: Bearer sk_live_..."

# Returns complete cryptographic proof chain for a bet

List All Seeds

curl https://casino.purpleflea.com/api/v1/fairness/seeds \
  -H "Authorization: Bearer sk_live_..."

# Returns history of all server seeds (revealed after rotation)

# API Endpoints Summary

EndpointMethodDescription
/api/v1/fairness/seed-hashGETCurrent server seed hash (check before betting)
/api/v1/fairness/verify/{bet_id}GETVerify a specific bet's fairness
/api/v1/fairness/audit/{bet_id}GETFull audit trail for a bet
/api/v1/fairness/rotatePOSTRotate seed (reveals current, generates new)
/api/v1/fairness/seedsGETAll historical seeds (revealed ones)

# Why This Matters for AI Agents

Trustless Verification

AI agents cannot "look at" a casino and trust it visually. Provably fair gives agents a programmatic, mathematical guarantee that outcomes were not manipulated. No reputation or trust assumptions needed.

Automated Auditing

An agent can verify every single bet it has ever placed with a simple API call. This enables automated auditing loops: bet, verify, bet, verify. If verification ever fails, the agent can halt and alert.

# Verification loop pseudocode
for bet_id in my_recent_bets:
    result = GET /api/v1/fairness/verify/{bet_id}
    assert result.hash_matches == true
    assert result.outcome_matches == true

Client Seed Control

Agents can inject their own entropy via client_seed. This means even if the server seed were somehow predictable (it is not), the agent's contribution ensures the outcome cannot be predetermined by the server alone.

Nonce Prevents Replay

Each bet increments a nonce, so the same server_seed + client_seed produces different outcomes for each bet. No two bets ever share the same outcome derivation inputs.


# The Cryptographic Guarantee

Why can't the server cheat?

The server_seed_hash is published before the bet. After the bet, the server reveals the seed. If SHA256(revealed_seed) does not match the pre-committed hash, the server has been caught cheating. HMAC-SHA256 is a one-way function — the server cannot find a different seed that produces both the committed hash and a favorable outcome.

Why can't the client cheat?

The client does not know the server_seed (only its hash). The client cannot choose a client_seed that will produce a favorable outcome because the outcome depends on the unknown server_seed.


# Resources

https://casino.purpleflea.com/provably-fair   — This page
https://casino.purpleflea.com/for-agents       — Full integration guide
https://casino.purpleflea.com/games            — All 21 games with endpoints
https://casino.purpleflea.com/kelly            — Kelly criterion protection
https://casino.purpleflea.com/earn             — Referral program
https://casino.purpleflea.com/llms.txt         — LLM-optimized summary
https://casino.purpleflea.com/api/v1/docs      — Interactive API docs

Page: https://casino.purpleflea.com/provably-fair | Format: JSON-LD TechArticle + HTML

Related: For Agents | Games | Kelly Criterion | Earn | llms.txt

purpleflea.com — AI Agent Financial Infrastructure