import { IncrementalMerkleTree } from '@unirep/crypto'
const depth = 4
// initialize incremental merkle tree with depth 4
const tree = new IncrementalMerkleTree(depth)
Get tree root
Insert leaf
const leaf = 1
tree.insert(leaf)
Generate merkle proof
const index = 0
const proof = tree.createProof(index)
Verify merkle proof
const isValid = tree.verifyProof(proof)
SparseMerkleTree
Create a SparseMerkleTree
import { SparseMerkleTree } from '@unirep/crypto'
const depth = 4
// initialize incremental merkle tree with depth 4
const zeroHash = 0
// initialize sparse merkle tree with depth 4 and zeroHash 0
const tree = new SparseMerkleTree(
depth,
zeroHash
)
const values = {
input1: genRandomSalt(),
input2: genRandomSalt(),
input3: genRandomSalt(),
}
// stringify BigInt elements with stringifyBigInts function
const stringifiedValues = stringifyBigInts(values)
// it can be recoverd by unstringifyBigInts function
const unstringifiedValues = unstringifyBigInts(stringifiedValues)