Documentation
Runnable examples
Copy these into the repo tests or the /api/clear playground. They encode the two failure modes that matter most.
Double-spend must fail
First spend of a nullifier succeeds. Second spend with the same nullifier throws DoubleSpendError and leaves the ledger unchanged beyond the first mark.
const ledger = new CommitmentLedger();
const nf = demoNullifier("alice-1");
ledger.spend(nf, demoCommitment("out-1"), true);
ledger.spend(nf, demoCommitment("out-2"), true); // throwsOut-of-band clear must fail
If every limit sits outside ±band around reference, clearBatch returns { ok: false, reason: "outside_band" }. There is no fallback "best effort" print.
clearBatch(
[{ id: "b1", side: "bid", limit: 120, size: 10 }],
[{ id: "a1", side: "ask", limit: 121, size: 10 }],
100,
50,
);
// → { ok: false, reason: "outside_band" }