Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
@accumulators/incremental-merkle-tree
Advanced tools
A TypeScript implementation of Incremental Merkle Trees with multiproofs
Incremental Merkle Tree is a structure that contains a constant amount of hashes, allows updating a given hash and proving efficiently. Time complexity of both operations is O(log tree_size).
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
initialize(treeSize: number, nullValue: string, hasher: Hasher, store: Store, treeId?: string)
Creates a new Incremental Merkle Tree of a given treeSize
and fills all leaves with value nullValue
. Returns the promise of IncrementalMerkleTree
.
All the values in store
have keys prefixes with treeId
. If you want to recreate an existing Merkle Tree, you need to provide the same treeId
as the original one. In case you want to create a new tree, you can omit treeId
and it will be generated automatically. treeId
can be later accessed using the property (e.g. myTree.treeId
).
getRoot()
Returns the promise of a string
of hexadecimal number which is the root hash of the tree.
getInclusionProof(index: number)
Returns the promise of string[]
for a given index
(0-based). The array contains hashes of all siblings of nodes on the path from the leaf to the root.
verifyProof(index: number, value: string, proof: string[])
Returns the promise of boolean
which is true
if the value
is in the tree at index
(0-based) and false
otherwise.
proof
is an array of hashes returned by getInclusionProof
.
update(index: number, oldValue: string, newValue: string, proof: string[])
Changes the value of the leaf at index
(0-based) from oldValue
to newValue
. proof
is an array of hashes returned by getInclusionProof
.
If provided oldValue
or proof
is incorrect, the function will throw an error.
getInclusionMultiProof(indexes: number[])
Returns the promise of string[]
for a given indexes
(0-based). The array contains hashes of all siblings of nodes on the path from the leaves to the root.
verifyMultiProof(indexes: number[], values: string[], proof: string[])
Returns the promise of boolean
which is true
if and only if for every i
value at position indexes[i]
(0-based) is equal to values[i]
and proof
is a valid proof for all of them.
4.2.3 (2023-10-06)
Note: Version bump only for package accumulators
FAQs
A TypeScript implementation of Incremental Merkle Trees with multiproofs
We found that @accumulators/incremental-merkle-tree demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.