Documentation ¶
Overview ¶
Package merkle is responsible for creating the tree and verify the proof
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PartialTree ¶
type PartialTree struct {
// contains filtered or unexported fields
}
PartialTree represents a part of the original tree that is enough to calculate the root. Used in to extract the root in a merkle proof, to apply diff to a tree or to merge multiple trees into one. It is a rare case when you need to use this struct on it's own. It's mostly used inside
func NewPartialTree ¶
func NewPartialTree(hasher types.Hasher) PartialTree
NewPartialTree Takes hasher as an argument and build a Merkle Tree from them. Since it's a partial tree, hashes must be accompanied by their index in the original tree.
func (*PartialTree) Root ¶
func (pt *PartialTree) Root() []byte
Root returns the root of the tree, it is the first item hash of the last layer
type Proof ¶
type Proof struct {
// contains filtered or unexported fields
}
Proof is used to parse, verify, calculate a root for Merkle proofs. Proof requires specifying hashing algorithm and hash size in order to work. The hashing algorithm is set through the Hasher interface, which is supplied as a generic parameter to the Proof.
func NewProof ¶
func NewProof(leaves Leaves, proofHashes [][]byte, totalLeavesCount uint64, hasher types.Hasher) Proof
NewProof create new instance of merkle proof
func (Proof) ProofHashes ¶
ProofHashes returns all hashes from the proof, sorted from the left to right, bottom to top.
func (Proof) ProofHashesHex ¶
ProofHashesHex returns all hashes from the proof, sorted from the left to right, bottom to top, as a slice of lower hex strings.
func (Proof) Root ¶
Root calculates Merkle root based on provided leaves and proof hashes. Used inside the Verify method, but sometimes can be used on its own.
type Tree ¶
type Tree struct { UncommittedLeaves [][]byte // contains filtered or unexported fields }
Tree is a Merkle Tree that is well suited for both basic and advanced usage.
Basic features include the creation and verification of Merkle proofs from a set of leaves. This is often done in various cryptocurrencies.
Advanced features include being able to make transactional changes to a tree with being able to roll back to any previously committed state of the tree. This scenario is similar to Git and can be found in databases and file systems.
func NewTree ¶
NewTree creates a new instance of merkle tree. requires a hash algorithm to be specified.
func (Tree) FromLeaves ¶
FromLeaves clones the leaves and builds the tree from them
func (*Tree) Proof ¶
Proof Returns the Merkle proof required to prove the inclusion of items in a data set.