JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 13
  • Score
    100M100P100Q54709F
  • License MPL-2.0

An implementation of the modified merkle patricia tree used in Ethereum, optimized for in-memory usage

Package Exports

  • @rainblock/merkle-patricia-tree

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@rainblock/merkle-patricia-tree) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

☔️🌲 RainBlock's In-Memory Merkle Tree

NPM Package Build Status Coverage Status node

@rainblock/merkle-patricia-tree is an in-memory merkle tree which conforms to the specifications of the modified merkle patricia tree used by Ethereum. It is a fork of the EthereumJS library, and released under the same license, however, the API has changed to be synchronous instead of callback based. The goals of @rainblock/merkle-patricia-tree are to be:

  • In-Memory Optimized. @rainblock/merkle-patricia-tree is optimized for in-memory use and does not support persistence.

  • High performance. By taking advantage of in-memory optimizations, @rainblock/merkle-patricia-tree aims to be high performance - currently, it is 2-8x more performant than EthereumJS's merkle tree on standard benchmarks.

  • Well documented. API documentation is automatically generated from the JSdoc embedded in the typescript source, and the source code aims to be commented and maintainable.

  • Ethereum compatible. The root hashes produced by @rainblock/merkle-patricia-tree should produce the same root hashes as other Ethereum merkle tree libraries given the same input data.

Install

Add @rainblock/merkle-patricia-tree to your project with:

npm install @rainblock/merkle-patricia-tree

Usage

Basic API documentation can be found here, but the following example shows basic use of puts and gets and verification:

import {MerklePatriciaTree, VerifyWitness} from '@rainblock/merkle-patricia-tree';
const tree = new MerklePatriciaTree();

tree.put(Buffer.from('a'), Buffer.from('b'));

// Get returns a witness which contains { value, proof }
const witness = tree.get(Buffer.from('a'));

// VerifyWitness will throw an error if the proof doesn't match the given root
VerifyWitness(witness, tree.root);

Benchmarks

Benchmarks can be run by executing npm run benchmark from the package directory.