merkle

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MerkleHash

func MerkleHash(x, y *big.Int) (*big.Int, error)

MerkleHash calculates the Merkle hash of two big integers.

Parameters: - x: the first big integer - y: the second big integer Returns: - *big.Int: the Merkle hash of the two big integers - error: an error if the calculation fails

func ProofMerklePath

func ProofMerklePath(root *big.Int, leaf *big.Int, path []*big.Int) bool

ProofMerklePath checks if a given leaf node is part of a Merkle tree path.

It takes the root node of the Merkle tree, the leaf node to be checked, and the path of nodes from the leaf to the root. The function recursively traverses the path, verifying each node against the expected hash value. If the path is valid, the function returns true; otherwise, it returns false.

Parameters: - root: The root node of the Merkle tree as a *big.Int - leaf: The leaf node to be checked as a *big.Int - path: The path of nodes from the leaf to the root as a slice of *big.Int Returns: - bool: True if the leaf node is part of the Merkle tree path, false otherwise

Types

type FixedSizeMerkleTree

type FixedSizeMerkleTree struct {
	Leaves   []*big.Int
	Branches [][]*big.Int
	Root     *big.Int
}

func NewFixedSizeMerkleTree

func NewFixedSizeMerkleTree(leaves ...*big.Int) (*FixedSizeMerkleTree, error)

NewFixedSizeMerkleTree creates a new fixed-size Merkle tree.

It takes a variable number of *big.Int leaves as input and returns a pointer to a FixedSizeMerkleTree and an error. The function builds the Merkle tree using the given leaves and sets the tree's root. If there is an error during the tree building process, the function returns nil and the error.

Parameters: - leaves: a slice of *big.Int representing the leaves of the tree. Returns: - *FixedSizeMerkleTree: a pointer to a FixedSizeMerkleTree - error: an error if any

func (*FixedSizeMerkleTree) Proof

func (mt *FixedSizeMerkleTree) Proof(leaf *big.Int) ([]*big.Int, error)

Proof calculates the Merkle proof for a given leaf in the FixedSizeMerkleTree.

Parameters: - leaf: The leaf for which the Merkle proof is calculated Returns: - []*big.Int: The Merkle proof for the given leaf - error: An error if the calculation of the Merkle proof fails

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL