इसे छोड़कर कंटेंट पर जाएं

Quickstart

यह कंटेंट अभी तक आपकी भाषा में उपलब्ध नहीं है।

The shortest path to a first result. Vault first, then each AI mode. Each part works alone.

Terminal window
npm install @geometer/trust

Until the package is published, your Geometer contact gives you the install command. You also need openai (npm install openai) for the AI parts.

1. Vault: save one encrypted note (about 10 minutes)

Section titled “1. Vault: save one encrypted note (about 10 minutes)”

You need: a React app (or any browser app). Vault code runs in the browser only: in Next.js put it in a file that starts with "use client";, and call it from a user action (a button), not while the page renders.

Path A. Try it now, no account (development only)

Section titled “Path A. Try it now, no account (development only)”

browserKeyStore() keeps the key file in this browser’s localStorage. It needs no database and no sign-in. Development only: switch to the Supabase or Firebase store (Path B) before real users, because the key file then lives in one browser and is lost with it.

import { openVault, browserKeyStore } from "@geometer/trust/vault";
export async function saveFirstNote(text: string) {
const vault = await openVault({
app: "my-notes", // your app's name. Never change it later.
user: "dev-user", // in a real app: the signed-in user's id
keyStore: browserKeyStore(),
unlock: { passphrase: "four random words go here" }, // see "Unlocking" below
onRecoveryCode: ({ code }) => {
window.alert(`Write this recovery code down:\n\n${code}`);
},
});
const id = vault.newId(); // make the id first: it is part of the encryption
const saved = await vault.encrypt(text, { table: "notes", id, field: "body" });
const back = await vault.decrypt(saved, { table: "notes", id, field: "body" });
return { id, saved, back }; // `saved` is scrambled text, `back` equals `text`
}

Step 1. Create the key table. Open the Supabase SQL editor and run this once. Each user can read only their own key file.

create table if not exists public.trust_keys (
app text not null,
user_id uuid not null references auth.users (id) on delete cascade,
key_file text not null,
updated_at timestamptz not null default now(),
primary key (app, user_id)
);
alter table public.trust_keys enable row level security;
create policy "read own key file" on public.trust_keys
for select using (auth.uid() = user_id);
create policy "add own key file" on public.trust_keys
for insert with check (auth.uid() = user_id);
create policy "change own key file" on public.trust_keys
for update using (auth.uid() = user_id) with check (auth.uid() = user_id);

Create a table for the notes too. The body column holds the encrypted string.

create table if not exists public.notes (
id uuid primary key,
user_id uuid not null default auth.uid() references auth.users (id),
body text not null
);
alter table public.notes enable row level security;
create policy "own notes" on public.notes
for all using (auth.uid() = user_id) with check (auth.uid() = user_id);

Step 2. Save one note. Put this in a file such as src/saveFirstNote.ts. It runs after the user signs in.

import { createClient } from "@supabase/supabase-js";
import { openVault, recoveryKit, supabaseKeyStore } from "@geometer/trust/vault";
const supabase = createClient(
import.meta.env.VITE_SUPABASE_URL,
import.meta.env.VITE_SUPABASE_ANON_KEY,
);
export async function saveFirstNote(text: string) {
const { data } = await supabase.auth.getUser();
const user = data.user;
if (!user) throw new Error("Sign in first.");
const vault = await openVault({
app: "my-notes", // your app's name. Never change it later.
user: user.id,
keyStore: supabaseKeyStore(supabase, { app: "my-notes", user: user.id }),
unlock: "passkey",
onRecoveryCode: ({ code, replacesPrevious, reason }) => {
// Shown at first setup (reason "setup"), and again whenever a new code is made or an earlier one was never
// confirmed (reason "unconfirmed", "recovery", "requested" or "rotation"). If replacesPrevious is true, say the
// old code stops working. After reason "rotation" the old code has already stopped.
window.alert(`Write this recovery code down:\n\n${code}`);
// Better: offer "Download" and "Print" next to the code. The Recovery Kit is a plain-text file with the code,
// where to keep it, and that your app never asks for it by message:
// const kit = recoveryKit({ code, app: "my-notes", user: user.id }); // { text, filename, blob }
// a.href = URL.createObjectURL(kit.blob); a.download = kit.filename; a.click();
},
});
const id = vault.newId(); // make the id first: it is part of the encryption
const saved = await vault.encrypt(text, { table: "notes", id, field: "body" });
// Your own table. Any text column holds the encrypted string.
const { error } = await supabase.from("notes").insert({ id, body: saved });
if (error) throw error;
const back = await vault.decrypt(saved, { table: "notes", id, field: "body" });
return { id, saved, back }; // `back` equals `text`
}

Check it worked: open your notes table in Supabase. The body column holds scrambled text, not the note. In the app, back shows the note.

