merkletree

package
v1.10.8 Latest Latest
Warning

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

Go to latest
Published: May 10, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// todo: 64 levels causes an overflow issue
	MaxLevels = 63
)

Variables

View Source
var (
	ErrMerkleTreeFull    = errors.New("merkle tree is full")
	ErrInvalidLevelCount = errors.New("level count is invalid")
	ErrLeafNotFound      = errors.New("leaf not found")
)

Functions

func Verify

func Verify(proof []Hash, root Hash, leaf Leaf) bool

Types

type Hash

type Hash []byte

func (Hash) String

func (h Hash) String() string

type Leaf

type Leaf []byte

type MerkleTree

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

Reference in-memory implementation only. It's not terribly performant, but can be used to validate other more optimized implementations.

func New

func New(levels uint8, seeds []Seed) (*MerkleTree, error)

func (*MerkleTree) AddLeaf

func (t *MerkleTree) AddLeaf(leaf Leaf) error

func (*MerkleTree) GetExpectedHashFromPair

func (t *MerkleTree) GetExpectedHashFromPair(h1, h2 Hash) Hash

func (*MerkleTree) GetIndexForLeaf

func (t *MerkleTree) GetIndexForLeaf(leaf Leaf) (int, error)

func (*MerkleTree) GetLeafCount

func (t *MerkleTree) GetLeafCount() uint64

func (*MerkleTree) GetLeafHash

func (t *MerkleTree) GetLeafHash(leaf Leaf) Hash

func (*MerkleTree) GetProofForLeafAtIndex

func (t *MerkleTree) GetProofForLeafAtIndex(forLeaf, untilLeaf uint64) ([]Hash, error)

todo: We'll need a more efficient version of this method in production

func (*MerkleTree) GetRoot

func (t *MerkleTree) GetRoot() Hash

func (*MerkleTree) GetZeroValues

func (t *MerkleTree) GetZeroValues() []Hash

func (*MerkleTree) String

func (t *MerkleTree) String() string

type Seed

type Seed []byte

Jump to

Keyboard shortcuts

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