Skip to content

chainpoint/merkletools-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

merkletools-go

License

Merkletools-go is a library used by the Chainpoint project to efficiently generate and interact with Merkle trees. 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

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages