Incremental Merkle tree implementation in TypeScript.
npm install @zk-kit/incremental-merkle-tree
Incremental Merkle tree implementation in TypeScript.
---
Install the @zk-kit/incremental-merkle-tree package with npm:
``bash`
npm i @zk-kit/incremental-merkle-tree --save
or yarn:
`bash`
yarn add @zk-kit/incremental-merkle-tree
You can also load it using a script tag using unpkg:
`html`
or JSDelivr:
`html`
\# new IncrementalMerkleTree(hash: _HashFunction_, depth: _number_, zero: _Node_, arity: _number_, leaves: _Node\[]_): _IncrementalMerkleTree_
`typescript
import { IncrementalMerkleTree } from "@zk-kit/incremental-merkle-tree"
import { poseidon } from "circomlibjs" // v0.0.8
const tree = new IncrementalMerkleTree(poseidon, 16, BigInt(0), 2) // Binary tree.
// Or, if you already have tree leaves to insert:
const leaves = [1, 2, 3]
const tree = new IncrementalMerkleTree(poseidon, 16, BigInt(0), 2, leaves)
`
\# insert(leaf: _Node_)
`typescript`
tree.insert(BigInt(1))
\# update(index: _number_, newLeaf: _Node_)
`typescript`
tree.update(0, BigInt(2))
\# delete(index: _number_)
`typescript`
tree.delete(0)
\# indexOf(leaf: _Node_): _number_
`typescript
tree.insert(BigInt(2))
const index = tree.indexOf(BigInt(2))
`
\# createProof(index: _number_): _Proof_
`typescript`
const proof = tree.createProof(1)
\# verifyProof(proof: _Proof_): _boolean_
`typescript``
console.log(tree.verifyProof(proof)) // true
- e-mail : me@cedoor.dev
- github : @cedoor
- website : https://cedoor.dev