mkltree

package module
v0.0.0-...-80a28e6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

README

mkltree

merkle tree library implemented in Go language.

Feature

  • build tree when initialized
  • proof whether a data block belongs to a merkle tree
  • add block one by one, then build tree. (Useful when reads data incrementally from big files.)
  • customize tree depth. (Default is binary tree. Depth depends on number of leaves.)
  • consider whether use double hash

How to Use?

please see example.go

Reference

Development environment

  • Go: 1.12.6

Documentation

Overview

Merkle Tree library

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Proof

func Proof(leafBlock []byte, leafBlockIndex int,
	merkleRoot []byte, merkleHashPath [][]byte, hasher hash.Hash) bool

Proof the original leaf Block is in the blockIndex of the merkle tree whose root hash is known by user already.

Types

type MklTree

type MklTree struct {
	// contains filtered or unexported fields
}

Merkle Tree. It can only be build by using New* method, for example: mkltree.NewMklTree() You can choose whether to store blocks in this merkle tree, if yes, it will cause more memory. You can only build a tree once. If you want a new tree, try to build a new one.

func NewMklTree

func NewMklTree(blocks [][]byte, storeBlocks bool) *MklTree

NewMklTree return an merkle tree with default hash method sha256

func NewMklTreeCustomHash

func NewMklTreeCustomHash(blocks [][]byte, storeBlocks bool, h hash.Hash) *MklTree

NewMklTreeCustomHash return an merkle tree with customized hash method

func (*MklTree) Path

func (m *MklTree) Path(leafBlockIndex int) [][]byte

Path returns relevant merkle tree hash path, from leaf to root.

func (*MklTree) Root

func (m *MklTree) Root() []byte

func (*MklTree) String

func (m *MklTree) String() string

print Hash Tree structure. Hash bytes are encoded in BASE64, separated by character comma ','

func (*MklTree) StringBytes

func (m *MklTree) StringBytes() string

print Hash Tree structure. Hash bytes are encoded as corresponding integers(0-255), separated by character comma ','

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL