Skip to main content

StateBoundedMerkleTree

@midnight-ntwrk/onchain-runtime v0.2.2 β€’ Readme | API


@midnight-ntwrk/onchain-runtime v0.2.2 / StateBoundedMerkleTree

Class: StateBoundedMerkleTree

Represents a fixed-depth Merkle tree storing hashed data, whose preimages are unknown

Constructors​

new StateBoundedMerkleTree(height)​

new StateBoundedMerkleTree(height): StateBoundedMerkleTree

Create a blank tree with the given height

Parameters​

β€’ height: number

Returns​

StateBoundedMerkleTree

Properties​

height​

readonly height: number;

Methods​

collapse()​

Internal

collapse(start, end): StateBoundedMerkleTree

Erases all but necessary hashes between, and inclusive of, start and end inidices

Parameters​

β€’ start: bigint

β€’ end: bigint

Returns​

StateBoundedMerkleTree

Throws​

If the indices are out-of-bounds for the tree, or end < start


findPathForLeaf()​

Internal

findPathForLeaf(leaf): AlignedValue

Internal implementation of the finding path primitive

Parameters​

β€’ leaf: AlignedValue

Returns​

AlignedValue

Throws​

If the leaf is not in the tree


pathForLeaf()​

Internal

pathForLeaf(index, leaf): AlignedValue

Internal implementation of the path construction primitive

Parameters​

β€’ index: bigint

β€’ leaf: AlignedValue

Returns​

AlignedValue

Throws​

If the index is out-of-bounds for the tree


root()​

Internal

root(): Value

Internal implementation of the merkle tree root primitive

Returns​

Value


toString()​

toString(compact?): string

Parameters​

β€’ compact?: boolean

Returns​

string


update()​

update(index, leaf): StateBoundedMerkleTree

Inserts a value into the Merkle tree, returning the updated tree

Parameters​

β€’ index: bigint

β€’ leaf: AlignedValue

Returns​

StateBoundedMerkleTree

Throws​

If the index is out-of-bounds for the tree