Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct { // Customizable hash function used for tree generation. HashFunc HashFuncType // Number of goroutines run in parallel. // If RunInParallel is true and NumRoutine is set to 0, use number of CPU as the number of goroutines. NumRoutines int // Mode of the Merkle Tree generation. Mode ModeType // If true, generate a dummy node with random hash value. // Otherwise, then the odd node situation is handled by duplicating the previous node. NoDuplicates bool // IMPORTANT: To match the behavior of merkletreejs, sort leaves before building tree SortLeaves bool // IMPORTANT: To match the behavior of merkletreejs, sort pairs before hashing them SortPairs bool }
Config is the configuration of Merkle Tree.
type HashFuncType ¶
HashFuncType is the signature of the hash functions used for Merkle Tree generation.
type MerkleTree ¶
type MerkleTree struct { *Config // Root is the Merkle root hash Root []byte // Leaves are Merkle Tree leaves, i.e. the hashes of the data blocks for tree generation Leaves [][]byte // Proofs are proofs to the data blocks generated during the tree building process Proofs []*Proof // Depth is the Merkle Tree depth Depth uint32 // contains filtered or unexported fields }
MerkleTree implements the Merkle Tree structure
func New ¶
func New(config *Config, blocks []DataBlock) (m *MerkleTree, err error)
New generates a new Merkle Tree with specified configuration.
func (*MerkleTree) GenerateProof ¶
func (m *MerkleTree) GenerateProof(dataBlock DataBlock) (*Proof, error)
GenerateProof generates the Merkle proof for a data block with the Merkle Tree structure generated beforehand. The method is only available when the configuration mode is ModeTreeBuild or ModeProofGenAndTreeBuild. In ModeProofGen, proofs for all the data blocks are already generated, and the Merkle Tree structure is not cached.
Click to show internal directories.
Click to hide internal directories.