Skip to main content

@midnight/ledger v2.0.8Readme | API


@midnight/ledger v2.0.8 / 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