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

merkle-patricia-tree

Package Overview
Dependencies
Maintainers
7
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

merkle-patricia-tree

This is an implementation of the modified merkle patricia tree as specified in Ethereum's yellow paper.

  • 4.2.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
142K
decreased by-25.52%
Maintainers
7
Weekly downloads
 
Created

What is merkle-patricia-tree?

The merkle-patricia-tree npm package is a JavaScript implementation of the Ethereum modified Merkle Patricia Trie. It is used to store key-value pairs in a way that allows for efficient verification of the inclusion and integrity of data. This is particularly useful in blockchain applications where data integrity and proof of inclusion are critical.

What are merkle-patricia-tree's main functionalities?

Creating a Trie

This feature allows you to create a new instance of a Merkle Patricia Trie. The Trie can then be used to store and manage key-value pairs.

const { BaseTrie: Trie } = require('merkle-patricia-tree');
const trie = new Trie();

Inserting Data

This feature allows you to insert key-value pairs into the Trie. The keys and values are stored as Buffers.

const { BaseTrie: Trie } = require('merkle-patricia-tree');
const trie = new Trie();
trie.put(Buffer.from('key1'), Buffer.from('value1'), (err) => {
  if (err) throw err;
  console.log('Data inserted');
});

Retrieving Data

This feature allows you to retrieve the value associated with a given key from the Trie.

const { BaseTrie: Trie } = require('merkle-patricia-tree');
const trie = new Trie();
trie.put(Buffer.from('key1'), Buffer.from('value1'), (err) => {
  if (err) throw err;
  trie.get(Buffer.from('key1'), (err, value) => {
    if (err) throw err;
    console.log('Retrieved value:', value.toString());
  });
});

Deleting Data

This feature allows you to delete a key-value pair from the Trie.

const { BaseTrie: Trie } = require('merkle-patricia-tree');
const trie = new Trie();
trie.put(Buffer.from('key1'), Buffer.from('value1'), (err) => {
  if (err) throw err;
  trie.del(Buffer.from('key1'), (err) => {
    if (err) throw err;
    console.log('Data deleted');
  });
});

Proving Inclusion

This feature allows you to create a proof that a particular key-value pair is included in the Trie.

const { BaseTrie: Trie } = require('merkle-patricia-tree');
const trie = new Trie();
trie.put(Buffer.from('key1'), Buffer.from('value1'), (err) => {
  if (err) throw err;
  trie.createProof(Buffer.from('key1'), (err, proof) => {
    if (err) throw err;
    console.log('Proof:', proof);
  });
});

Other packages similar to merkle-patricia-tree

Keywords

FAQs

Package last updated on 23 Mar 2022

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