# solidity-partial-tree

> Solidity implementation of partial merkle tree

Latest version **2.0.1** (published 2019-04-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install solidity-partial-tree
pnpm add solidity-partial-tree
yarn add solidity-partial-tree
bun add solidity-partial-tree
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2019-04-09 |
| First published | 2018-11-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 47.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Wanseob Lim |
| Maintainers | wanseob |
| Keywords | Solidity, Partial, Patricia, Merkle, Tree |

## Links

- npm: https://www.npmjs.com/package/solidity-partial-tree
- Repository: https://github.com/commitground/solidity-partial-tree
- Homepage: https://github.com/commitground/solidity-partial-tree#readme
- Issues: https://github.com/commitground/solidity-partial-tree/issues
- npm.io page: https://npm.io/package/solidity-partial-tree

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 2.0.1 (latest) — 2019-04-09
- 2.0.0 — 2019-04-09
- 1.1.1 — 2018-11-24
- 1.1.0 — 2018-11-24
- 1.0.0 — 2018-11-21

## README

# Solidity Partial Merkle Tree

## Credits 

This implementation is based on [Christian Reitwießner](https://github.com/chriseth)'s [patricia-trie](https://github.com/chriseth/patricia-trie) 


##### latest released version
[![npm](https://img.shields.io/npm/v/solidity-partial-tree/latest.svg)](https://www.npmjs.com/package/solidity-partial-tree)
[![Build Status](https://travis-ci.org/commitground/solidity-partial-tree.svg?branch=master)](https://travis-ci.org/commitground/solidity-partial-tree)
[![Coverage Status](https://coveralls.io/repos/github/commitground/solidity-partial-tree/badge.svg?branch=master)](https://coveralls.io/github/commitground/solidity-partial-tree?branch=develop)

##### in progress
[![npm](https://img.shields.io/npm/v/solidity-partial-tree/next.svg)](https://www.npmjs.com/package/solidity-partial-tree)
[![Build Status](https://travis-ci.org/commitground/solidity-partial-tree.svg?branch=develop)](https://travis-ci.org/commitground/solidity-partial-tree)
[![Coverage Status](https://coveralls.io/repos/github/commitground/solidity-partial-tree/badge.svg?branch=develop)](https://coveralls.io/github/commitground/solidity-partial-tree?branch=develop)

[![JavaScript Style Guide](https://cdn.rawgit.com/standard/standard/master/badge.svg)](https://github.com/standard/standard)



## Usage

```bash
npm i solidity-partial-tree
npm i solidity-patricia-tree
```

```solidity
pragma solidity ^0.4.24;

import {PatriciaTree} from "solidity-patricia-tree/contracts/tree.sol";
import {PartialMerkleTree} from "solidity-partial-tree/contracts/tree.sol";

contract TestPartialMerkleTree {
    using PartialMerkleTree for PartialMerkleTree.Tree;
    using PatriciaTree for PatriciaTree.Tree;

    PatriciaTree.Tree patriciaTree;
    PartialMerkleTree.Tree partialTree;

    /**
     * @dev we can reenact merkle tree transformation by submitting only referred siblings instead of submitting all nodes
     */
    function testOnChainProof() public {
        // update merkle root
        patriciaTree.insert("key1", "val1");
        patriciaTree.insert("key2", "val2");
        patriciaTree.insert("key3", "val3");

        // root hash of patricia tree @ phase A
        bytes32 phaseAOfPatriciaTree = patriciaTree.getRootHash();

        // get siblings to update "key1"
        uint branchMask;
        bytes32[] memory siblings;
        (branchMask, siblings) = patriciaTree.getProof("key1");

        // Init partial tree with the root hash
        partialTree.initialize(phaseAOfPatriciaTree);
        // commit branch (we submit sibling data here)
        partialTree.commitBranch("key1", "val1", branchMask, siblings);

        // Update key1 of patricia tree
        patriciaTree.insert("key1", "val4");

        // Update key1 of partial tree
        partialTree.insert("key1", "val4");

        // get updated root hashes of each tree
        bytes32 phaseBOfPatriciaTree = patriciaTree.getRootHash();
        bytes32 phaseBOfPartialTree = partialTree.getRootHash();

        // We have succeeded to reenact merkle tree transformation without submitting all node data
        require(phaseBOfPatriciaTree == phaseBOfPartialTree);
    }
}
```


## Development 

### Pre-requisites

```bash
npm install -g truffle
npm install -g ganache-cli
npm install
```

### Tests

```bash
npm run test
```

## Contributors
- [Wanseob Lim](https://github.com/james-lim)<[email@wanseob.com](mailto:email@wanseob.com)>

## License

[MIT LICENSE](./LICENSE)

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