Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

merkletreejs

Package Overview
Dependencies
Maintainers
1
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

merkletreejs

Construct Merkle Trees and verify proofs

  • 0.2.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is merkletreejs?

The merkletreejs package is a JavaScript library for constructing and verifying Merkle Trees. Merkle Trees are a fundamental component in blockchain technology and cryptographic applications, providing a way to efficiently and securely verify the integrity of data. This package allows you to create Merkle Trees, generate proofs, and verify proofs.

What are merkletreejs's main functionalities?

Creating a Merkle Tree

This feature allows you to create a Merkle Tree from an array of data. The example uses the keccak256 hashing algorithm to hash the data and then constructs the tree. The root of the tree is then printed.

const { MerkleTree } = require('merkletreejs');
const keccak256 = require('keccak256');

const leaves = ['a', 'b', 'c'].map(x => keccak256(x));
const tree = new MerkleTree(leaves, keccak256, { sortPairs: true });
const root = tree.getRoot().toString('hex');
console.log(root);

Generating a Proof

This feature allows you to generate a proof for a specific leaf in the Merkle Tree. The proof can be used to verify that the leaf is part of the tree.

const leaf = keccak256('a');
const proof = tree.getProof(leaf);
console.log(proof);

Verifying a Proof

This feature allows you to verify a proof against the root of the Merkle Tree. It checks if the provided leaf and proof match the root, ensuring the integrity of the data.

const isValid = tree.verify(proof, leaf, root);
console.log(isValid);

Other packages similar to merkletreejs

Keywords

FAQs

Package last updated on 02 Jun 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc