merkle

package
v0.0.0-...-157c9c8 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Assembler

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

Assembler of Leaves. Adds Leaves to a tree until the tree is complete.

func (*Assembler) Add

func (a *Assembler) Add(l *Leaf) bool

Add a Leaf to the tree being assembled. Returns a bool indicating if the Leaf was valid. Adding a Leaf multiple times will validate the Leaf, but will not change the tree. Add should not be called concurrently.

func (*Assembler) Done

func (a *Assembler) Done() (bool, Tree)

Done checks if assembly is done. If it is not, Tree will be nil.

type Builder

type Builder interface {
	Build(data []byte) Tree
}

Builder handles the logic of generating and populating a tree from data.

func NewBuilder

func NewBuilder(maxSize uint32, h func() hash.Hash) Builder

NewBuilder creates a Builder whose trees will follow the limits set by maxSize and branch and will use the provided hash.

type Description

type Description struct {
	Digest []byte
	Leaves uint32
}

Description of tree.

func (Description) Assembler

func (d Description) Assembler(h hash.Hash) *Assembler

Assembler creates a new Assembler from the Description. All Leaves added to the tree will be validated against against the initial validator.

type Leaf

type Leaf struct {
	Data  []byte
	Rows  []ValidatorRow
	Index uint32
}

Leaf represents a Data Leaf in a Merkle Tree and contains the rows necessary to validate that the leaf belongs to the Tree. Leaves can be used by an Assembler to assemble a tree.

func (*Leaf) Digest

func (l *Leaf) Digest(h hash.Hash, buf []byte) []byte

Digest of the leaf, this can be checked against a known Tree hash before starting assembly. The digest of each additional Leaf will be checked by the assembler.

type Tree

type Tree interface {
	Leaf(int) *Leaf
	Description() Description
	// Read fulfills io.Reader
	Read(p []byte) (n int, err error)
	// Seek fulfills io.Seeker
	Seek(offset int64, whence int) (int64, error)
	// contains filtered or unexported methods
}

type ValidatorRow

type ValidatorRow struct {
	SiblingDigest []byte
	IsFirst       bool
}

ValidatorRow represents a Branch in a Merkle Tree. It provides the digests needed for validation.

Jump to

Keyboard shortcuts

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