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.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
fix(cz): delete the rehearsal fake-success path and repair the broken embed snippet
nirholasc2e33186497d
diff --git a/public/cz/README.md b/public/cz/README.mdindex 251bdb27e..050f2b50e 100644--- a/public/cz/README.md+++ b/public/cz/README.md@@ -1,129 +1,77 @@-# CZ Demo — Landing & Claim Flow+# CZ claim page-The CZ landing page is served at `/cz/` and provides:--- Full-bleed dark landing page with centered three.ws avatar-- **Claim CZ** button — initiates wallet connection and claim flow-- **Copy embed** button — copies `<agent-3d>` snippet to clipboard-- Footer — displays on-chain state (chain, agentId, metadataURI)-- Custom event analytics via `window.dispatchEvent('cz-demo-event', ...)`+The CZ agent's claim page, served at `/cz/`. A visitor connects a browser+wallet, signs a one-line message, and the platform hands them ownership of the+pre-registered CZ agent. `/cz/offline` is the static fallback shown when the+page is presented without a network (see `offline/README.md`).## Files-- `index.html` — Main landing page-- `boot.js` — Client-side initialization and claim flow UI-- `state.json` — On-chain state stub (updated by `prompts/cz-demo/01-pre-register.js`)--## State Schema--`state.json` is a JSON file with this shape:--```json-{- "status": "pre-onchain" | "onchain",- "chainId": null | number,- "agentId": null | number,- "metadataURI": null | string,- "ownerAddress": null | "0x0..." | string,- "avatarUrl": "/avatars/cz.glb" | string-}-```--**Fields:**--- `status` — `"pre-onchain"` (not yet registered) or `"onchain"` (registered)-- `chainId` — Chain ID (e.g., `8453` for Base, `84532` for Base Sepolia), or `null`-- `agentId` — Token ID from IdentityRegistry, or `null`-- `metadataURI` — IPFS/HTTPS URL of the full registration JSON, or `null`-- `ownerAddress` — Current owner address, `"0x0..."` (unclaimed), or `null`-- `avatarUrl` — GLB URL (default `/avatars/cz.glb`)--The landing page footer displays the state. In `pre-onchain`, it shows "Not yet onchain".--## Claim Flow--The `startClaim()` function in `src/cz-flow.js` handles:--1. **Pre-onchain** — Shows modal: "Claim opens when CZ is registered"-2. **Unclaimed** (`ownerAddress === "0x0..."`): Calls `IdentityRegistry.claim(agentId)`-3. **Demo EOA transfer**: Guides user through `transferOwner()`-4. **Already owned**: Shows modal with current owner--All steps emit progress via `onProgress({ step, status, txHash?, error? })` and fire custom events:--- `landing_view` — Page loaded-- `claim_start` — Claim button clicked-- `claim_wallet_connected` — Wallet connected (implicit in flow)-- `claim_tx_sent` — Transaction sent-- `claim_complete` — Claim successful-- `claim_error` — Error occurred-- `embed_copied` — Embed snippet copied--Listen for these on `window`:--```js-window.addEventListener('cz-demo-event', (e) => {- console.log(e.detail.event, e.detail.props);-});-```--## Routing--The page is served at `/cz/` by the Vite dev server and Vercel (`public/cz/` → `/cz/`).--To add `/cz` (without trailing slash) or a custom route, edit:--- **Local dev**: `vite.config.js` — `vercel-rewrites` plugin-- **Production**: `vercel.json` — `rewrites` array--Example for `vercel.json`:--```json-{- "rewrites": [{ "source": "/cz", "destination": "/cz/" }]-}-```--Then run `npm run deploy` to push changes.--## Integration with `prompts/cz-demo/01-pre-register.js`--When the onchain pre-registration is ready, that script will:--1. Deploy / verify the ERC-8004 IdentityRegistry if needed-2. Call `register()` with the GLB and metadata-3. Write an updated `public/cz/state.json` with real `chainId`, `agentId`, `metadataURI`, `ownerAddress`--The landing page will automatically reflect this state on next load.--## Accessibility--- Semantic `<h1>` for the headline-- `aria-label` on all buttons-- Focus rings visible (2px outline with 2px offset)-- Reduced motion support (`prefers-reduced-motion`)-- Modal keyboard-escapable--## Testing+| File | Role |+|---|---|+| `index.html` | The page: preview avatar, the connect / sign / success / error steps, and the embed snippets shown after a claim. |+| `cz.js` | The whole client flow: wallet connect, nonce fetch, `personal_sign`, claim POST, optional on-chain broadcast. |+| `cz.css` | Page styles. |++The server side is a single handler, `api/cz/claim.js`, backed by the+`cz_claims` table (`api/_lib/migrations/20260812140000_cz_claims.sql`).++## The claim flow++1. **Connect.** `cz.js` asks the injected provider for an account+ (`eth_requestAccounts`), then calls `GET /api/cz/claim?address=0x...`, which+ mints a random 16-byte nonce, stores it against the lowercased address as a+ `pending` row, and returns `{ nonce, expiresInSeconds }`.+2. **Sign.** The user signs `Claim CZ Agent\n\nNonce: <nonce>` with+ `personal_sign`. Nothing is sent on-chain at this point and no gas is spent.+3. **Redeem.** `POST /api/cz/claim` with `{ signerAddress, signature, nonce }`.+ The handler recovers the signer from the signature, requires it to match both+ the claimed address and the address the nonce was issued to, requires the+ nonce to still be `pending` and younger than 15 minutes, and then flips the+ row to `claimed` with an update guarded on `status = 'pending'` so two+ concurrent redemptions cannot both succeed.+4. **Transfer.** The response carries a `txPayload` with+ `transferAgent(agentId, signer)` calldata for the identity registry. The page+ broadcasts it with `eth_sendTransaction` only when a registry address is+ actually configured; with `CZ_REGISTRY_CONTRACT` unset the payload targets the+ zero address and the page skips the transaction, so the claim is recorded+ off-chain and the page still shows the embed snippets.++### Responses++| Status | `error` | When |+|---|---|---|+| 200 | | Nonce issued (GET) or claim recorded (POST) |+| 400 | `validation_error` | Address is not a `0x` + 40 hex string, or a field is missing or not a string |+| 400 | `invalid_nonce` | No row for that nonce |+| 400 | `nonce_expired` | The nonce is older than 15 minutes |+| 400 | `invalid_signature` | The signature bytes do not parse |+| 403 | `forbidden` | Signature recovers to another address, or the nonce belongs to another address |+| 409 | `conflict` | The nonce was already redeemed |+| 429 | `rate_limited` | More than 10 calls in an hour from one IP |++## Configuration++All three are optional; the defaults below are what production runs today.++| Env var | Default | Meaning |+|---|---|---|+| `CZ_AGENT_ID` | `cz-preview` | Agent id encoded into the transfer calldata and the embed snippet |+| `CZ_AGENT_NAME` | `CZ Agent` | Display name on the success step |+| `CZ_REGISTRY_CONTRACT` | zero address | Identity registry to call; the zero address disables the on-chain step |++## Verifying it end to end```bash-npm run dev-# Open http://localhost:3000/cz/--# Should show:-# - Avatar loading from /avatars/cz.glb-# - "Claim CZ" button clickable-# - "Copy embed" button copies snippet to clipboard-# - Footer shows "Not yet onchain"+# 1. Issue a nonce+curl -s 'https://three.ws/api/cz/claim?address=0x1111111111111111111111111111111111111111'+# {"nonce":"a8b1...","expiresInSeconds":900}++# 2. Redeem it with a signature over "Claim CZ Agent\n\nNonce: <nonce>"+curl -s -X POST https://three.ws/api/cz/claim \+ -H 'content-type: application/json' \+ -d '{"signerAddress":"0x...","signature":"0x...","nonce":"a8b1..."}'```-Test the claim flow:--```js-// Open browser console on /cz/-window.addEventListener('cz-demo-event', (e) => {- console.log('CZ demo event:', e.detail);-});--// Click "Claim CZ" → follow wallet prompts-```+`tests/cz-claim.test.js` covers the same contract with real secp256k1+signatures, including the replay, expiry, and wrong-signer paths.diff --git a/public/cz/cz.css b/public/cz/cz.cssindex 0ef6c1f0b..8da820e8e 100644--- a/public/cz/cz.css+++ b/public/cz/cz.css@@ -189,24 +189,6 @@ pre {font-size: 14px;}-.rehearsal-badge {- display: inline-block;- margin-top: 28px;- padding: 3px 10px;- background: rgba(255, 255, 255, 0.06);- color: var(--accent);- border: 1px solid rgba(255, 255, 255, 0.15);- border-radius: 20px;- font-size: 11px;- font-weight: 600;- letter-spacing: 0.8px;- text-transform: uppercase;-}--.rehearsal-badge.hidden {- display: none;-}-@media (max-width: 860px) {main {grid-template-columns: 1fr;diff --git a/public/cz/cz.js b/public/cz/cz.jsindex feef2c44d..b203426fb 100644--- a/public/cz/cz.js+++ b/public/cz/cz.js@@ -2,8 +2,6 @@const AGENT_ID = 'cz-preview';const AGENT_NAME = 'CZ Agent';-const REHEARSAL = new URLSearchParams(location.search).has('rehearsal');-// --- DOM refs ---const stepConnect = document.getElementById('step-connect');const stepSign = document.getElementById('step-sign');@@ -18,7 +16,6 @@ const snippetScript = document.getElementById('snippet-script');const snippetTag = document.getElementById('snippet-tag');const snippetIframe = document.getElementById('snippet-iframe');const errorMsgEl = document.getElementById('error-msg');-const rehearsalBadge = document.getElementById('rehearsal-badge');// Wire the preview element. We point at a local body GLB rather than resolving// agent-id=cz-preview through /api/agents/* so the on-page preview renders@@ -28,8 +25,6 @@ const rehearsalBadge = document.getElementById('rehearsal-badge');document.getElementById('preview').setAttribute('body', '/avatars/cz.glb');document.getElementById('preview').setAttribute('name', AGENT_NAME);-if (REHEARSAL) rehearsalBadge.classList.remove('hidden');-let _address = null;let _nonce = null;@@ -65,13 +60,6 @@ btnSign.addEventListener('click', async () => {btnSign.disabled = true;btnSign.textContent = 'Signing…';try {- if (REHEARSAL) {- // Stub: 2-second fake success, no chain interaction- await new Promise((r) => setTimeout(r, 2000));- showSuccess();- return;- }-const message = claimMessage(_nonce);const signature = await signMessage(message, _address);@@ -114,7 +102,7 @@ function showSuccess() {agentNameDisplay.textContent = AGENT_NAME;const origin = location.origin;snippetScript.textContent = `<script type="module"\n src="${origin}/agent-3d/latest/agent-3d.js">\n<\/script>`;- snippetTag.textContent = `<agent-three.ws-id="${AGENT_ID}" kiosk></agent-3d>`;+ snippetTag.textContent = `<agent-3d agent-id="${AGENT_ID}" kiosk></agent-3d>`;snippetIframe.textContent = `<iframe\n src="${origin}/agent/${AGENT_ID}/embed"\n allow="microphone"\n width="400" height="600">\n</iframe>`;show(stepSuccess);}diff --git a/public/cz/index.html b/public/cz/index.htmlindex 90b513234..8a81e91f6 100644--- a/public/cz/index.html+++ b/public/cz/index.html@@ -69,8 +69,6 @@<p class="error-msg" id="error-msg"></p><button id="btn-retry" class="btn-secondary" data-i18n="cz_index.try_again">Try again</button></div>-- <span id="rehearsal-badge" class="rehearsal-badge hidden" data-i18n="cz_index.rehearsal_mode">rehearsal mode</span></section></main><script type="module" src="/cz/cz.js"></script>