Getting started with TypeScript.
Install one zero-dependency Node package, connect with your service key, and store your first sealed record in about fifty lines.
TypeScript · zero dependencies
1. Install the package
npm install vaultdb-client@0.4.0 installs the package from npm. It runs on Node 26 or newer with no external dependencies, using only Node's built-in node:crypto, node:zlib, and WebSocket.
2. Get a server to talk to
To try it, run a test server on your machine: vaultdb-hosted --memory keeps nothing on disk and prints its service card on its first line. Put that line in VAULTDB_CARD. For real use, write to us: make a service key once with generateServiceKey(), keep secret in your app, send us only its public half, and we send you your card.
3. Run the example
It connects, creates a vault whose key you derive yourself, puts a deal and a note, searches by the start of a title, stores a file and reads it back, and reads the audit trail.
import { randomBytes, hkdfSync } from "node:crypto";
import { Writable } from "node:stream";
import { bytesSource, Connection, createVault, generateServiceKey } from "vaultdb-client";
async function main() {
// The service key is made once and kept by your app. Give its public key to whoever runs your service.
const { secret } = generateServiceKey();
// The service card is what your operator sent you: a line of JSON.
const conn = await Connection.connect(process.env["VAULTDB_CARD"] ?? "", secret);
const call = { actor: "user-42" }; // whoever is acting in your app; it goes into the audit
try {
// The vault key is made here, in your app, and never leaves it.
const k = new Uint8Array(hkdfSync("sha256", "a long secret only my app knows", "my-app", "vault key", 32));
const declaration = {
types: {
deal: { parents: [""] },
note: { parents: ["deal"], fields: { title: { exact: true } } },
},
};
const vault = await createVault(conn, k, declaration, call);
// Put: a deal, and a note under it. What you put is sealed before it leaves your app.
const crid = new Uint8Array(randomBytes(16));
const deal = await vault.put({ type: "deal", indexed: {}, app: new TextEncoder().encode("Acme"), crid }, call);
await vault.put(
{ type: "note", indexed: { title: "Kickoff meeting" }, app: new TextEncoder().encode("Friday at ten"), parent: { id: deal.id } },
call,
);
// Search: the server finds it without ever seeing the words.
const found = await vault.search("note", [{ field: "title", match: "prefix", text: "kick" }], call);
// A file: put in parts of 4 MiB, each compressed and sealed; read back part by part into any Writable.
const terms = new TextEncoder().encode("Net 30 days.");
await vault.putFile(bytesSource(terms), { entry: deal.id, recordCrid: crid, name: "terms.txt", type: "text/plain" }, call);
const [file] = (await vault.listFiles(deal.id, crid, call)).files;
const chunks: Buffer[] = [];
const sink = new Writable({
write(chunk: Buffer, _encoding: string, done: () => void) {
chunks.push(chunk);
done();
},
});
await vault.readFile(file!.info, crid, sink, call);
// Audit: every call is on the record, with the actor you named.
const audit = await vault.auditRead(call);
return { notes: found.records.length, file: Buffer.concat(chunks).toString("utf8"), audit: audit.events.map((e) => e.op) };
} finally {
conn.close();
}
}4. What it returns
notes: 1, file: "Net 30 days.", and audit containing "put", "get_file", and the other calls from the run.
Where your key comes from
You derive the 32-byte vault key on your side from your own secret, as the example does with hkdfSync. We never see it. If you lose it, nobody can open the vault, us included.
Files, concurrency, and errors
Every call is async, accepts an optional AbortSignal, shares one connection (up to 64 calls in flight), and never retries silently; vault.seal(item) lets you repeat a write safely without creating a duplicate. Files up to 1 GiB go up in 4 MiB parts from fileHandleSource or bytesSource; to resume an interrupted upload, prepare it once with prepareFile and pass that object to putFile again so only the missing parts are sent. readFile writes into a Node Writable or a WritableStream — if it rejects with CLAV-STOR-INTEGRITY, discard what was written so far. Errors report code, detail, next, and retryAfterMs where waiting helps.
When a node changes its key
When a node changes its key, Connection.connect follows it by itself — nobody needs a new card. If we switch your vault over to its second copy, the client follows there too. conn.card() returns the current card, and passing { onCardChange: (card) => save(card) } as the third argument calls your handler once with the updated card JSON so you can save it; a program that never saves keeps working and learns the new key again on its next start.
Plain tables
A vault also holds plain SQLite tables of your own, for state about no one in particular: counters, queues, slots, settings. vault.plainQuery(sql, params, call) reads and vault.plainTx(statements, call) writes several statements all or nothing, with optional expect checks. Only the vault's owner may call them. The SQL, its parameters and the rows are readable by the server and are not audited, and a row you delete stays in the vault's log until you shred the vault, so personal data stays in sealed records.