unlock: "passkey" needs a browser and passkey that support the WebAuthn PRF extension, and the app open in its own tab. In a preview frame from another site (Lovable, Bolt) or in a browser without PRF, Vault says vault/passkey-unsupported. Use unlock: { passphrase: "..." } there, or let Vault ask only when it must: unlock: { passkey: true, fallbackPassphrase: () => askUserForPassphrase() } tries the passkey and calls your function only where passkeys cannot work. A new passphrase needs at least 15 characters, must not be a common password, must not contain the app name or user id, and must not have a run of 6 identical or consecutive characters. Four or more random words pass.

Next: Vault in full.

2. Sealed AI: one private chat (about 15 minutes)

Section titled “2. Sealed AI: one private chat (about 15 minutes)”

You need: a server route that holds your Sealed AI key. Pick your stack: Next.js, Vite and Supabase Edge, Firebase.

Step 1. The server route. Next.js example, in app/api/trust/sealed-ai/[...path]/route.ts (src/app/api/... if your project has a src folder, as create-next-app offers):

import { sealedRoute } from "@geometer/trust/sealed-ai/server";
import { isSignedIn } from "@/lib/authorize"; // your own check of the session: see the Next.js recipe
const handler = sealedRoute({
provider: "tinfoil",
apiKey: process.env.SEALED_AI_KEY!,
authorize: (request) => isSignedIn(request), // required: who may use your key
});
export const GET = handler;
export const POST = handler;

authorize is required. It decides who may spend your key, and it guards the evidence calls too. isSignedIn is shown in the Next.js recipe (it uses Supabase); other stacks have their own check in their recipe. With another sign-in, write your own src/lib/authorize.ts: export async function isSignedIn(request: Request): Promise<boolean> that returns true only when your session check says the user is signed in (read your session cookie or token from request.headers). Do not return true for everyone. Put SEALED_AI_KEY in your server’s environment variables. Never in code the browser loads.

Step 2. The browser. This code runs in the browser. In Next.js, put it in a file that starts with "use client"; or is imported only by one. Call askPrivately from a button or effect, not while the page renders on the server.

import OpenAI from "openai";
import { findTrustError, sealedFetch } from "@geometer/trust/sealed-ai";
const ai = new OpenAI({
baseURL: `${window.location.origin}/api/trust/sealed-ai/v1`,
apiKey: "not-used", // the real key lives only on the server
dangerouslyAllowBrowser: true,
maxRetries: 0, // the client would retry a failed check, which never helps
fetch: sealedFetch(),
});
export async function askPrivately(question: string) {
try {
const reply = await ai.chat.completions.create({
model: "<model>", // an open model that Tinfoil offers: signed in, open /api/trust/sealed-ai/v1/models to see the list
messages: [{ role: "user", content: question }],
});
return reply.choices[0]?.message.content;
} catch (err) {
const problem = findTrustError(err); // the client wraps our error: this finds it
if (problem) throw new Error(problem.message); // ends with the next step
throw err;
}
}

Check it worked: the call returns an answer. If the server cannot be checked, the call fails with a sealed-ai/... error. It never falls back. See errors.

Next: Sealed AI in full.

3. Masked AI: one masked chat (about 10 minutes)

Section titled “3. Masked AI: one masked chat (about 10 minutes)”

Step 1. The server route. Next.js example, in app/api/trust/masked-ai/[...path]/route.ts (src/app/api/... if your project has a src folder, as create-next-app offers):

import { maskedRoute } from "@geometer/trust/masked-ai/server";
import { isSignedIn } from "@/lib/authorize"; // your own check of the session: see the Next.js recipe
const handler = maskedRoute({
provider: "openai",
apiKey: process.env.OPENAI_API_KEY!,
authorize: (request) => isSignedIn(request), // required: who may use your key
});
export const GET = handler;
export const POST = handler;

Step 2. The browser. Same rule as above: browser code. In Next.js, "use client"; at the top, and call askMasked from a button.

import OpenAI from "openai";
import { findTrustError, maskedFetch } from "@geometer/trust/masked-ai";
const ai = new OpenAI({
baseURL: `${window.location.origin}/api/trust/masked-ai/v1`,
apiKey: "not-used", // the real key lives only on the server
dangerouslyAllowBrowser: true,
maxRetries: 0, // the client would retry a refusal, which never helps
fetch: maskedFetch({
alsoMask: ["Asha Menon", "Acme Traders"], // names your app knows
onMasked: (summary) => console.log(summary.counts), // counts by type, never values
}),
});
export async function askMasked() {
try {
const reply = await ai.chat.completions.create({
model: "gpt-4o-mini",
messages: [
{ role: "user", content: "Write a reminder to Asha Menon at asha@example.com about her invoice." },
],
});
return reply.choices[0]?.message.content; // the real name and email are put back on the device
} catch (err) {
const problem = findTrustError(err);
if (problem) throw new Error(problem.message);
// Your route said no (for example 401 `masked-ai/not-authorized` when nobody is signed in): the client's own error, `err.status` and `err.code`.
throw err;
}
}

Check it worked: in your browser’s Network tab, the request body holds placeholders, not the name or the email. The answer on screen holds the real ones.

Masked AI is not encryption. The AI company reads everything that was not masked. Next: Masked AI in full.