merkletree

package
v0.0.0-...-bdd61b6 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MerkleTree

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

func NewMerkleTree

func NewMerkleTree(leaves [][]byte, hash crypto.Hash) *MerkleTree

NewMerkleTree creates a new MerkleTree, it returns nil if no leaves are given.

func (*MerkleTree) Paths

func (mt *MerkleTree) Paths() []Path

Paths calculates and returns the paths of the MerkleTree.

type Path

type Path []*PathElement

Path is the path to a leaf, including the leaf itself.

func UnMarshallPath

func UnMarshallPath(d []byte, hash crypto.Hash) (ok bool, path Path)

UnMarshallPath returns a Path from a marshalled path, and true. Or false and nil on error.

func (Path) Compress

func (p Path) Compress() Path

Compress a path by removing empty elements which can be inferred.

func (Path) GetRoot

func (p Path) GetRoot() (root *PathElement, ok bool)

GetRoot returns true and the root from a path. False and nil if it has no root.

func (Path) Marshall

func (p Path) Marshall() []byte

Marshall a path into a byteslice.

func (Path) Verify1

func (p Path) Verify1(leafContent []byte, hash crypto.Hash) (ok bool)

Verify returns true if the path given is valid.

func (Path) Verify2

func (p Path) Verify2(leafContent []byte, hash crypto.Hash) (ok bool)

Verify2 returns true if the path given is valid. Verify2 should always be used since it detects

func (Path) VerifyLeaf

func (p Path) VerifyLeaf(leafContent []byte, hash crypto.Hash) (ok bool)

VerifyLeaf verifies that the leaf in a path matches it's content.

type PathElement

type PathElement struct {
	IsLeaf  bool   // Is this node a leaf?
	IsLeft  bool   // Is the left child of its father.
	Depths  uint32 // Depths to this node.
	Hash    []byte // Hash of content.
	IsEmpty bool   // Is this an empty node.
}

PathElement is a single element within a path.

func ParentPathElement

func ParentPathElement(isLeft bool, leftNode, rightNode *PathElement, hash crypto.Hash) *PathElement

ParentPathElement creates a new parent from two children.

func UnMarshallPathElement

func UnMarshallPathElement(d []byte, hashSize int) (ok bool, pathElement *PathElement)

UnMarshallPathElement returns a PathElement from the given marshalled PathElement and true, false and nil on error.

func (*PathElement) CalcHash

func (pe *PathElement) CalcHash(hash crypto.Hash, leftNodeHash, rightNodeHash []byte)

CalcHash calculates the Hash field of a PathElement from left and right children, both of which could be nil. The input uses 0x00 as prefix and postfix for the data to be hashed, and separates left and right by 0x00. Furthermore it includes the prefix of the PathElement which encodes Leaf/Interrior, Depths and Left/Right position.

func (*PathElement) CalcHashFromNodes

func (pe *PathElement) CalcHashFromNodes(hash crypto.Hash, leftNode, rightNode *PathElement)

CalcHashFromNodes calculates a new parent node hash from left and right node.

func (*PathElement) CalcHashLeaf

func (pe *PathElement) CalcHashLeaf(hash crypto.Hash, leafContent []byte)

CalcHashLeaf calculates the Hash field for a leaf.

func (*PathElement) Marshall

func (pe *PathElement) Marshall() []byte

Marshall a PathElement into a byteslice.

func (*PathElement) RootHash

func (p *PathElement) RootHash(hash crypto.Hash) []byte

func (*PathElement) String

func (pe *PathElement) String() string

Jump to

Keyboard shortcuts

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