mirror of
https://github.com/HerodotusDev/accumulators.git
synced 2026-05-22 13:06:17 +00:00
No description
- TypeScript 94.4%
- JavaScript 5.6%
| .github/workflows | ||
| .vscode | ||
| examples | ||
| packages | ||
| .gitignore | ||
| .prettierrc | ||
| banner.png | ||
| CHANGELOG.md | ||
| jest.config.ts | ||
| lerna.json | ||
| package.json | ||
| pnpm-lock.yaml | ||
| pnpm-workspace.yaml | ||
| README.md | ||
| tsconfig.json | ||
ACCUMULATORS
This library contains a collection of packages that accumulate data in Merkle Mountain Range or Incremental Merkle Tree data structures.
Detailed documentation
Example
Merkle Mountain Range example:
import MemoryStore from "@accumulators/memory";
import { KeccakHasher } from "@accumulators/hashers";
import Mmr from "@accumulators/merkle-mountain-range";
const store = new MemoryStore();
const hasher = new KeccakHasher();
const mmr = new Mmr(store, hasher);
await mmr.append("1");
await mmr.append("2");
await mmr.append("3");
const { elementIndex } = await mmr.append("4");
await mmr.append("5");
const proof = await mmr.getProof(elementIndex);
console.log(await mmr.verifyProof(proof, "4")); // true
Incremental Merkle Tree example:
import MemoryStore from "@accumulators/memory";
import { KeccakHasher } from "@accumulators/hashers";
import { IncrementalMerkleTree } from "@accumulators/incremental-merkle-tree";
const store = new MemoryStore();
const hasher = new KeccakHasher();
const tree = await IncrementalMerkleTree.initialize(4, "0x0", hasher, store);
const proof = await tree.getInclusionProof(2);
console.log(await tree.verifyProof(2, "0x0", proof)); // true
await tree.update(2, "0x0", "0x1", proof);
console.log(await tree.verifyProof(2, "0x0", proof)); // false
console.log(await tree.verifyProof(2, "0x1", proof)); // true
