Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/theodesp/u-merklele
Simple reference implementation of Merkle trees for general use.
https://github.com/theodesp/u-merklele
algorithms datastructures go golang-library merkel-tree
Last synced: 20 days ago
JSON representation
Simple reference implementation of Merkle trees for general use.
- Host: GitHub
- URL: https://github.com/theodesp/u-merklele
- Owner: theodesp
- License: mit
- Created: 2018-04-13T18:18:33.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-04-13T18:20:55.000Z (over 6 years ago)
- Last Synced: 2024-10-03T07:21:21.430Z (about 1 month ago)
- Topics: algorithms, datastructures, go, golang-library, merkel-tree
- Language: Go
- Size: 5.86 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING
- License: LICENSE
- Authors: AUTHORS
Awesome Lists containing this project
README
Simple reference implementation of Merkle trees for general use.
A **hash tree** or **Merkle tree** is a tree in which every leaf node is labelled with the hash of a data
block and every non-leaf node is labelled with the cryptographic hash of the labels of its child nodes.
Hash trees allow efficient and secure verification of the contents of large data structures.## Installation
```bash
$ go get -u github.com/theodesp/u-merklele
```## Usage
```go
package mainimport (
"crypto/sha256"
"fmt"
"u-merklele"
)func main() {
runExample1()
}func runExample1() {
// Create some leaf trees
block1 := []byte{
byte(1), byte(10), byte(12), byte(20), byte(90), byte(45), byte(23), byte(67),
}// Create some leaf trees
block2 := []byte{
byte(10), byte(45), byte(22), byte(26), byte(78), byte(33), byte(67), byte(22),
}l1 := umerklele.NewLeaf(block1, sha256.New())
l2 := umerklele.NewLeaf(block2, sha256.New())
fmt.Printf("Leaf 1 Digest is: %x\n", l1.HashCode())
fmt.Printf("Leaf 2 Digest is: %x\n", l2.HashCode())m1 := umerklele.New(sha256.New())
m1.Merge(l1, l2)fmt.Printf("Merkle Digest of both Leafs is: %x\n", m1.HashCode())
m2 := umerklele.New(sha256.New())
m2.Merge(l2, l1)fmt.Printf("Merkle Digest of the extended tree is: %x\n", m2.HashCode())
m2.Do(func(mt *umerklele.MerkleTree) {
fmt.Printf("[Merkele Tree: hashCode=%x], isLeaf=%t\n", mt.HashCode(), mt.IsLeaf())
})
}
```You can also run the demo application in the `example` folder
## LICENCE
Copyright © 2017 Theo Despoudis MIT license