Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateMerkleRootFromMerklePath ¶
func CalculateMerkleRootFromMerklePath( leafHash hash.Byte32, merklePath MerklePath) hash.Byte32
CalculateMerkleRootFromMerklePath is a stand along function that more properly belongs out in client-world, where it will be used. Note that it is completely decoupled from any access to the Merkle Tree the path has been derived from, and does its work only from the dependency-injected arguments. It has been included in this module, so that a person studying the Merkle Tree logic can find it all in one place. This is the function that starts with the hash value of a record and consumes the Merkle Path one hash at a time by concatenating each hash encountered to the previously calculated value, before rehashing the concatenated bytes and repeating the process for the next hash in the path. Note that is seeks advice from the Merkle Path about in which order the elements should be concatenated at each level.
Types ¶
type MerklePath ¶
type MerklePath []MerklePathElement
The MerklePath type models the Merkle Path of a given leaf in the Merkle Tree. It comprises essentially the sequence of hash values that must by cumulatively appended to the hash of a record before being re-hashed and moving on to repeat the process with the next value in the path. If this traversal algorithm produces the Merkle Root hash value at the end, the Merkle Path truth-test has been passed. The reason it is not just a sequence of hash values, is that the thing traversing the path needs also to know if the values found should be appended to the previous value or prepended before doing the re hash operation.
type MerklePathElement ¶
type MerklePathElement struct {
Hash hash.Byte32
UseFirstInConcatenation bool // me+other, not other+me
}
The MerklePathElement type is a trivial container that binds together a hash value and a flag to guide the Merkle Path traversal algorithm.
type MerkleTree ¶
type MerkleTree struct {
// contains filtered or unexported fields
}
MerkleTree is our implementation of a Merkle Tree. It comprises simply a sequence of Rows, representing the tiers in the tree, with the rows[0] being the leaf row. There are some notes in a comment at the end of this file about the thinking behind the choice of this data structure and storage.
func NewMerkleTree ¶
func NewMerkleTree(bottomRow Row) (tree MerkleTree)
NewMerkleTree is a factory that makes the Merkle Tree corresponding to a given set of leaf row hash values.
func (MerkleTree) MerklePathForLeaf ¶
func (tree MerkleTree) MerklePathForLeaf(leafIndex int) ( merklePath MerklePath)
MerklePathForLeaf is a an API method that builds the Merkle Path that corresponds to a given leaf in the tree. You specify which leaf by providing its record index. It works bottom up calculating which nodes in the tree are the siblings from which hashes should be collected.
func (MerkleTree) MerkleRoot ¶
func (tree MerkleTree) MerkleRoot() hash.Byte32
MerkleRoot is a simple API query function, that exists so that the row-based implementation details do not leak outside the object.