Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arriqaaq/merkletree
A merkle tree (with proofs) in Go as per RFC6962
https://github.com/arriqaaq/merkletree
blockchain crypto go golang merkle-proof merkle-tree
Last synced: 16 days ago
JSON representation
A merkle tree (with proofs) in Go as per RFC6962
- Host: GitHub
- URL: https://github.com/arriqaaq/merkletree
- Owner: arriqaaq
- License: mit
- Created: 2022-05-02T11:28:41.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-05-06T03:52:47.000Z (over 2 years ago)
- Last Synced: 2024-10-14T19:48:53.353Z (30 days ago)
- Topics: blockchain, crypto, go, golang, merkle-proof, merkle-tree
- Language: Go
- Homepage: https://aly.arriqaaq.com/merkle-tree-and-verifiable-data-structures/
- Size: 6.84 KB
- Stars: 56
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# merkletree
An implementation of a merkle tree based on the specification provided for [Certificate Transparency](https://datatracker.ietf.org/doc/html/rfc6962#section-2.1)
# Usage
```go
package mainimport (
"fmt""github.com/arriqaaq/merkletree"
)/*
The binary Merkle Tree with 7 leaves:hash
/ \
/ \
/ \
/ \
/ \
k l
/ \ / \
/ \ / \
/ \ / \
g h i j
/ \ / \ / \ |
a b c d e f d6
| | | | | |
d0 d1 d2 d3 d4 d5
*/func makeleaves() (D [][]byte) {
for i := 0; i < 7; i++ {
v := "d" + strconv.FormatInt(int64(i), 10)
D = append(D, []byte(v))
}
return
}func main() {
tree := merkletree.NewTree()// Insert
D := makeleaves()
tree := NewTree(D)// Root Hash
hash:=tree.Hash()// Path
// The audit path for d0 is [b, h, l].
path := tree.Path(0)// Proof
// The consistency proof between hash0 and hash is PROOF(3, D[7]) = [c,
// d, g, l]. c, g are used to verify hash0, and d, l are additionally
// used to show hash is consistent with hash0.
proof := tree.Proof(3)
}
```# Reference
- [RFC#6962](https://datatracker.ietf.org/doc/html/rfc6962#section-2.1)
- [Codenotary](https://github.com/codenotary/merkletree)