commit

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package commit computes RFC 6962 Merkle roots and inclusion paths: the root a store reference commits to, one per named store, over the commitments (carrier txids) of that store's members.

Domain separation is the point of RFC 6962's prefixes: a leaf hash and an interior node hash can never collide, so a member cannot be passed off as a subtree or the other way round. The prefixes are frozen at an application's first mint along with everything else a reader recomputes.

Index

Constants

This section is empty.

Variables

View Source
var ErrIndex = errors.New("commit: index out of range")

ErrIndex reports an index outside the leaf set.

Functions

func LeafHash

func LeafHash(leaf [32]byte) [32]byte

LeafHash is SHA-256(0x00 || leaf).

func NodeHash

func NodeHash(left, right [32]byte) [32]byte

NodeHash is SHA-256(0x01 || left || right).

func Root

func Root(leaves [][32]byte) [32]byte

Root is the RFC 6962 root over leaves in order. The empty tree's root is SHA-256 of the empty string, as the RFC defines it, so an empty store still has one well-defined commitment.

func Verify

func Verify(leaf [32]byte, path Path, root [32]byte) bool

Verify recomputes the root from leaf and path and compares it with root.

Types

type Path

type Path []Step

Path is an inclusion path from a leaf to the root.

func Prove

func Prove(leaves [][32]byte, index int) (Path, error)

Prove returns the inclusion path for leaves[index].

type Step

type Step struct {
	Hash [32]byte
	// Left is true when the sibling sits to the LEFT of the node being
	// proven, so the verifier hashes NodeHash(sibling, current).
	Left bool
}

Step is one sibling on an inclusion path.

Jump to

Keyboard shortcuts

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