Server-minted claim codes for in-game rewards (never ship the secret)
rewardsone-time-codeshashingatomic-updategamescorsanti-cheat
A browser game that reveals a prize code when you win is trivially cheated if the code (or the logic that produces it) is in the shipped JavaScript. TLDR's "gold coins" (August 2026) fix this: the game ships no secret; it reports progress to the API, and the server mints a one-time code only after it is satisfied the play happened. The first version embedded an XOR-obfuscated code in the game; it was considered burned (it sat in git history and old deploys) and the coin's hash was rotated.
Model
coin: id,code_hash(SHA-256), label, source, rewards,claimed_by,claimed_at.award: a random "passport" id the game keeps in localStorage, the source game, a JSON map of seal id to first-seen timestamp, created_at, the minted code's hash, minted_at, the coin id, redeemed_by/at.
Endpoints
- Public
POST /coins/progress {source, passport?, seal}: creates the passport or records a seal. Only the first sighting of each seal is stored, so re-reports cannot rewrite history. - Public
POST /coins/award {passport}: mints a code only if all seals are present, the passport is at least 15 minutes old (no instant scripted completion), and the coin is still unclaimed. The plaintext is returned once and never stored, only its hash. Mint is an atomicUPDATE ... WHERE code_hash IS NULL; 409 if already minted, 403 if incomplete or too young, 410 if the coin is gone. - Authenticated
POST /coins/claim {code}: hash the input, match a coin or an award, then an atomicUPDATE ... WHERE claimed_by IS NULL(first claim wins). 200 claimed / already yours, 404 bad code, 409 taken. - The seal list on the server must match the game's exactly.
Why it holds up
The server never trusts a client-supplied "I won"; it trusts a timeline it recorded itself, and the timestamps per seal are an audit trail for suspicious mints. Nothing secret is ever in the client. Admin fallback codes live in a 0600, git-excluded file.
Cross-site CORS
The game lives on a different site than the API, so the API vhost echoes an allowlisted Origin:
SetEnvIf Origin "^https://(tldrnerd\.com|justinahampton\.com)$" CORS_ORIGIN=$0
Header always set Access-Control-Allow-Origin "%{CORS_ORIGIN}e" env=CORS_ORIGIN
Requests without an Origin header (curl) get no ACAO header at all, so test with -H 'Origin: ...'.
Money note
If rewards become cash prizes, US payouts over $600 per person per year trigger 1099 reporting.