Class: OptimizedSMT ​
Defined in: optimized-smt.ts:20
Optimized Sparse Merkle Tree.
Lifecycle: add() indexes → setHash() per leaf → finalize() → proof(). Call reset() to clear hashes and re-finalize with new data.
Constructors ​
Constructor ​
new OptimizedSMT(
allowNonInclusion):OptimizedSMT
Defined in: optimized-smt.ts:32
Parameters ​
allowNonInclusion ​
boolean
Returns ​
OptimizedSMT
Properties ​
BITS ​
readonlystaticBITS: readonlybigint[]
Defined in: optimized-smt.ts:25
Pre-computed MSB-first bit masks for tree traversal.
OUTER_BIT ​
readonlystaticOUTER_BIT:bigint
Defined in: optimized-smt.ts:22
2^256 — sentinel bit above the key space. Used by batch validation.
Accessors ​
allowNonInclusion ​
Get Signature ​
get allowNonInclusion():
boolean
Defined in: optimized-smt.ts:36
Returns ​
boolean
rootHash ​
Get Signature ​
get rootHash():
Uint8Array
Defined in: optimized-smt.ts:39
Root hash. Throws if tree has not been finalized.
Returns ​
Uint8Array
Methods ​
add() ​
add(
indexes):void
Defined in: optimized-smt.ts:52
Add leaf indexes to the tree. May be called multiple times before finalization. Duplicate indexes throw.
Parameters ​
indexes ​
bigint[]
Returns ​
void
finalize() ​
finalize():
void
Defined in: optimized-smt.ts:133
Compute root hash and generate all proofs in a single recursive pass. Must be called after all hashes are set.
Returns ​
void
proof() ​
proof(
index):SMTProof
Defined in: optimized-smt.ts:145
Retrieve the proof for an index. Only valid after finalize.
Parameters ​
index ​
bigint
Returns ​
reset() ​
reset():
void
Defined in: optimized-smt.ts:152
Clear hashes and proofs, keeping the tree structure for reuse.
Returns ​
void
setHash() ​
setHash(
index,hash):void
Defined in: optimized-smt.ts:111
Set the hash for a leaf at the given index. The index must have been previously added via add. Each leaf's hash can only be set once (until reset).
Parameters ​
index ​
bigint
hash ​
Uint8Array
Returns ​
void