Merkle Tree implemented in Go. This is a port of https://github.com/cliftonm/MerkleTree from C# to Go.
Note: This project doesn't duplicate an odd node like some other implementation
import "github.com/varshard/merkletree"
func main() {
leaves := []*Node{
NewNode([]byte("1")),
NewNode([]byte("2")),
NewNode([]byte("3")),
}
tree := Tree{
Leaves: leaves,
// In case that we need even leaves
MustBalance: true
}
tree.BuildTree()
// Get root's hash
fmt.Println(tree.Root.Hash)
}
target := sha256.Sum256([]byte("2")])
// return boolean
tree.verify(target)