Coder Social home page Coder Social logo

merkletree-1's Introduction

MerkleTree

一款简单的基于Golang实现的默克尔树

作用

可以通过默克尔树根Hash或者节点Hash,快速验证数据的一致性。

使用方式

go get github.com/wk331100/MerkleTree

外部调用方法

  • NewMerkleTree() // 新建一个默克尔树
  • mk.VerifyTree // 验证一个默克尔树是否完整
  • mk.VerifyData // 验证数据是否在树中
  • mk.GetRootHash // 获取默克尔树根Hash

测试示例

func TestMerkleTree(t *testing.T) {
  // data为[][]byte类型数据
	data := initData()
  // 实例化一个默克尔树
	mk, err := NewMerkleTree("md5", data)
	require.Nil(t, err)
	fmt.Sprintf("%x", mk.GetRootHash())
	printHash(mk)

  // 验证数据是否在默克尔树中
	res, _ := mk.VerifyData(testData)
	require.True(t, res)

  // 验证默克尔树是否完整
	res2, _ := mk.VerifyTree()
	require.True(t, res2)
}

merkletree-1's People

Contributors

wk331100 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.