Skip to content

varshard/merkletree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MerkleTree

CircleCI

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

Usages

Import

import "github.com/varshard/merkletree"

Building a tree

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)
}

Verify that a hash and root are of the same tree

target := sha256.Sum256([]byte("2")])

// return boolean
tree.verify(target)

About

MerkleTree implemented in Go

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages