Documentation ¶
Index ¶
- type MerkleTree
- type Path
- func (p Path) Compress() Path
- func (p Path) GetRoot() (root *PathElement, ok bool)
- func (p Path) Marshall() []byte
- func (p Path) Verify1(leafContent []byte, hash crypto.Hash) (ok bool)
- func (p Path) Verify2(leafContent []byte, hash crypto.Hash) (ok bool)
- func (p Path) VerifyLeaf(leafContent []byte, hash crypto.Hash) (ok bool)
- type PathElement
- func (pe *PathElement) CalcHash(hash crypto.Hash, leftNodeHash, rightNodeHash []byte)
- func (pe *PathElement) CalcHashFromNodes(hash crypto.Hash, leftNode, rightNode *PathElement)
- func (pe *PathElement) CalcHashLeaf(hash crypto.Hash, leafContent []byte)
- func (pe *PathElement) Marshall() []byte
- func (p *PathElement) RootHash(hash crypto.Hash) []byte
- func (pe *PathElement) String() string
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 ¶
UnMarshallPath returns a Path from a marshalled path, and true. Or false and nil on error.
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.
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) String ¶
func (pe *PathElement) String() string