Create a new incremental merkle tree
See type
Protected_Internal method to get a reference to the buffer slice for a node at a given index
element-wise index
subarray of bytesPerElement aligned to a multiple of the node size
Protected_Internal method to set a node at a given
element-wise index
bytesPerElement-sized buffer to copy
Get a reference to the leaf node at a given index
Zero-based index of the leaf node. Out of bounds indices will throw an error
Read-only zero-copy leaf node
Insert nodes at a given index of the tree. Supports either a single node or an array of nodes,
efficiently updating parents. Note only up to size elements can be filled, overfilling will
cause an assertion error.
start index of first element
single element or sequence of consecutive elements
index after last element inserted. Useful for chaining inserts
Return the root element of the tree
Read-only zero-copy root element
Generate an inclusion proof for a given index. Returns an object with the index, root and path elements, where path elements are the first sibling and uncles of the node up to the root.
Leaf index to prove
Merkle proof for the given leaf index
Append nodes at the end of the tree
Either a single node or list of nodes to append
new length of the tree
Clone the current tree into an independent instance
Cloned SparseMerkleTree instance
Zero-copy a serialisable representation of the current tree into a plain object
Serializable object representation of the tree
StaticLEAF_Level of leaf nodes in the tree. All leaf nodes are at this level, while all internal nodes are at higher levels.
ReadonlybufUnderlying buffer holding all tree nodes
Readonlyhash3-arity hash function deriving parents. First argument is output buffer to be populated with the hash digest
ReadonlybytesBytes per node
ReadonlycapacityTotal number of nodes in the tree
Protected Readonly_Cached index of root node
ReadonlysizeTotal number of leaf nodes in the tree
ReadonlydepthDepth of the tree
ReadonlylengthNumber of filled leaves in the tree
StaticcreateCreate a new SparseMerkleTree instance with the given parameters, allocating memory to contain all nodes. Initializes the tree with the zero element. Returns an instance to use
Creation parameters
Depth of the tree, excluding the root node. Must be at least 1
Hash function to use for internal nodes. Must follow the InplaceMerkleHashFn signature
Zero element to use for leaf nodes. Internal nodes are calculated up to the root. Must be at least 1 byte
Number of filled leaves in the tree. Defaults to 0
Instance of MerkleTree
StaticfromCreate a new SparseMerkleTree instance from a serialized object and global parameters
Serialized object of the merkle tree
Additional system parameters
Instance
Sparse Merkle Tree implementation. Extends the base Merkle Tree, but provides the convenience of appending nodes at the end of the tree.