Skip to content

feat: Mochi's sealed note via NEAR AI private inference, behind VITE_SEALED_NOTE_ENABLED - #5

Merged
dadadave80 merged 21 commits into
mainfrom
feat/sealed-note
Nov 13, 2026
Merged

dadadave80 merged 21 commits into
mainfrom
feat/sealed-note

Conversation

@dadadave80

Copy link
Copy Markdown
Owner

What

After an accepted return, Mochi can write a short note through NEAR AI Cloud private inference (z-ai/glm-5.3-flash, Intel TDX and NVIDIA TEE).

  • Browser:
    • Fetches the model's attestation and verifies every instance with @nearai/inference-sdk 0.3.0, requiring GPU evidence and one shared Ed25519 key.
    • Encrypts both messages (E2EE v3) with a one-use key, sends the exact bytes, then decrypts the reply.
    • Sealed only if signature_kind is provider_tee, the signed text equals <model>:sha256(request):sha256(response), and the signature verifies against the attested key. Otherwise the note is Not sealed (with the reason), Seal not recorded yet (retryable, not stored) or broken (no text shown).
    • Only the harbor name and recent accepted returns are sent; no player-written text.
    • Sealed line: "Written where nobody could read over her shoulder."
  • Relay: POST /api/v1/privy/note, under the existing Privy origin, JWT, size and quota checks.
    • Checks only plain fields: model, stream=false, max_tokens ≤ 120, two ciphertext messages, canonical JSON, 8 KB cap.
    • The account must have an accepted claim on familiar-game.testnet.
    • Forwards the bytes unchanged with the server-held NEAR_AI_API_KEY, and never decodes or logs content.
    • Allowance: 3 notes per account per UTC day, 3/hour per account, 120/hour overall, all checked before any is charged.
    • Every step is bounded inside the 60 s function limit.
    • Returns 503 when the key is unset.
  • Docs:
    • THREAT-MODEL gains a relay row and a sealed-note section, including NEAR AI's limit that instances share signing keys: the claim is only "signed by the attested model key".
    • JUDGES gains two reproducible rows.
    • PROGRESS records the commands, the live chat ids, and the NEAR AI doc discrepancies (docs describe E2EE v2 while the SDK and live service use v3; attestation needed no key; thinking_token_budget vs enable_thinking).

Flag

VITE_SEALED_NOTE_ENABLED reaches the production build only when VERCEL_ENV=production, a Privy app ID is set, and the value is exactly true. Previews never get it, so production is unchanged after merge until the flag is set.

Verified locally

  • bun run test: 264 pass.
  • cargo test --workspace: 130 pass.
  • Typecheck, make build, bun run build:release, make browser (Chromium and WebKit) and make evidence pass.
  • Crypto reproduces NEAR AI's official v3 Ed25519 test vector.
  • Live NEAR AI: notes sealed with provider_tee signatures that verified:
    • chat daa6b158… (Bun), 20d3c9c6… (Chromium) and d8b367f5… (WebKit), using the real browser code.
    • Two earlier attempts broke before the reasoning-budget fix.
    • 5 completions used in total.
  • Reviews: three independent review rounds. The first found 5 confirmed issues, the second 5, the third 2. All are fixed in this branch, and none could mark a note sealed falsely.

Not verified (production-only after merge)

  • The Privy JWT and eligibility path, the deployed relay on Vercel, and the note in the real game with the flag on.
  • The latest review fixes were not run against a live NEAR AI completion.
  • The "failed retry keeps the readable note" path is typechecked but not exercised in a browser.
  • Quotas are per instance and reset on restart, as THREAT-MODEL states.

To switch on (David)

  1. Merge. NEAR_AI_API_KEY is already in Production.
  2. Set VITE_SEALED_NOTE_ENABLED=true for Production and redeploy.
  3. Sign in with an account that has an accepted return and ask for one note.

…relay step

Check the daily, hourly and global allowances before charging any, bound register reads, the completion and the signature lookup from the request start, and match the invite copy to the one-note-per-harbor behaviour.
@vercel

vercel Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
familiar Ready Ready Preview Nov 13, 2026 11:29pm UTC

@dadadave80
dadadave80 merged commit 0a691de into main Nov 13, 2026
3 checks passed
@dadadave80
dadadave80 deleted the feat/sealed-note branch November 13, 2026 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant