@tryengrave/client
v0.1.4
Published
Isomorphic Engrave SDK with local-by-default proof verification and fork detection.
Readme
@tryengrave/client
The official isomorphic SDK for Engrave — record tamper-evident events, wrap agent runs, and verify proofs locally by default. Runs in Node, Bun, Deno, Cloudflare Workers, and the browser.
npm install @tryengrave/clientQuickstart
import { Engrave } from "@tryengrave/client"
const engrave = new Engrave({ apiKey: "ek_live_…" })
// 1 — record an event, get a receipt
const receipt = await engrave.record({ key: "evt/order/1001", value: JSON.stringify({ amount: 250 }) })
// 2 — verify it, in THIS process, with no trust in the server
const result = await engrave.verify(`tx:${receipt.tx_id}/0`)
if (!result.ok) throw new Error(`verification failed at ${result.step}`)verify() fetches the proof material and recomputes the entry digest, both Merkle paths, the transaction hash, and the Ed25519 signature on your side. Pass { trustServer: true } only if you explicitly want the server's word for it — the default doesn't.
Fork detection
Every response carries the signed tree size and root. The client tracks them and surfaces a fork the moment the server's history diverges from what you've already seen — pin the tenant public key (publicKey option) to make the first read trustless too.
What you can do
- Records & reads —
record,get,history,tx,search,state,usage - Proofs —
proofInclusion,proofConsistency,verify,publicKey - Agent runs —
runStart,runSpan,runClose,trace(a hash-linked trace of every step an agent took) - Evidence —
requestExport,downloadExport,erase(crypto-shred a value while its proof survives) - Keys —
createApiKey,listApiKeys
Auto-instrument your model calls
If your agent calls OpenAI or Anthropic directly, wrap the client once — every
model call becomes a verifiable inference span (prompt/completion hashes by
default, full text with captureContent). Streaming is handled; behaviour is
byte-identical and recording never blocks.
import OpenAI from "openai"
import { startRunSession } from "@tryengrave/client"
import { instrumentOpenAI } from "@tryengrave/client/openai"
const run = await startRunSession(engrave, "triage ticket #4471")
const openai = instrumentOpenAI(new OpenAI(), run) // ← every call engraved
await openai.chat.completions.create({ model: "gpt-4o", messages })
await run.close()@tryengrave/client/anthropic exports instrumentAnthropic for Claude the same way.
Options
new Engrave({
apiKey: "ek_live_…",
baseUrl: "https://api.tryengrave.com", // default
publicKey: "…hex…", // pin the tenant key → trustless first read
})Part of Engrave — immutable audit evidence, verifiable by anyone. · Docs · MIT
