@zk-kit/incremental-merkle-tree
v1.1.0
Published
Incremental Merkle tree implementation in TypeScript.
Downloads
12,933
Readme
🛠 Install
npm or yarn
Install the @zk-kit/incremental-merkle-tree
package with npm:
npm i @zk-kit/incremental-merkle-tree --save
or yarn:
yarn add @zk-kit/incremental-merkle-tree
CDN
You can also load it using a script
tag using unpkg:
<script src="https://unpkg.com/@zk-kit/incremental-merkle-tree/"></script>
or JSDelivr:
<script src="https://cdn.jsdelivr.net/npm/@zk-kit/incremental-merkle-tree/"></script>
📜 Usage
# new IncrementalMerkleTree(hash: HashFunction, depth: number, zero: Node, arity: number, leaves: Node[]): IncrementalMerkleTree
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)
tree.insert(BigInt(1))
# update(index: number, newLeaf: Node)
tree.update(0, BigInt(2))
# delete(index: number)
tree.delete(0)
# indexOf(leaf: Node): number
tree.insert(BigInt(2))
const index = tree.indexOf(BigInt(2))
# createProof(index: number): Proof
const proof = tree.createProof(1)
# verifyProof(proof: Proof): boolean
console.log(tree.verifyProof(proof)) // true
Contacts
Developers
- e-mail : [email protected]
- github : @cedoor
- website : https://cedoor.dev