https://github.com/chainpoint/merkletools-go
https://github.com/chainpoint/merkletools-go
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/chainpoint/merkletools-go
- Owner: chainpoint
- License: apache-2.0
- Created: 2019-01-31T23:26:24.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-05-03T22:28:21.000Z (about 4 years ago)
- Last Synced: 2023-08-07T11:21:49.255Z (almost 3 years ago)
- Language: Go
- Size: 11.7 KB
- Stars: 0
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# merkletools-go
[](https://opensource.org/licenses/Apache-2.0)
Merkletools-go is a library used by the Chainpoint project to efficiently generate and interact with [Merkle trees](https://en.wikipedia.org/wiki/Merkle_tree).
It possesses a number of options for creating blockchain-compatible trees and generating proofs of inclusion.
## Install
This package uses Go modules for dependency management.
`go get github.com/chainpoint/merkletools-go`
## Usage
```go
package main
import (
"fmt"
"encoding/hex"
"time"
merkletools "github.com/chainpoint/merkletools-go"
)
func main() {
mt := merkletools.MerkleTree{}
var hash, _ = hex.DecodeString("cb4990b9a8936bbc137ddeb6dcab4620897b099a450ecdc5f3e86ef4b3a7135c")
leafCount := 100000
for i := 0; i < leafCount; i++ {
mt.AddLeaf(hash)
}
mt.MakeTree()
for i := 0; i < leafCount; i++ {
proof := mt.GetProof(i)
isValid := merkletools.VerifyProof(proof, mt.GetLeaf(i).Hash, mt.GetMerkleRoot())
if !isValid {
panic("Bad Proof!")
}
}
}
```