package testonly

import "github.com/transparency-dev/merkle/testonly"

Package testonly contains code and data for testing Merkle trees, such as a reference implementation of in-memory Merkle tree.

Index

Functions

func CompactTrees

func CompactTrees() [][][]byte

CompactTrees returns a slice of compact.Tree internal hashes for all subsequent trees built from LeafInputs() using the RFC 6962 hashing strategy.

func EmptyRootHash

func EmptyRootHash() []byte

EmptyRootHash returns the root hash for an empty Merkle tree that uses SHA256-based strategy from RFC 6962.

func LeafInputs

func LeafInputs() [][]byte

LeafInputs returns a slice of leaf inputs for testing Merkle trees.

func NodeHashes

func NodeHashes() [][][]byte

NodeHashes returns a structured slice of node hashes for all complete subtrees of a Merkle tree built from LeafInputs() using the RFC 6962 hashing strategy. The first index in the slice is the tree level (zero being the leaves level), the second is the horizontal index within a level.

func RootHashes

func RootHashes() [][]byte

RootHashes returns a slice of Merkle tree root hashes for all subsequent trees built from LeafInputs() using the RFC 6962 hashing strategy. Hashes are indexed by tree size starting from an empty tree.

Types

type Tree

type Tree struct {
	// contains filtered or unexported fields
}

Tree implements an append-only Merkle tree. For testing.

func New

func New(hasher merkle.LogHasher) *Tree

New returns a new empty Merkle tree.

func (*Tree) Append

func (t *Tree) Append(hashes ...[]byte)

Append adds the given leaf hashes to the end of the tree.

func (*Tree) AppendData

func (t *Tree) AppendData(entries ...[]byte)

AppendData adds the leaf hashes of the given entries to the end of the tree.

func (*Tree) ConsistencyProof

func (t *Tree) ConsistencyProof(size1, size2 uint64) ([][]byte, error)

ConsistencyProof returns the consistency proof between the two given tree sizes. Requires 0 <= size1 <= size2 <= Size(), otherwise may panic.

func (*Tree) Hash

func (t *Tree) Hash() []byte

Hash returns the current root hash of the tree.

func (*Tree) HashAt

func (t *Tree) HashAt(size uint64) []byte

HashAt returns the root hash at the given size. Requires 0 <= size <= Size(), otherwise panics.

func (*Tree) InclusionProof

func (t *Tree) InclusionProof(index, size uint64) ([][]byte, error)

InclusionProof returns the inclusion proof for the given leaf index in the tree of the given size. Requires 0 <= index < size <= Size(), otherwise may panic.

func (*Tree) LeafHash

func (t *Tree) LeafHash(index uint64) []byte

LeafHash returns the leaf hash at the given index. Requires 0 <= index < Size(), otherwise panics.

func (*Tree) Size

func (t *Tree) Size() uint64

Size returns the current number of leaves in the tree.

Source Files

constants.go tree.go

Version
v0.0.2 (latest)
Published
May 5, 2023
Platform
linux/amd64
Imports
4 packages
Last checked
4 days ago

Tools for package owners.