merkle

package
v0.0.0-...-f661f07 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2013 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package merkle provides a binary merkle tree implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetHeight

func GetHeight(count uint64) int

Returns the height of the tree containing count leaf nodes. This the number of nodes (including the final leaf) from the root to any leaf.

Types

type Root

type Root struct {
	Count uint64
	Base  []byte
}

The Root of a merkle tree for a client that does not store the tree

func (*Root) CheckProof

func (r *Root) CheckProof(proof [][]byte, index int) bool

Proves the inclusion of an element at the given index with the value thats the first entry in proof

type Tree

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

A merkle tree for a user that stores the entire tree Specifically this tree is left a leaning balanced binary tree Where each node holds the hash of its leaves And the rootHash is the root node hashed with the count This tree is immutable

func Build

func Build(data [][]byte) *Tree

Build a tree

func (Tree) Count

func (t Tree) Count() uint64

func (*Tree) InclusionProof

func (t *Tree) InclusionProof(index int) [][]byte

Return a [][]byte needed to prove the inclusion of the item at the passed index The payload of the item at index is the first value in the proof

func (Tree) Root

func (t Tree) Root() []byte

The hash/root of an empty tree does not matter

func (Tree) Validate

func (t Tree) Validate() error

All trees should pass Validate, unless they are invalid, which should only happen if incorrectly built or modified. Checks the rep invariants

Jump to

Keyboard shortcuts

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