mt

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: AGPL-3.0, ISC Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrIndexOutOfBounds = errors.New("merkle tree data index out of bounds")
View Source
var ErrNilData = errors.New("merkle tree input data is nil")

Functions

func EvalMerklePath

func EvalMerklePath(merklePath []*PathItem, leaf Data, hashAlgorithm crypto.Hash) []byte

EvalMerklePath returns root hash calculated from the given leaf and path items

func SecondaryHash added in v0.1.1

func SecondaryHash(txs []txsystem.GenericTransaction, hashAlgorithm crypto.Hash) ([]byte, error)

SecondaryHash returns root merkle hash calculated from given txs

Types

type ByteHasher

type ByteHasher struct {
	Val []byte
}

ByteHasher helper struct to satisfy Data interface

func (*ByteHasher) Hash

func (h *ByteHasher) Hash(hashAlgorithm crypto.Hash) []byte

type Data

type Data interface {
	Hash(hashAlgorithm crypto.Hash) []byte
}

type MerkleTree

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

func New

func New(hashAlgorithm crypto.Hash, data []Data) (*MerkleTree, error)

New creates a new canonical Merkle Tree.

func (*MerkleTree) GetMerklePath

func (s *MerkleTree) GetMerklePath(leafIdx int) ([]*PathItem, error)

GetMerklePath extracts the merkle path from the given leaf to root.

func (*MerkleTree) GetRootHash

func (s *MerkleTree) GetRootHash() []byte

GetRootHash returns the root Hash of the Merkle Tree.

func (*MerkleTree) PrettyPrint

func (s *MerkleTree) PrettyPrint() string

PrettyPrint returns human readable string representation of the Merkle Tree.

type PathItem

type PathItem struct {
	Hash          []byte
	DirectionLeft bool // true - left from parent, false - right from parent
}

PathItem helper struct for proof extraction, contains Hash and Direction from parent node

func SecondaryChain added in v0.1.1

func SecondaryChain(txs []txsystem.GenericTransaction, txIdx int, hashAlgorithm crypto.Hash) ([]*PathItem, error)

SecondaryChain returns hash chain for a secondary transaction based on list of secondary transactions

Jump to

Keyboard shortcuts

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