# icjs-mpt

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

Latest version **0.0.1** (published 2018-08-07) · MPL-2.0 license · 0 weekly downloads

## Install

```sh
npm install icjs-mpt
pnpm add icjs-mpt
yarn add icjs-mpt
bun add icjs-mpt
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2018-08-07 |
| First published | 2018-08-07 |
| Weekly downloads | 0 |
| License | MPL-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 897.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | ldcc |
| Maintainers | irchain-io |
| Keywords | merkle, radix, trie, patricia, irchain |

## Links

- npm: https://www.npmjs.com/package/icjs-mpt
- Repository: https://github.com/icjs/icjs-mpt
- Homepage: https://github.com/icjs/icjs-mpt#readme
- Issues: https://github.com/icjs/icjs-mpt/issues
- npm.io page: https://npm.io/package/icjs-mpt

## Dependencies (8)

- [rlp](https://npm.io/package/rlp.md) ^2.0.0
- [async](https://npm.io/package/async.md) ^1.4.2
- [levelup](https://npm.io/package/levelup.md) ^1.2.1
- [memdown](https://npm.io/package/memdown.md) ^1.0.0
- [level-ws](https://npm.io/package/level-ws.md) 0.0.0
- [icjs-util](https://npm.io/package/icjs-util.md) ^0.0.1
- [semaphore](https://npm.io/package/semaphore.md) >=1.0.1
- [readable-stream](https://npm.io/package/readable-stream.md) ^2.0.0

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 0.0.1 (latest) — 2018-08-07

## README

# SYNOPSIS 
[![NPM Package](https://img.shields.io/npm/v/icjs-mpt.svg?style=flat-square)](https://www.npmjs.org/package/icjs-mpt)
[![Build Status](https://img.shields.io/travis/icjs/icjs-mpt.svg?branch=master&style=flat-square)](https://travis-ci.org/icjs/icjs-mpt)
[![Coverage Status](https://img.shields.io/coveralls/icjs/icjs-mpt.svg?style=flat-square)](https://coveralls.io/r/icjs/icjs-mpt)
[![Gitter](https://img.shields.io/gitter/room/irchain/icjs-lib.svg?style=flat-square)](https://gitter.im/irchain/icjs-lib) or #icjs on freenode

[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)  

This is an implementation of the modified merkle patricia tree as specified in the [Ethereum's yellow paper](http://gavwood.com/Paper.pdf).

> 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

```javascript
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

```javascript
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

```javascript
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/](./docs/index.md)

# TESTING
`npm test`

# REFERENCES

- ["Exploring IrChain's state trie with Node.js"](https://wanderer.github.io/irchain/nodejs/code/2014/05/21/using-irchains-tries-with-node/) blog post
- ["Merkling in Ethereum"](https://blog.irchain.org/2015/11/15/merkling-in-irchain/) blog post
- [Ethereum Trie Specification](https://github.com/irchain/wiki/wiki/Patricia-Tree) Wiki
- ["Understanding the irchain trie"](https://easythereentropy.wordpress.com/2014/06/04/understanding-the-irchain-trie/) blog post
- ["Trie and Patricia Trie Overview"](https://www.youtube.com/watch?v=jXAHLqQthKw&t=26s) Video Talk on Youtube

# LICENSE
MPL-2.0

---
_Source: https://npm.io/package/icjs-mpt · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
