Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/parsh/merkle-tree
Merkle tree(Bitcoin-style) implementation
https://github.com/parsh/merkle-tree
Last synced: 4 days ago
JSON representation
Merkle tree(Bitcoin-style) implementation
- Host: GitHub
- URL: https://github.com/parsh/merkle-tree
- Owner: Parsh
- Created: 2020-10-29T13:55:43.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2020-10-29T15:31:50.000Z (about 4 years ago)
- Last Synced: 2024-10-12T20:38:21.613Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Merkle Tree Implementation
> A quick implementation of Bitcoin style merkle tree (carry forwarding mono-hash rather than dual hashing it)
## Prerequisites:
- [Node](https://nodejs.org/en/)
## Instructions
### How to execute
```sh
git clone https://github.com/Parsh/Merkle-Tree.git
cd Merkle-Tree
node Merkle.js
```### Generating(and logging) the merkle tree
```javascript
const merkle = new Merkle();
const merkle_root = merkle.generate_merkle_root(txids);
console.log("Merkle Root: ", merkle_root);
merkle.log_merkle_tree();
```### Fetching merkle path and inclusion status
```javascript
const txId = "522137b80ce9a66845e05d5abc09a1dad04ec80f774a7e585c6e8db975962d06";
const { hasTransaction, merklePath, merkleRoot } = merkle.hasTransaction(txId);
```### Self-validation of tx-inclusion using merkle path & root
```javascript
// user validates the inclusion of the tx by regenerating the root via merkle path
validateUsingMerklePath(txId, merklePath, merkleRoot); // true or false
```