merkle

package
v0.0.0-...-fffdf24 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2022 License: AGPL-3.0 Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HCAS = struct {
	Sha256 HashCombiningAlgorithm
}{

	Sha256: "sha256",
}

HCAS represents hash combining algorithms

View Source
var VHAS = struct {
	None ValueHashAlgorithm
}{

	None: "none",
}

VHAS represents value hash algorithms

Functions

This section is empty.

Types

type BagEntries

type BagEntries []BagEntry

BagEntries is a slice of BagEntries

func (BagEntries) Len

func (b BagEntries) Len() int

Len is the number of BagEntries

func (BagEntries) Less

func (b BagEntries) Less(i, j int) bool

Less reports whether the BagEntry with index i should sort before the BagEntry with index j

func (BagEntries) Swap

func (b BagEntries) Swap(i, j int)

Swap swaps the BagEntries with indexes i and j

type BagEntry

type BagEntry [2][]byte

BagEntry is a key-value pair with first element as key and second as value

type BagHasher

type BagHasher interface {
	// Patch patches the latest version of the hasher with BagEntries and optional keys for
	// generating proofs, and it returns the root hash and required proofs. When a value for a key
	// is empty, i.e. len([]byte) == 0, that key is used to delete any existing item with the same
	// key in the hasher. The order of the given entries will not affect the root hash if applying
	// different permutations of the same entries results in the same bag of BagEntries
	Patch(entries BagEntries, proofKeys ...[]byte) (hash []byte, proofs []Proof)

	// SaveVersion saves current version for the hasher and returns the next version number. Any
	// changes made to the saved version become finalized, and BagEntries of that version hence
	// become immutable. All future changes will be made to the next version
	SaveVersion() (nextVersion int64)

	// Version returns the current version number
	Version() (version int64)

	// GetProofs gets merkle proofs for BagEntries with given keys in given version
	GetProofs(version int64, keys ...[]byte) (proofs []Proof)

	// GetLatestProofs gets merkle proofs for BagEntries with given keys in the latest version
	GetLatestProofs(keys ...[]byte) (proofs []Proof)

	// Height returns the height of the underlie tree in BagHasher
	Height() (height int)

	// Size returns the number of nodes in the underlie tree in BagHasher
	Size() (size int)
}

BagHasher is the generic hashing interface for a bag of unordered key-value pairs

type HashCombiningAlgorithm

type HashCombiningAlgorithm string

HashCombiningAlgorithm represents hash combining algorithm

type PathNode

type PathNode struct {
	// LeftHash is the left hash value
	LeftHash []byte
	// RightHash is the right hash value
	RightHash []byte
}

PathNode represents a node along the merkle path

type Proof

type Proof struct {
	// Key is the key of the BagEntry this proof represents
	Key []byte
	// Value is the value of the BagEntry this proof represents
	Value []byte
	// RootHash is the merkle root hash
	RootHash []byte
	// ValueHashAlgorithm is the name of the value hash algorithm used
	ValueHashAlgorithm ValueHashAlgorithm
	// HashCombiningAlgorithm is the name of the hash combining used
	HashCombiningAlgorithm HashCombiningAlgorithm
	// Path is the merkle path
	Path []PathNode
	// Meta is any meta data associated with this proof
	Meta interface{}
}

Proof represents the merkle proof of a key-value pair

func (Proof) Verify

func (p Proof) Verify() (verified bool, err error)

Verify verifies current Proof

type ValueHashAlgorithm

type ValueHashAlgorithm string

ValueHashAlgorithm represents value hash algorithm

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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