Giter VIP home page Giter VIP logo

merkletree's Introduction

Merkle Trees and verify proofs in Golang

image

copy to https://github.com/miguelmota/merkletreejs

Construct Merkle Trees and verify proofs in Golang.

Support HASH include sha3.NewLegacyKeccak256 and sha256

var list []Content
list = append(list, Content{X: "0x0000007adc3815c056c91dbc5ec48c4fd0950b49"})
list = append(list, Content{X: "0x00010a9bbde3f6ec395c179e36f1df24e59bd824"})
list = append(list, Content{X: "0x0004932ff86fbdb0e7cf99203111624ea57cd772"})
list = append(list, Content{X: "0x01291849cc904161603c1c60ff86658ad7eadb8d"})
list = append(list, Content{X: "0x0582f324704bf44f7e9e80a2ca68f08e91e45927"})
/*list = append(list, Content{x: "a"})
list = append(list, Content{x: "b"})
list = append(list, Content{x: "c"})
list = append(list, Content{x: "d"})*/

tr := New(SHA256)
tr.WithOption(Option{
	Sort: true,
})
tr.InitLeaves(list)

//tr.AddLeaf(Content{X: "e"})
root := tr.GetRoot()
leaf := Content{X: "0x01291849cc904161603c1c60ff86658ad7eadb8d"}

root, _ = hex.DecodeString("5651b0b746e49be1307faa82cdef9a6cbd454d9b0df2318cd795e8adb877c594")

proof := tr.GetProof(leaf)
fmt.Println(tr.String())

t.Fatal(tr.Verify(proof, leaf, root)) // true

//t.Fatal(tr.GetHexLeaves())
//t.Fatal(tr.GetHexLayers())

merkletree's People

Contributors

authur117 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.