merkletools_go

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2022 License: Apache-2.0 Imports: 3 Imported by: 3

README

merkle-tools-go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func VerifyBTCProof

func VerifyBTCProof(proofSteps []ProofStep, targetHash []byte, merkleRoot []byte) bool

VerifyBTCProof : Checks the validity of the proof generated with MakeBTCTree and returns true or false

func VerifyProof

func VerifyProof(proofSteps []ProofStep, targetHash []byte, merkleRoot []byte) bool

VerifyProof : Checks the validity of the proof and returns true or false

Types

type MerkleTree

type MerkleTree struct {
	Leaves []*Node
	Nodes  []*Node
	Root   []byte
}

MerkleTree : The complete tree structure

func (*MerkleTree) AddLeaf

func (mt *MerkleTree) AddLeaf(hash []byte)

AddLeaf : Adds one leaf to the tree

func (*MerkleTree) AddLeaves

func (mt *MerkleTree) AddLeaves(hashes [][]byte)

AddLeaves : Adds multiple leaves to the tree

func (*MerkleTree) GetLeaf

func (mt *MerkleTree) GetLeaf(index int) *Node

GetLeaf : Gets the Leaf node at a given index

func (*MerkleTree) GetLeafCount

func (mt *MerkleTree) GetLeafCount() int

GetLeafCount : Returns the total number of leaves

func (*MerkleTree) GetMerkleRoot

func (mt *MerkleTree) GetMerkleRoot() []byte

GetMerkleRoot : Returns the Root for this Tree

func (*MerkleTree) GetProof

func (mt *MerkleTree) GetProof(index int) []ProofStep

GetProof : Returns the proof for a leaf at the given index

func (*MerkleTree) MakeBTCTree

func (mt *MerkleTree) MakeBTCTree()

MakeBTCTree : Builds the tree using the given Leaves These tree will duplicate odd nodes to enforce even number on each level This is for compatability with how Bitcoin builds Merkle trees Hash operations are performed twice

func (*MerkleTree) MakeTree

func (mt *MerkleTree) MakeTree()

MakeTree : Builds the tree using the given Leaves

func (*MerkleTree) Reset

func (mt *MerkleTree) Reset()

Reset : Clears all values in tree

type Node

type Node struct {
	Parent     *Node
	Sibling    *Node
	IsLeftNode bool
	IsRoot     bool
	Hash       []byte
}

Node : A node on the tree

type ProofStep

type ProofStep struct {
	Left  bool
	Value []byte
}

ProofStep : A sibling position and value used to descibe an inclusion proof

Jump to

Keyboard shortcuts

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