# @tzstamp/merkle

> Appendable merkle tree library

Latest version **1.1.0** (published 2020-11-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install @tzstamp/merkle
pnpm add @tzstamp/merkle
yarn add @tzstamp/merkle
bun add @tzstamp/merkle
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2020-11-20 |
| First published | 2020-11-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 14.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | metanomial |

## Links

- npm: https://www.npmjs.com/package/@tzstamp/merkle
- npm.io page: https://npm.io/package/@tzstamp/merkle

## Recent versions

- 1.1.0 (latest) — 2020-11-20
- 1.0.0 — 2020-11-19

## README

# Merkle
Appendable merkle tree library

## Installation
```
$ npm install --save @tzstamp/merkle
```

## Proofs
```js
const { Proof } = require('@tzstamp/merkle')
```

Deserialize a proof from JSON:
```js
const proofString = fs.readFileSync('./my-proof.json')
const proof = Proof.parse(proofString)
```

Reserialize with:
```js
JSON.stringify(proof)
```

### `proof.derive(hash)`
Derive the merkle root, given the leaf hash.
- hash: `Uint8Array`
- returns: `Uint8Array`

### `proof.verify(hash, root)`
Verify the proof, given the leaf hash and merkle root.
- hash: `Uint8Array`
- root: `Uint8Array`
- returns: `boolean`

## MerkleTree
```js
const { MerkleTree } = require('@tzstamp/merkle')
```

Instantiate optionally with leaves:
```js
const merkleTree = new MerkleTree(...leaves)
```

### `merkleTree.append(...hashes)`
Append leaves to the merkle tree. Deduplicates leaves.
- hashes: `...Uint8Array`

### `merkleTree.prove(hash)`
Build a proof, given a leaf hash included in the tree.
- hash: `Uint8Array`
- return: `Proof`
- throws an error when the leaf is not included in the tree.

### `merkleTree.leaves`
Array of all leaves included in the tree.

## License
[MIT](LICENSE.txt) &copy; 2020 The TzStamp Authors

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