mt

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

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 PlainTreeOutput

func PlainTreeOutput(merklePath []*PathItem, input []byte, hashAlgorithm crypto.Hash) []byte

PlainTreeOutput calculates the output hash of the chain.

Types

type Data

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

type MerkleTree

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

func New

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

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

Jump to

Keyboard shortcuts

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