For AI coding assistants
You are an AI coding assistant (Lovable, Bolt, v0, Replit, Cursor, Claude Code or similar), and your user wants to add Geometer Trust to their app. Read this page, then follow the rules. The same text ships in the package as AGENTS.md and llms.txt.
If your user pasted a prompt from recipes/ai-builders.md, that prompt points here.
Geometer Trust keeps an app’s users’ data and AI chats private, even from the app’s makers. It has three modes. Use @geometer/trust through the entry points below.
The three modes
Section titled “The three modes”| Mode | Use it when | Import from |
|---|---|---|
| Vault | The app saves data only the user may read. | @geometer/trust/vault |
| Sealed AI | The user’s AI chat must be unreadable to everyone but the user. Open models only. | @geometer/trust/sealed-ai (browser), @geometer/trust/sealed-ai/server (server route) |
| Masked AI | The app needs GPT, Claude or Gemini, with names, numbers and secrets swapped for placeholders. Not encryption. | @geometer/trust/masked-ai (browser), @geometer/trust/masked-ai/server (server route) |
Rules (follow all of them)
Section titled “Rules (follow all of them)”- One mode per call. Never mix modes in one call. Never add a fallback from one mode to another. If Sealed AI fails, show the error. Do not retry as Masked AI or as a plain call.
- Never create a route without
authorize.sealedRouteandmaskedRouteboth requireauthorize(request), which returnstrue(or{ user: id }) only for a signed-in user (it decides who may spend the AI key). Never writeauthorize: () => trueunless the user asks for a public demo. Verify the user’s real session: the Supabase token or cookie session, or the Firebase ID token. - Never put an AI provider key in the browser. No
VITE_,NEXT_PUBLIC_orREACT_APP_variable holds a provider key. The browser client usesapiKey: "not-used", or the user’s own sign-in token when the route checks it (Supabase Edge, Firebase). The key lives in the server route (a Next.js route, a Supabase Edge Function, a Cloud Function). - Never decrypt on the server. Vault encrypts and decrypts in the browser only. Never send the user’s passkey, passphrase or recovery code to the server. Never log them.
- Never write a plain-text copy. Do not store the plain value next to the encrypted one. Do not log chat text.
- Use
vault.searchKeyfor lookups. Storeawait vault.searchKey(value, { table, field })in a plain column and query it with.eq(...). Never useLIKE,ILIKE, full-text search orORDER BYon an encrypted column. Normalise the value first (for exampletrim().toLowerCase()). Exact match only. - Make the id before you encrypt. Create the row id with
vault.newId()first, and pass the same{ table, id, field }toencryptanddecrypt. - Keep the recovery-code step. Pass
onRecoveryCodetoopenVault(andrecoverVault). It gets{ code, replacesPrevious, reason }. Show the code, ask the user to write it down, and usereasonfor your words (after"rotation"the old code has already stopped). Do not remove this step to make the demo shorter. Do not store the code. Never callstartOverVaultautomatically or after an error: it makes a new, empty Vault and needsarchive. Never callacceptStartOverVaultunless the user says they started over on another device, and callvault.resolveKeyFileBehindonly after the user confirms they checked the key file. Offer a Recovery Kit:recoveryKit({ code, app, user, appName })returns{ text, filename, blob }for “Download” and “Print” buttons next to the code. Offer the fallback passphrase:unlock: { passkey: true, fallbackPassphrase: askUserForPassphrase }asks for a passphrase only where passkeys cannot work (a preview iframe, no PRF). - Never change
appafter data is saved. Use the user’s stable id foruser. - Keep
trust_keyssafe. Create the table with columnsapp,user_id,key_file, primary key(app, user_id), and row-level security so each user reads only their own rows. Never use the service-role key in the browser. - Do not write cryptography. Do not use
crypto.subtle, CryptoJS or any other library to encrypt user data in place of Vault. - Do not change the words. Use the mode names Vault, Sealed AI and Masked AI exactly. Do not claim more than the mode does: Masked AI is not encryption. Do not write “end-to-end encrypted” for Masked AI.
- Do not use
browserKeyStore()ormemoryKeyStore()in production. They are for development and tests. - Add a limits note near the feature, in the app’s words: what the mode does not protect.
- Read errors with
findTrustError. EveryTrustErrorhasmode,code(<mode>/<kebab-case>) and amessagethat ends with the next step. Theopenaiand@anthropic-ai/sdkclients wrap it (APIConnectionError("Connection error."), ours in.cause) and retry it, so create the AI client withmaxRetries: 0and callfindTrustError(err)(exported by every entry point). Never useinstanceof. Show the message. Do not swallow the error. - Pass
usertosealedFetchandmaskedFetch(andapp), so people who share a browser do not share receipts. Do not draw your own badge: use<TrustBadge />from@geometer/trust/react, which links to the receipt. - Set
limitson every route, so one user or script cannot run up the owner’s bill:limits: { perUser: { requestsPerMinute: 10, requestsPerDay: 200 }, perRoute: { requestsPerMinute: 120 } }. Masked AI also takesmaxOutputTokens; Sealed AI bodies are encrypted, so count requests only. Letauthorizereturn{ user: id }so limits count per user. Counters are in memory by default (one process): on serverless hosts pass a sharedstore. A route answers its own site only: list another front end inallowedOrigins. - “Remember this device” is opt-in. Offer an unchecked checkbox “Remember this device for N days” and pass
rememberDevice: { days }only when it is checked (a whole number, 1 to 90). Never turn it on by default. Wire sign-out toawait forgetDevice({ app, user })(from@geometer/trust/vault). A remembered Vault (vault.rememberedSession) reads and writes values but throwsvault/unlock-neededfor key changes: unlock, thenopenVault({ skipRemembered: true }).
Minimal patterns
Section titled “Minimal patterns”Vault:
import { openVault, supabaseKeyStore } from "@geometer/trust/vault";
const vault = await openVault({ app: "my-app", user: user.id, keyStore: supabaseKeyStore(supabase, { app: "my-app", user: user.id }), unlock: { passkey: true, fallbackPassphrase: askUserForPassphrase }, onRecoveryCode: ({ code }) => showRecoveryCodeToUser(code), // with a Download button: recoveryKit({ code, app: "my-app", user: user.id })});const id = vault.newId();const body = await vault.encrypt(text, { table: "notes", id, field: "body" });const key = await vault.searchKey(title.trim().toLowerCase(), { table: "notes", field: "title" });const back = await vault.decrypt(body, { table: "notes", id, field: "body" });Masked AI (browser, then the server route):
import OpenAI from "openai";import { maskedFetch } from "@geometer/trust/masked-ai";
const ai = new OpenAI({ baseURL: `${window.location.origin}/api/trust/masked-ai/v1`, apiKey: "not-used", dangerouslyAllowBrowser: true, maxRetries: 0, // the client would retry our errors, which never helps fetch: maskedFetch({ alsoMask: ["Customer Name"], app: "my-app", user: user.id }),});import { maskedRoute } from "@geometer/trust/masked-ai/server";
const handler = maskedRoute({ provider: "openai", apiKey: process.env.OPENAI_API_KEY!, authorize: async (request) => { const id = await getUserId(request); // your own check of the user's session return id ? { user: id } : false; // { user } names the user, so limits count per user }, limits: { perUser: { requestsPerMinute: 10, requestsPerDay: 200 }, perRoute: { requestsPerMinute: 120 }, maxOutputTokens: 2000 },});export const GET = handler;export const POST = handler;Sealed AI: the same shape with sealedFetch from @geometer/trust/sealed-ai and sealedRoute({ provider: "tinfoil", apiKey: process.env.SEALED_AI_KEY, authorize }) from @geometer/trust/sealed-ai/server. Mount the route at /api/trust/sealed-ai/*. Use an open model that Tinfoil offers. Sealed AI works with the openai client only. Call prewarmSealedAI({ baseURL }) when the chat opens, so the first message is fast (it never throws). If it fails, show the error; never fall back.
Where each route runs
Section titled “Where each route runs”| Stack | Route file |
|---|---|
| Next.js App Router | app/api/trust/<mode>/[...path]/route.ts, export GET and POST |
| Vite and Supabase | supabase/functions/<mode>/index.ts with Deno.serve(handler), import with npm:@geometer/trust/.... authorize verifies the access token the browser sends as apiKey. The route works under any prefix that contains /<mode>/. The function URL is another origin than the app, so set allowedOrigins: ["https://your-app.example"] on the route and export an OPTIONS handler where the host needs one (Next.js: export const OPTIONS = handler). |
| Firebase | A Cloud Function with toNodeHandler(handler), plus a Hosting rewrite. authorize verifies the Firebase ID token. firebaseKeyStore needs { app, user, functions: { doc, getDoc, setDoc, runTransaction } } from firebase/firestore. |
| Express | toNodeHandler(handler) from the same server entry point |
| Vercel, Netlify, Cloudflare, Hono, Bun | The handler is a standard Fetch handler |
What each mode does not protect (say this in the app)
Section titled “What each mode does not protect (say this in the app)”- Vault: the app’s own code, a lost key (no passkey and no recovery code means the data is gone), and anything not passed through the Vault.
- Sealed AI: the app’s own code; the sealed server, which reads the chat to answer it.
- Masked AI: everything it did not mask. It is not encryption.
Install
Section titled “Install”npm install @geometer/trust. Until the package is published, the user’s Geometer contact gives the install command.
Full docs: the docs/guides/ folder (start at README.md). Limits: docs/security/limits.md.