Skip to main content
Version: 2.0.0-beta-4

Incremental Merkle Tree

info

The tree extends from @zk-kit/incremental-merkle-tree

Import this class like so:

import { IncrementalMerkleTree } from '@unirep/utils'

const tree = new IncrementalMerkleTree(32)

constructor

Get a new tree instance.

constructor(
depth: number,
zeroValue: Node = 0,
arity: number = 2
): IncrementalMerkleTree

Node

The type of each leaf.

type Node = any

insert

Insert a new leaf in the next free index.

tree.insert(leaf: Node)

update

Update a leaf in the tree by index.

tree.update(index: number, leaf: Node)

delete

Delete (set to zero value) a leaf in the tree.

tree.delete(index: number)

indexOf

Get the index of given node.

tree.indexOf(leaf: Node)

MerkleProof

A struct for representing merkle proofs.

type MerkleProof = {
root: any
leaf: any
siblings: any[]
pathIndices: number[]
}

createProof

Get a merkle inclusion proof for an index.

tree.createProof(index: number): MerkleProof

verifyProof

Verify a merkle proof in the tree.

tree.verifyProof(proof: MerkleProof): boolean