Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@guildofweavers/merkle
Advanced tools
Merkle tree and other data structures.
$ npm install @guildofweavers/merkle --save
import { MerkleTree } from '@guildofweavers/merkle';
// create an array of values to put into a tree
const values = [
Buffer.from('a'),
Buffer.from('b'),
Buffer.from('c'),
Buffer.from('d')
];
// create a Merkle tree
const tree = MerkleTree.create(values, 'sha256');
// create a proof for the second position in the tree (value 'b')
const proof = tree.prove(1);
console.log(proof[0].toString()); // 'b'
// verify the proof
const result = MerkleTree.verify(tree.root, 1, proof, 'sha256');
console.log(result); // true
You can find complete API definitions in merkle.d.ts. Here is a quick overview of the provided functionality:
You can use two methods to create a Merkle Tree from a list of values:
Buffer[]
, hashAlgorithm: string
): MerkleTree
Buffer[]
, hashAlgorithm: string
): Promise<MerkleTree>
Both methods take an array of values and a name of the hash algorithm to use when building the tree. Currently, only 2 hash algorithms are supported: sha256
and blake2s256
.
Note: async method is currently just a placeholder. All it does is call the sync version and returns the result.
Once you have a tree, you can use it to prove that a value is located at a certain index like so:
number
): Buffer[]
You can also create a proof for many indexes at the same time:
proveBatch(indexes: number[]
): BatchMerkleProof
The resulting proof is compressed. So, if you need to prove membership of multiple values, this is a much more efficient approach.
Batch proof has the following form:
interface BatchMerkleProof {
values : Buffer[];
nodes : Buffer[][];
depth : number;
}
where, values
are the leaves located at the indexes covered by the proof, nodes
are the internal nodes that form the actual proof, and depth
is the depth of the source tree.
Once you have a proof, you can verify it against a tree root like so:
Buffer
, index: number
, proof: Buffer[]
, hashAlgorithm: string
): boolean
true
if the value located at the first position in the proof
array is indeed located at the specified index
in the tree.For the batched version use:
Buffer
, indexes: number[]
, proof: BatchMerkleProof
, hashAlgorithm: string
): boolean
true
if the values in proof.values
are indeed located at the specified indexes
in the tree.FAQs
Merkle tree and other data structures
The npm package @guildofweavers/merkle receives a total of 1 weekly downloads. As such, @guildofweavers/merkle popularity was classified as not popular.
We found that @guildofweavers/merkle demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.