Maintain a signed key-event log and content-addressed trails with rotations, witness receipts, and duplicity evidence. The main entry is browser-safe; file persistence and Node HTTP helpers are exported from @toip-tools/eventlog/node.
Install the package from npm. It needs Node 22.13 or later, or a bundler for browser entry points.
ShellInstall
npm install @toip-tools/eventlog
Runtime: Browsers and Node. A file store and an HTTP witness are in the Node entry.
TypeScriptImport
import { Controller, Trail, MemoryStore } from "@toip-tools/eventlog";
Usage
Create a controller and append a witnessed trail entry
Choose hot signers, commit future keys using coldKeysFromSeed or explicit next-key digests, and call Controller.incept with a store and clock. Open a trail with openTrail(purpose). Use appendWitnessed when an external action must wait for receipts; ordinary append only signs and stores locally. Publish to witness clients and inspect missing receipts and evidence.
Call Controller.rotate with the committed future signers or retained cold keys. Rotation seals trail heads automatically. For recovery, cutAfter cuts later trail entries, and supersede can replace interaction events with a rotation. Persist newly active signers from signers() securely. Passing next: [] abandons the identifier and prevents further controller events.
Run verifyKel and verifyTrail on received history, then inspect problems and witness status. Use checkTrailRef with a witness client to verify a referenced entry, or verifySignature to distinguish a valid signature from its current/retired and anchored status. Export selected bodies or entries with exportBundle and verify received bundles with verifyBundle. A Watcher can ingest first-seen copies and poll witnesses for conflicting histories.
Persist logs, bodies, receipts, and evidence through a LogStore. MemoryStore.dump() can be restored through its constructor, but it is not durable by itself. Node's JsonFileStore batches writes; call flush() or close() at shutdown to write pending changes.
Keep cold-key material separate from current hot keys. Controller.load re-verifies stored logs; supplying hot keys supports appending and interacting, while rotation additionally needs committed future signers or matching cold keys.
Trail.close() records a signed end-of-trail event. It is a protocol operation, not a resource cleanup call. Watcher.poll() is caller-driven; own and cancel any application polling timer and close HTTP servers/file stores that you create.
Error handling
WitnessError
appendWitnessed throws if fewer than max(1, bt) witness receipts are held. The newly appended entry remains in the local log, pending.
Do not perform the dependent external action. Inspect details.missing, retry publishing the existing entry, and reconcile its receipt state instead of appending a duplicate action.
Verification reports structured problems with a code, message, and optional log/sequence location. Unsupported protocol features are identified separately from invalid signatures or missing witness thresholds.
Check result problems before accepting history. Fetch missing receipts or use a compatible implementation for unsupported features; do not bypass signature checks.
Witness submission can refuse history and may return receipts for messages accepted before the refusal. Duplicity may include the first-seen conflicting stream.
Retain valid partial receipts and conflicting evidence. Supply the controller KEL before its trails, correct clock skew, and investigate conflicts before acting. Controller.publish collects such failures in its report.
API reference
Choose an entry point for the complete export list. Each export has a reference page with its signature, parameter types, return type, fields, and public methods where applicable.