Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type HTree ¶
type HTree struct {
// contains filtered or unexported fields
}
HTree accepts a sequence of leaf hashes via its Add method. A leaf hash is the result of calling LeafHash on a string. After adding all leaf hashes in the sequence, their merkle root hash may be read via the Root method.
Note that a Tree works by converting its input from a sequence of strings to the corresponding sequence of leaf hashes and feeding those to an HTree.
func NewProofHTree ¶
NewProofHTree produces a new HTree that can compactly prove a given reference hash is in it. After adding elements to the tree, call Proof to get the proof.
func (*HTree) Add ¶
Add adds a leaf hash to the sequence in h. The caller must not reuse the space in item. It is an error to call Add after a call to Root or Proof.
type Proof ¶
type Proof struct { Steps []ProofStep // contains filtered or unexported fields }
Proof is a merkle proof.
func (Proof) Hash ¶
Hash computes the hash of a merkle proof. A valid merkle proof hash matches the root hash of the merkle tree it came from.
To prove that x is in a tree, create a tree t with NewProofTree(h, x). Then fill the tree with calls to t.Add. Then get the proof p with t.Proof(). Then check that p.Hash(h, x) is the same as t.Root(). This will be true only if there was a call t.Add(x).
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree accepts a sequence of strings via its Add method. It builds a merkle hash tree from them. After adding all strings in the sequence, their merkle root hash may be read via the Root method.
func NewProofTree ¶
NewProofTree produces a new Tree that can compactly prove a given string is in it. After adding elements to the tree, call Proof to get the proof.
func (*Tree) Add ¶
Add adds a string to the sequence in m. The caller may reuse the space in str. It is an error to call Add after a call to Root or Proof.