merklehasher

package
v4.0.0-...-3659144 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 8 Imported by: 3

Documentation

Index

Constants

View Source
const (
	LeafHashPrefix = 0
	NodeHashPrefix = 1
)

Domain separation prefixes.

Variables

View Source
var (
	// ErrProofValueNotFound gets returned when the value for which to compute the proof was not found.
	ErrProofValueNotFound = ierrors.New("the value for which to compute the inclusion proof was not found in the supplied list")
)

Functions

func RegisterSerixRules

func RegisterSerixRules[V Value](api *serix.API)

Types

type Hasher

type Hasher[V Value] struct {
	// contains filtered or unexported fields
}

Hasher implements the hashing algorithm described in the IOTA protocol RFC-12.

func NewHasher

func NewHasher[V Value](h crypto.Hash) *Hasher[V]

NewHasher creates a new Hasher using the provided hash function.

func (*Hasher[V]) ComputeProof

func (t *Hasher[V]) ComputeProof(values []V, valueToProof V) (*Proof[V], error)

ComputeProof computes the audit path given the values and the value we want to create the inclusion proof for.

func (*Hasher[V]) ComputeProofForIndex

func (t *Hasher[V]) ComputeProofForIndex(values []V, index int) (*Proof[V], error)

ComputeProofForIndex computes the audit path given the values and the index of the value we want to create the inclusion proof for.

func (*Hasher[V]) EmptyRoot

func (t *Hasher[V]) EmptyRoot() []byte

EmptyRoot returns a special case for an empty tree. This is equivalent to Hash(nil).

func (*Hasher[V]) Hash

func (t *Hasher[V]) Hash(data [][]byte) []byte

Hash computes the Merkle tree hash of the provided data.

func (*Hasher[V]) HashValues

func (t *Hasher[V]) HashValues(values []V) ([]byte, error)

HashValues computes the Merkle tree hash of the provided BlockIDs.

func (*Hasher[V]) Size

func (t *Hasher[V]) Size() int

Size returns the length, in bytes, of a digest resulting from the given hash function.

type LeafHash

type LeafHash[V Value] struct {
	Hash []byte `serix:",lenPrefix=uint8"`
}

LeafHash contains the hash of a leaf in the tree.

type MerkleHashable

type MerkleHashable[V Value] interface {
	// contains filtered or unexported methods
}

type MerkleHashableType

type MerkleHashableType = uint8
const (
	MerkleHashableTypeNode      MerkleHashableType = iota
	MerkleHashableTypeLeafHash  MerkleHashableType = 1
	MerkleHashableTypeValueHash MerkleHashableType = 2
)

type Node

type Node[V Value] struct {
	Left  MerkleHashable[V] `serix:"l"`
	Right MerkleHashable[V] `serix:"r"`
}

Node contains the hashes of the left and right children of a node in the tree.

type Proof

type Proof[V Value] struct {
	MerkleHashable[V] `serix:",inlined"`
}

func ProofFromBytes

func ProofFromBytes[V Value](bytes []byte) (*Proof[V], int, error)

func ProofFromJSON

func ProofFromJSON[V Value](bytes []byte) (*Proof[V], error)

func (*Proof[V]) Bytes

func (p *Proof[V]) Bytes() ([]byte, error)

func (*Proof[V]) ContainsValue

func (p *Proof[V]) ContainsValue(value V, hasher *Hasher[V]) (bool, error)

func (*Proof[V]) Hash

func (p *Proof[V]) Hash(hasher *Hasher[V]) []byte

func (*Proof[V]) JSONEncode

func (p *Proof[V]) JSONEncode() ([]byte, error)

type Value

type Value interface {
	serializer.Byter
}

type ValueHash

type ValueHash[V Value] struct {
	Hash []byte `serix:",lenPrefix=uint8"`
}

ValueHash contains the hash of the value for which the proof is being computed.

Jump to

Keyboard shortcuts

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