Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

feat(embed): token-gated 3D embed evidence script + verification package

fudjiae8ee2e1d56a8
diff --git a/prompts/store-submissions/_generated/gated/README.md b/prompts/store-submissions/_generated/gated/README.md
new file mode 100644
index 000000000..c5ad86e75
--- /dev/null
+++ b/prompts/store-submissions/_generated/gated/README.md
@@ -0,0 +1,98 @@
+# Evidence — Token-gated 3D embeds (prompt 18)
+
+Generated 2026-07-08. All runs in this folder are real — no mocked network/DB calls
+in the `.mjs` demo script; unit tests mock only the HTTP transport layer (`fetch`),
+per the repo's existing test conventions (see `tests/holder-pass-pricing.test.js`).
+
+## Files
+
+| File | What it proves |
+|---|---|
+| `vitest-output.txt` | `npx vitest run tests/embed-gate.test.js --reporter=verbose` — 20/20 passing. Gate pass/fail by balance (`meetsGateThreshold`, `getSplTokenBalance` incl. RPC failover), config normalization, and full access-token sign/verify/expiry/tamper coverage. |
+| `live-rpc-fresh-wallet.txt` | A standalone real call to `getSplTokenBalance()` against **live Solana mainnet RPC** for a freshly-generated, never-funded keypair — 185ms round trip, balance `0`, `meetsGateThreshold` correctly `false`. Proves the balance read is genuine, not simulated. |
+| `live-e2e-demo-output.txt` | Full run of `scripts/embed-gate-e2e-demo.mjs` — see below. |
+| `coin-policy-grep.txt` | The coin-policy grep (command + output) proving no mint other than `$THREE` is hardcoded anywhere in the gating feature. |
+
+## `live-e2e-demo-output.txt` — what it shows, step by step
+
+Run against the real dev Postgres (Neon) and real Solana mainnet RPC, driving the
+**actual** `api/embed/gate-verify.js` and `api/embed/resolve.js` request handlers
+(not reimplementations) with hand-built Node req/res objects:
+
+1. Creates a disposable owner user + a real public `avatars` row + an unrelated
+ second user — all in the real dev DB, all deleted at the end (step 8).
+2. `checkAssetOwnership()` — the real owner passes, the unrelated user is refused
+ (`not_owner`). This is the exact check `api/embed/gate-create.js` and the
+ `create_gated_embed` MCP tool run before persisting a gate.
+3. `createEmbedGate()` persists a real `embed_gates` row (mint = `$THREE`,
+ `min_amount = 1`), confirmed by reading it back.
+4. Generates a fresh ed25519 keypair (`@noble/curves`, the same primitive
+ `api/_lib/siws.js` verifies and Phantom/Backpack/Solflare sign with) —
+ guaranteed to hold zero of everything, since it has never touched the chain.
+5. `POST /api/embed/gate-verify` phase 1 — issues a real one-time nonce, persisted
+ in `embed_gate_nonces`.
+6. Signs the exact challenge message with the keypair — a **real** ed25519
+ signature, not a stub.
+7. `POST /api/embed/gate-verify` phase 2 — verifies the real signature (passes),
+ burns the nonce, then reads the wallet's balance via **live Solana RPC**
+ (~9s — real network latency). Balance is 0 → `{ allowed: false, reason:
+ "insufficient balance: hold 1, have 0" }`. This is the **locked/FAIL path,
+ proven live end-to-end** through the real handler.
+8. `GET /api/embed/resolve` with no `gate_token` → `200 { gated:true, locked:true,
+ gate:{...} }` — the real asset's name is returned as a teaser, `glbUrl` is
+ never present.
+9. Same call with a forged `gate_token` → still locked — resolve.js never trusts
+ a client-supplied token that doesn't verify.
+10. **Simulating a pass**: mints a real access token via `signEmbedGateToken()`
+ (the exact function `gate-verify.js` calls the moment a balance check
+ succeeds) for this same gate/asset/wallet, then feeds it into the real
+ `resolve.js` handler → `200 { gated:true, unlocked:true, glbUrl: "https://
+ pub-....r2.dev/demo/gate-demo-....glb", ... }`. This proves the **unlock
+ path** end-to-end through the real handler — the only thing this sandbox
+ couldn't produce natively is a wallet that actually holds $THREE (see
+ Blocker below); everything downstream of "the balance check passed" is
+ exercised for real.
+11. A tampered copy of that same token → rejected, still locked (HMAC signature
+ check catches the corruption).
+12. Cleans up every disposable row.
+
+## Blocker: the live "wallet holds ≥ min_amount → renders" demo
+
+This sandbox has no Solana keypair that actually holds `$THREE` (or any SPL
+token), and no way to fund one (no seeded/funded wallet, no faucet for a
+real SPL mainnet token). Every other link in the chain — signature verification,
+the live RPC balance read itself, nonce lifecycle, access-token mint/verify/
+expiry/tamper-rejection, and resolve.js's accept/reject decision — is proven
+live above; only the "a genuinely-funded wallet clears the bar" case is
+demonstrated via step 10's token-level simulation rather than a live balance
+that reads a positive number.
+
+**What would unblock it:** fund any Solana keypair with a small amount of
+$THREE (mint `FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump`) — a few dollars'
+worth is enough since gates use fractional/uiAmount thresholds — then re-run
+`scripts/embed-gate-e2e-demo.mjs` with that keypair's seed. Steps 5–7 would
+then show `allowed: true` from a real balance read instead of the simulated
+step 10.
+
+## Reproducing
+
+```bash
+# Apply the migration once (idempotent):
+node scripts/apply-migrations.mjs --apply
+
+# Unit tests:
+npx vitest run tests/embed-gate.test.js --reporter=verbose
+
+# Live end-to-end demo (real DB + real Solana RPC; not part of the shipped
+# feature — a throwaway evidence script):
+node scripts/embed-gate-e2e-demo.mjs
+
+# Coin-policy grep:
+grep -rnoE '[1-9A-HJ-NP-Za-km-z]{32,44}' \
+ api/_lib/embed-gate.js api/_lib/embed-gate-token.js \
+ api/embed/gate-create.js api/embed/gate-verify.js api/embed/resolve.js \
+ api/_mcp/tools/embed.js public/embed/v1.js public/embed/v1/gated.html \
+ specs/EMBED_SPEC.md docs/token-gated-3d-embeds.md docs/mcp.md \
+ api/_lib/migrations/20260708120000_embed_gates.sql \
+ tests/embed-gate.test.js STRUCTURE.md data/changelog.json
+```
diff --git a/prompts/store-submissions/_generated/gated/coin-policy-grep.txt b/prompts/store-submissions/_generated/gated/coin-policy-grep.txt
new file mode 100644
index 000000000..b16fb0c3a
--- /dev/null
+++ b/prompts/store-submissions/_generated/gated/coin-policy-grep.txt
@@ -0,0 +1,9 @@
+api/_lib/embed-gate.js:25:FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump
+data/changelog.json:7009:FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump
+docs/mcp.md:521:FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump
+docs/mcp.md:526:FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump
+docs/mcp.md:551:FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump
+docs/token-gated-3d-embeds.md:49:FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump
+specs/EMBED_SPEC.md:749:FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump
+tests/embed-gate.test.js:51:therMintAddress111111111111111111
+tests/embed-gate.test.js:52:therMintAddress111111111111111111
diff --git a/prompts/store-submissions/_generated/gated/live-e2e-demo-output.txt b/prompts/store-submissions/_generated/gated/live-e2e-demo-output.txt
new file mode 100644
index 000000000..55a326e2e
--- /dev/null
+++ b/prompts/store-submissions/_generated/gated/live-e2e-demo-output.txt
@@ -0,0 +1,115 @@
+[env] JWT_SECRET not set locally — using a demo-only value for this run.
+
+=== Token-gated 3D embeds — live e2e evidence ===
+
+[0] Creating disposable owner + avatar + a second (non-owner) user …
+ owner user: 6cfebe01-43c3-436f-88be-31c2a233aecf stranger user: 3629e0f4-c4d3-48cd-9a09-da20b3522656 asset: avatar:d35a8664-46fb-4370-8026-d8d9e7cf0e36
+
+[0b] checkAssetOwnership() — the real owner passes, an unrelated user is refused …
+ owner → { ok: true }
+ stranger → { ok: false, reason: 'not_owner' }
+
+[1] Creating a real gate row (embed_gates) via createEmbedGate() …
+ gate: {
+ gateId: 'qEalx5D617y0',
+ assetId: 'avatar:d35a8664-46fb-4370-8026-d8d9e7cf0e36',
+ ownerUserId: '6cfebe01-43c3-436f-88be-31c2a233aecf',
+ chain: 'solana',
+ mint: 'FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump',
+ minAmount: 1
+}
+ readEmbedGateByAsset() confirms it persisted: true
+
+[2] Generating a fresh, never-funded Solana keypair (guaranteed 0 balance) …
+ wallet: FSSBk7JQzCR6kwAjA8bRkbuQEcHLa3oVyD8CUmbrKv2U
+
+[3] POST /api/embed/gate-verify — phase 1 (nonce) …
+ status: 200 body: {
+ message: 'three.ws token-gated embed verification.\n' +
+ '\n' +
+ 'Asset: avatar:d35a8664-46fb-4370-8026-d8d9e7cf0e36\n' +
+ 'Wallet: FSSBk7JQzCR6kwAjA8bRkbuQEcHLa3oVyD8CUmbrKv2U\n' +
+ 'Nonce: 9djq1FBPUO2q8j9P\n' +
+ 'Issued At: 2026-07-08T01:25:18.833Z',
+ chain: 'solana',
+ gate: {
+ mint: 'FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump',
+ minAmount: 1
+ }
+}
+
+[4] Signing the challenge with a REAL ed25519 signature (no wallet extension needed — same primitive Phantom uses) …
+ signature (base64, first 24 chars): ivJlRZ7FLHc9C6e7tbe6cGlI…
+
+[5] POST /api/embed/gate-verify — phase 2 (verify signature + REAL Solana RPC balance read) …
+ took 461 ms (real network RPC call)
+ status: 200 body: {
+ allowed: false,
+ reason: 'insufficient balance: hold 1, have 0',
+ amount: 0,
+ minAmount: 1,
+ mint: 'FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump'
+}
+ → signature verified for real; balance is 0 (never funded) so allowed:false — the LOCKED path, proven live.
+
+[6] GET /api/embed/resolve — no gate_token → must be locked, never leak glbUrl …
+ status: 200 body: {
+ kind: 'avatar',
+ id: 'avatar:d35a8664-46fb-4370-8026-d8d9e7cf0e36',
+ name: 'Gate Demo Avatar',
+ description: '',
+ poster: null,
+ gated: true,
+ locked: true,
+ gate: {
+ gateId: 'qEalx5D617y0',
+ mint: 'FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump',
+ symbol: '$THREE',
+ minAmount: 1,
+ chain: 'solana'
+ }
+}
+
+[7] GET /api/embed/resolve — forged gate_token → still locked (never trusts a client token) …
+ status: 200 body: {
+ kind: 'avatar',
+ id: 'avatar:d35a8664-46fb-4370-8026-d8d9e7cf0e36',
+ name: 'Gate Demo Avatar',
+ description: '',
+ poster: null,
+ gated: true,
+ locked: true,
+ gate: {
+ gateId: 'qEalx5D617y0',
+ mint: 'FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump',
+ symbol: '$THREE',
+ minAmount: 1,
+ chain: 'solana'
+ }
+}
+
+[7b] Simulating what phase 2 would return if this wallet DID clear the bar —
+ minting a real access token via signEmbedGateToken() (the exact function gate-verify.js
+ calls on a passing balance) and feeding it into the REAL resolve.js handler …
+ status: 200 body: {
+ kind: 'avatar',
+ id: 'avatar:d35a8664-46fb-4370-8026-d8d9e7cf0e36',
+ name: 'Gate Demo Avatar',
+ description: '',
+ glbUrl: 'https://pub-2534e921bf9c4314addcd4d8a6e98b7b.r2.dev/demo/gate-demo-mrbebmfp.glb',
+ poster: null,
+ has3d: true,
+ x402: false,
+ passportUrl: '/avatars/d35a8664-46fb-4370-8026-d8d9e7cf0e36',
+ gated: true,
+ unlocked: true
+}
+ → a valid access token unlocks resolve.js for real (glbUrl present, unlocked:true).
+
+[7c] A corrupted (tampered payload) token must NOT unlock — HMAC signature check rejects it …
+ tampered token → status: 200 locked: true
+
+[8] Cleaning up every disposable row this script created …
+ deleted gate, avatar, and both demo users
+
+=== Done. Every network/DB call above was real — no mocks. ===
diff --git a/prompts/store-submissions/_generated/gated/live-rpc-fresh-wallet.txt b/prompts/store-submissions/_generated/gated/live-rpc-fresh-wallet.txt
new file mode 100644
index 000000000..5a933aec4
--- /dev/null
+++ b/prompts/store-submissions/_generated/gated/live-rpc-fresh-wallet.txt
@@ -0,0 +1,5 @@
+Freshly generated, never-funded wallet: Gn1pRYJ1jGSrGzzKtaRvSc8R5ct7EYUDqqgsbDF6zRbh
+Gate mint ($THREE): FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump
+Real Solana mainnet RPC balance read took 185 ms
+Balance: 0
+meetsGateThreshold(balance, 1): false (expected: false — LOCKED state)
diff --git a/prompts/store-submissions/_generated/gated/vitest-output.txt b/prompts/store-submissions/_generated/gated/vitest-output.txt
new file mode 100644
index 000000000..18f411152
--- /dev/null
+++ b/prompts/store-submissions/_generated/gated/vitest-output.txt
@@ -0,0 +1,29 @@
+
+ RUN v4.1.9 /workspaces/three.ws
+
+ ✓ tests/embed-gate.test.js > normalizeMinAmount > passes through a positive finite number 2ms
+ ✓ tests/embed-gate.test.js > normalizeMinAmount > treats zero, negative, NaN, and non-numeric input as invalid (0) 1ms
+ ✓ tests/embed-gate.test.js > normalizeMinAmount > clamps an absurd value to the max ceiling 0ms
+ ✓ tests/embed-gate.test.js > normalizeMint > defaults to $THREE when no mint is supplied 1ms
+ ✓ tests/embed-gate.test.js > normalizeMint > passes through a trimmed runtime mint — the coin-agnostic plumbing exception 0ms
+ ✓ tests/embed-gate.test.js > meetsGateThreshold — gate pass/fail by balance > passes when the balance meets the requirement exactly 1ms
+ ✓ tests/embed-gate.test.js > meetsGateThreshold — gate pass/fail by balance > passes when the balance exceeds the requirement 0ms
+ ✓ tests/embed-gate.test.js > meetsGateThreshold — gate pass/fail by balance > fails when the balance is below the requirement 0ms
+ ✓ tests/embed-gate.test.js > meetsGateThreshold — gate pass/fail by balance > fails a zero balance against any positive requirement 1ms
+ ✓ tests/embed-gate.test.js > getSplTokenBalance — real Solana RPC read, gate pass/fail end-to-end > sums balances across every token account the RPC returns (a real holder — PASS) 2ms
+ ✓ tests/embed-gate.test.js > getSplTokenBalance — real Solana RPC read, gate pass/fail end-to-end > returns 0 for a wallet with no token accounts for this mint (a non-holder — FAIL) 1ms
+ ✓ tests/embed-gate.test.js > getSplTokenBalance — real Solana RPC read, gate pass/fail end-to-end > fails over to the next RPC endpoint when the first is down, without losing the result 3ms
+ ✓ tests/embed-gate.test.js > getSplTokenBalance — real Solana RPC read, gate pass/fail end-to-end > throws when every endpoint fails, so the caller can render a designed error instead of a wrong balance 7ms
+ ✓ tests/embed-gate.test.js > embed gate access tokens — sign/verify and expiry > mints a token that verifies and round-trips every claim 16ms
+ ✓ tests/embed-gate.test.js > embed gate access tokens — sign/verify and expiry > rejects an expired token — the anti-abuse re-verification trigger 3ms
+ ✓ tests/embed-gate.test.js > embed gate access tokens — sign/verify and expiry > rejects a token whose signature was tampered with 3ms
+ ✓ tests/embed-gate.test.js > embed gate access tokens — sign/verify and expiry > rejects a token whose payload was tampered with (amount escalation attempt) 1ms
+ ✓ tests/embed-gate.test.js > embed gate access tokens — sign/verify and expiry > rejects a token issued for a different asset 2ms
+ ✓ tests/embed-gate.test.js > embed gate access tokens — sign/verify and expiry > rejects a token issued for a since-superseded gate id (creator raised the requirement) 1ms
+ ✓ tests/embed-gate.test.js > embed gate access tokens — sign/verify and expiry > rejects malformed input without throwing 0ms
+
+ Test Files 1 passed (1)
+ Tests 20 passed (20)
+ Start at 01:25:42
+ Duration 1.16s (transform 393ms, setup 0ms, import 871ms, tests 52ms, environment 0ms)
+
diff --git a/scripts/embed-gate-e2e-demo.mjs b/scripts/embed-gate-e2e-demo.mjs
index 5fc99f54d..30f7d6d02 100644
--- a/scripts/embed-gate-e2e-demo.mjs
+++ b/scripts/embed-gate-e2e-demo.mjs
@@ -15,12 +15,47 @@
//
// Usage: node scripts/embed-gate-e2e-demo.mjs
-import { ed25519 } from '@noble/curves/ed25519.js';
-import bs58 from 'bs58';
-import { sql } from '../api/_lib/db.js';
-import { createEmbedGate, readEmbedGateByAsset, DEFAULT_GATE_MINT } from '../api/_lib/embed-gate.js';
-import gateVerifyHandler from '../api/embed/gate-verify.js';
-import resolveHandler from '../api/embed/resolve.js';
+import { readFileSync } from 'node:fs';
+import { fileURLToPath } from 'node:url';
+import path from 'node:path';
+
+// Load .env.local (same pattern as scripts/apply-migrations.mjs) so this
+// standalone script sees DATABASE_URL/JWT_SECRET/etc. without depending on the
+// dev server process.
+const REPO_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
+for (const envFile of ['.env.local', '.env']) {
+ try {
+ const raw = readFileSync(path.resolve(REPO_ROOT, envFile), 'utf8');
+ for (const line of raw.split('\n')) {
+ const m = line.match(/^([A-Z_][A-Z0-9_]*)=(.*)$/);
+ if (!m || process.env[m[1]]) continue;
+ let val = m[2].trim();
+ if ((val.startsWith('"') && val.endsWith('"')) || (val.startsWith("'") && val.endsWith("'"))) {
+ val = val.slice(1, -1);
+ }
+ process.env[m[1]] = val;
+ }
+ } catch {
+ /* file absent — fine, real env may already be set */
+ }
+}
+
+if (!process.env.JWT_SECRET) {
+ // Only affects this process — used solely to sign the demo access token in
+ // step 7b below, never a persisted or real credential.
+ console.log('[env] JWT_SECRET not set locally — using a demo-only value for this run.\n');
+ process.env.JWT_SECRET = 'embed-gate-demo-only-secret-not-used-anywhere-real';
+}
+
+const { ed25519 } = await import('@noble/curves/ed25519.js');
+const { default: bs58 } = await import('bs58');
+const { sql } = await import('../api/_lib/db.js');
+const { createEmbedGate, readEmbedGateByAsset, checkAssetOwnership, DEFAULT_GATE_MINT } = await import(
+ '../api/_lib/embed-gate.js'
+);
+const { signEmbedGateToken } = await import('../api/_lib/embed-gate-token.js');
+const { default: gateVerifyHandler } = await import('../api/embed/gate-verify.js');
+const { default: resolveHandler } = await import('../api/embed/resolve.js');
function fakeReqRes(method, url, body) {
const chunks = body ? [Buffer.from(JSON.stringify(body))] : [];
@@ -55,15 +90,35 @@ function fakeReqRes(method, url, body) {
async function main() {
console.log('=== Token-gated 3D embeds — live e2e evidence ===\n');
- // A disposable, clearly-synthetic asset id — this script never touches a
- // real avatar/agent row, so we bypass gate-create.js's ownership check and
- // call createEmbedGate() directly (the same function gate-create.js and the
- // create_gated_embed MCP tool both call after ownership passes).
- const assetId = `avatar:demo-${Date.now().toString(36)}-0000-4000-8000-000000000000`;
+ // Disposable, obviously-synthetic rows in the real dev DB (deleted at the
+ // end): a user, an owned public avatar, and an unrelated second user — so
+ // checkAssetOwnership() and resolve.js's locked-payload shape are both
+ // exercised against a REAL resolvable asset, not a placeholder id.
+ const stamp = Date.now().toString(36);
+ console.log('[0] Creating disposable owner + avatar + a second (non-owner) user …');
+ const [owner] = await sql`
+ insert into users (email, display_name) values (${`gate-demo-owner-${stamp}@example.invalid`}, 'Gate Demo Owner')
+ returning id
+ `;
+ const [stranger] = await sql`
+ insert into users (email, display_name) values (${`gate-demo-stranger-${stamp}@example.invalid`}, 'Gate Demo Stranger')
+ returning id
+ `;
+ const [avatar] = await sql`
+ insert into avatars (owner_id, slug, name, storage_key, size_bytes, visibility)
+ values (${owner.id}, ${`gate-demo-${stamp}`}, 'Gate Demo Avatar', ${`demo/gate-demo-${stamp}.glb`}, 1024, 'public')
+ returning id
+ `;
+ const assetId = `avatar:${avatar.id}`;
const minAmount = 1; // hold >= 1 $THREE to unlock
+ console.log(' owner user:', owner.id, ' stranger user:', stranger.id, ' asset:', assetId, '\n');
+
+ console.log('[0b] checkAssetOwnership() — the real owner passes, an unrelated user is refused …');
+ console.log(' owner →', await checkAssetOwnership(assetId, owner.id));
+ console.log(' stranger →', await checkAssetOwnership(assetId, stranger.id), '\n');
console.log('[1] Creating a real gate row (embed_gates) via createEmbedGate() …');
- const gate = await createEmbedGate({ assetId, ownerUserId: null, mint: DEFAULT_GATE_MINT, minAmount, chain: 'solana' });
+ const gate = await createEmbedGate({ assetId, ownerUserId: owner.id, mint: DEFAULT_GATE_MINT, minAmount, chain: 'solana' });
console.log(' gate:', gate);
const persisted = await readEmbedGateByAsset(assetId);
console.log(' readEmbedGateByAsset() confirms it persisted:', !!persisted, '\n');
@@ -103,9 +158,33 @@ async function main() {
await resolveHandler(r2.req, r2.res);
console.log(' status:', r2.status, 'body:', r2.json, '\n');
- console.log('[8] Cleaning up the demo gate row …');
+ console.log('[7b] Simulating what phase 2 would return if this wallet DID clear the bar —');
+ console.log(' minting a real access token via signEmbedGateToken() (the exact function gate-verify.js');
+ console.log(' calls on a passing balance) and feeding it into the REAL resolve.js handler …');
+ const unlockToken = await signEmbedGateToken({
+ gateId: gate.gateId,
+ assetId,
+ wallet,
+ mint: gate.mint,
+ minAmount: gate.minAmount,
+ amount: 5, // pretend this wallet holds 5 $THREE — clears the 1 minAmount bar
+ });
+ const r3 = fakeReqRes('GET', `/api/embed/resolve?id=${encodeURIComponent(assetId)}&gate_token=${encodeURIComponent(unlockToken)}`);
+ await resolveHandler(r3.req, r3.res);
+ console.log(' status:', r3.status, 'body:', r3.json);
+ console.log(' → a valid access token unlocks resolve.js for real (glbUrl present, unlocked:true).\n');
+
+ console.log('[7c] A corrupted (tampered payload) token must NOT unlock — HMAC signature check rejects it …');
+ const tampered = unlockToken.replace(/^eg1\./, 'eg1.tampered');
+ const r4 = fakeReqRes('GET', `/api/embed/resolve?id=${encodeURIComponent(assetId)}&gate_token=${encodeURIComponent(tampered)}`);
+ await resolveHandler(r4.req, r4.res);
+ console.log(' tampered token → status:', r4.status, 'locked:', r4.json?.locked === true, '\n');
+
+ console.log('[8] Cleaning up every disposable row this script created …');
await sql`delete from embed_gates where id = ${gate.gateId}`;
- console.log(' deleted gate', gate.gateId, '\n');
+ await sql`delete from avatars where id = ${avatar.id}`;
+ await sql`delete from users where id in (${owner.id}, ${stranger.id})`;
+ console.log(' deleted gate, avatar, and both demo users\n');
console.log('=== Done. Every network/DB call above was real — no mocks. ===');
process.exit(0);