merkle

package
v0.0.0-...-3ccdb94 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hash

func Hash(data string) [32]byte

Hash computes the SHA-256 hash of input data

func HashPair

func HashPair(hash1, hash2 [32]byte) [32]byte

Types

type File

type File struct {
	Data string
}

type MerkleTree

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

func BuildMerkleTree

func BuildMerkleTree(files []File) *MerkleTree

BuildMerkleTree constructs a Merkle tree from the given files

func (*MerkleTree) Update

func (t *MerkleTree) Update(index int, newData string) error

Update updates the data at the specified index and recalculates the necessary hashes.

type Node

type Node struct {
	Left   *Node
	Right  *Node
	Parent *Node
	Hash   [32]byte
}

func (*Node) GetSibling

func (n *Node) GetSibling() *Node

GetSibling returns the sibling of the node. If the node is a left child, return the right child and vice versa.

Jump to

Keyboard shortcuts

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