Documentation ¶
Index ¶
- Constants
- func EncodeToHex(str []byte) string
- func Min(a, b int) int
- func VerifyProof(index uint64, leaf []byte, proof []Hash, root Hash) error
- func VerifyProofUsing(index uint64, leaf []byte, proof []Hash, root Hash, hasher hash.Hash) error
- type Hash
- type KeccakState
- type MerkleNode
- type MerkleTree
Constants ¶
const HashLength = 32
Variables ¶
This section is empty.
Functions ¶
func EncodeToHex ¶
EncodeToHex generates a hex string based on the byte representation, with the '0x' prefix
func VerifyProof ¶
VerifyProof verifies a Merkle tree proof of membership for provided data using the default hash type (Keccak256)
Types ¶
type KeccakState ¶
KeccakState wraps sha3.state. In addition to the usual hash methods, it also supports Read to get a variable amount of data from the hash state. Read is faster than Sum because it doesn't copy the internal state, but also modifies the internal state.
type MerkleNode ¶
type MerkleNode struct {
// contains filtered or unexported fields
}
MerkleNode represents a single node in merkle tree
type MerkleTree ¶
type MerkleTree struct {
// contains filtered or unexported fields
}
MerkleTree is the structure for the Merkle tree.
func NewMerkleTree ¶
func NewMerkleTree(data [][]byte) (*MerkleTree, error)
NewMerkleTree creates a new Merkle tree from the provided data and using the default hashing (Keccak256).
func NewMerkleTreeWithHashing ¶
func NewMerkleTreeWithHashing(data [][]byte, hasher hash.Hash) (*MerkleTree, error)
NewMerkleTreeWithHashing creates a new Merkle tree from the provided data and hash type
func (*MerkleTree) GenerateProof ¶
func (t *MerkleTree) GenerateProof(leaf []byte) ([]Hash, error)
GenerateProof generates the proof of membership for a piece of data in the Merkle tree.
func (*MerkleTree) LeafIndex ¶
func (t *MerkleTree) LeafIndex(leaf []byte) (uint64, error)
LeafIndex returns the index of given leaf if found in tree
func (*MerkleTree) String ¶
func (t *MerkleTree) String() string
String implements the stringer interface