JSPM

icjs-mpt

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

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

Package Exports

  • icjs-mpt
  • icjs-mpt/secure.js

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 (icjs-mpt) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

SYNOPSIS

NPM Package Build Status Coverage Status Gitter or #icjs on freenode

js-standard-style

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

The modified Merkle Patricia tree (trie) provides a persistent data structure to map between arbitrary-length binary data (byte arrays). It is defined in terms of a mutable data structure to map between 256-bit binary fragments and arbitrary-length binary data. The core of the trie, and its sole requirement in terms of the protocol specification is to provide a single 32-byte value that identifies a given set of key-value pairs.
- Ethereum's yellow paper

The only backing store supported is LevelDB through the levelup module.

INSTALL

npm install icjs-mpt

USAGE

Initialization and Basic Usage

var Trie = require('icjs-mpt'),
levelup = require('levelup'),
db = levelup('./testdb'),
trie = new Trie(db); 

trie.put('test', 'one', function () {
  trie.get('test', function (err, value) {
    if(value) console.log(value.toString())
  });
});

Merkle Proofs

Trie.prove(trie, 'test', function (err, prove) {
  if (err) return cb(err)
  Trie.verifyProof(trie.root, 'test', prove, function (err, value) {
    if (err) return cb(err)
    console.log(value.toString())
    cb()
  })
})

Read stream on Geth DB

var levelup = require('levelup')
var Trie = require('./secure')

var stateRoot = "0xd7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544" // Block #222

var db = levelup('YOUR_PATH_TO_THE_GETH_CHAIN_DB')
var trie = new Trie(db, stateRoot)

trie.createReadStream()
  .on('data', function (data) {
    console.log(data)
  })
  .on('end', function() { 
    console.log('End.')
  })

API

./docs/

TESTING

npm test

REFERENCES

LICENSE

MPL-2.0