All Projects → cbergoon → Merkletree

cbergoon / Merkletree

Licence: mit
A Merkle Tree implementation written in Go.

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Merkletree

Merkle Tree
Merkle Trees and Merkle Inclusion Proofs
Stars: ✭ 130 (-44.92%)
Mutual labels:  tree, merkle-tree
gb merkle trees
General balanced binary Merkle trees for Erlang
Stars: ✭ 25 (-89.41%)
Mutual labels:  tree, merkle-tree
Vue Orgchart
It's a simple and direct organization chart plugin. Anytime you want a tree-like chart, you can turn to OrgChart.
Stars: ✭ 182 (-22.88%)
Mutual labels:  tree
Element Tree Grid
tree grid extends element ui with vue
Stars: ✭ 223 (-5.51%)
Mutual labels:  tree
Domhandler
Handler for htmlparser2, to get a DOM
Stars: ✭ 203 (-13.98%)
Mutual labels:  tree
Interview Questions
List of all the Interview questions practiced from online resources and books
Stars: ✭ 187 (-20.76%)
Mutual labels:  tree
Heyui
🎉UI Toolkit for Web, Vue2.0 http://www.heyui.top
Stars: ✭ 2,373 (+905.51%)
Mutual labels:  tree
Leetcode
High-quality LeetCode solutions
Stars: ✭ 178 (-24.58%)
Mutual labels:  tree
Libdict
C library of key-value data structures.
Stars: ✭ 234 (-0.85%)
Mutual labels:  tree
Outwiker
Сross-platform software for keeping your notes in a tree
Stars: ✭ 198 (-16.1%)
Mutual labels:  tree
Vuejs Tree
A highly customizable and blazing fast Vue tree component ⚡🌲
Stars: ✭ 211 (-10.59%)
Mutual labels:  tree
Iavl
Merkleized IAVL+ Tree implementation in Go
Stars: ✭ 197 (-16.53%)
Mutual labels:  merkle-tree
React Vtree
React component for efficiently rendering large tree structures
Stars: ✭ 185 (-21.61%)
Mutual labels:  tree
Lark
Lark is a parsing toolkit for Python, built with a focus on ergonomics, performance and modularity.
Stars: ✭ 2,916 (+1135.59%)
Mutual labels:  tree
Orgchart
It's a simple and direct organization chart plugin. Anytime you want a tree-like chart, you can turn to OrgChart.
Stars: ✭ 2,325 (+885.17%)
Mutual labels:  tree
Scikit Garden
A garden for scikit-learn compatible trees
Stars: ✭ 230 (-2.54%)
Mutual labels:  tree
Vue Treeselect
A multi-select component with nested options support for Vue.js
Stars: ✭ 2,347 (+894.49%)
Mutual labels:  tree
Rrt Algorithms
n-dimensional RRT, RRT* (RRT-Star)
Stars: ✭ 195 (-17.37%)
Mutual labels:  tree
Fancytree
JavaScript tree view / tree grid plugin with support for keyboard, inline editing, filtering, checkboxes, drag'n'drop, and lazy loading
Stars: ✭ 2,398 (+916.1%)
Mutual labels:  tree
Computer Science In Javascript
Computer science reimplemented in JavaScript
Stars: ✭ 2,590 (+997.46%)
Mutual labels:  tree

Merkle Tree in Golang

Build Report Docs Version

An implementation of a Merkle Tree written in Go. A Merkle Tree is a hash tree that provides an efficient way to verify the contents of a set data are present and untampered with.

At its core, a Merkle Tree is a list of items representing the data that should be verified. Each of these items is inserted into a leaf node and a tree of hashes is constructed bottom up using a hash of the nodes left and right children's hashes. This means that the root node will effictively be a hash of all other nodes (hashes) in the tree. This property allows the tree to be reproduced and thus verified by on the hash of the root node of the tree. The benefit of the tree structure is verifying any single content entry in the tree will require only nlog2(n) steps in the worst case.

Documentation

See the docs here.

Install

go get github.com/cbergoon/merkletree

Example Usage

Below is an example that makes use of the entire API - its quite small.

package main

import (
  "crypto/sha256"
  "log"

  "github.com/cbergoon/merkletree"
)

//TestContent implements the Content interface provided by merkletree and represents the content stored in the tree.
type TestContent struct {
  x string
}

//CalculateHash hashes the values of a TestContent
func (t TestContent) CalculateHash() ([]byte, error) {
  h := sha256.New()
  if _, err := h.Write([]byte(t.x)); err != nil {
    return nil, err
  }

  return h.Sum(nil), nil
}

//Equals tests for equality of two Contents
func (t TestContent) Equals(other merkletree.Content) (bool, error) {
  return t.x == other.(TestContent).x, nil
}

func main() {
  //Build list of Content to build tree
  var list []merkletree.Content
  list = append(list, TestContent{x: "Hello"})
  list = append(list, TestContent{x: "Hi"})
  list = append(list, TestContent{x: "Hey"})
  list = append(list, TestContent{x: "Hola"})

  //Create a new Merkle Tree from the list of Content
  t, err := merkletree.NewTree(list)
  if err != nil {
    log.Fatal(err)
  }

  //Get the Merkle Root of the tree
  mr := t.MerkleRoot()
  log.Println(mr)

  //Verify the entire tree (hashes for each node) is valid
  vt, err := t.VerifyTree()
  if err != nil {
    log.Fatal(err)
  }
  log.Println("Verify Tree: ", vt)

  //Verify a specific content in in the tree
  vc, err := t.VerifyContent(list[0])
  if err != nil {
    log.Fatal(err)
  }

  log.Println("Verify Content: ", vc)

  //String representation
  log.Println(t)
}

Sample

merkletree

License

This project is licensed under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].