1.1.0 • Published 5 years ago
@tzstamp/merkle
Licence
MIT
Version
1.1.0
Deps
0
Size
14 kB
Vulns
0
Weekly
0
Merkle
Appendable merkle tree library
Installation
$ npm install --save @tzstamp/merkle
Proofs
const { Proof } = require('@tzstamp/merkle')
Deserialize a proof from JSON:
const proofString = fs.readFileSync('./my-proof.json')
const proof = Proof.parse(proofString)
Reserialize with:
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
const { MerkleTree } = require('@tzstamp/merkle')
Instantiate optionally with leaves:
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 2020 The TzStamp Authors