import { IncrementalMerkleTree } from'@unirep/crypto'constdepth=4// initialize incremental merkle tree with depth 4consttree=newIncrementalMerkleTree(depth)
Get tree root
Insert leaf
constleaf=1tree.insert(leaf)
Generate merkle proof
constindex=0constproof=tree.createProof(index)
Verify merkle proof
constisValid=tree.verifyProof(proof)
SparseMerkleTree
Create a SparseMerkleTree
import { SparseMerkleTree } from'@unirep/crypto'constdepth=4// initialize incremental merkle tree with depth 4constzeroHash=0// initialize sparse merkle tree with depth 4 and zeroHash 0consttree=newSparseMerkleTree( depth, zeroHash)
constvalues= { input1:genRandomSalt(), input2:genRandomSalt(), input3:genRandomSalt(),}// stringify BigInt elements with stringifyBigInts functionconststringifiedValues=stringifyBigInts(values)// it can be recoverd by unstringifyBigInts functionconstunstringifiedValues=unstringifyBigInts(stringifiedValues)