registry

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package registry is the byte-prefix registry of SPEC.md section 4 and the hashes computed under it. It is named for that registry: each of the thirteen bytes of SPEC.md section 4.3 is applied here, so every record hash H(p, R), the key id, the prerotation commitment and the one Merkle walk the SPEC.md verifier computes go through this package. The hashes SPEC.md section 4.1 puts outside the registry do not: Bitcoin's SHA-256d values and the content digests (the constructions address, a keyring file, a served proof file).

  • the table of section 4.3, with each row's name, Construction.String (this file);
  • the record hash H(p, R) of sections 2.2 and 4.1, RecordHash (record_hash.go);
  • the key id and the prerotation commitment of sections 3.3 and 4.1, KeyIDOf and PrerotationCommitmentOf, which sit outside H(p, R) (key_id.go);
  • the inclusion walk of section 5.3, Walk, the one place the leaf and node bytes 0x00 and 0x01 are used (walk.go);
  • the canonical base64url of the pattern classes B64U32 and B64U64 of section 2.4, through which the 32 key bytes a key id hashes are decoded (base64url.go).

A row's byte is not exported: a byte is applied only by digest, which refuses the leaf and node, and by the walk, so no other package can take the leaf or node byte from here.

Rule 2 of SPEC.md section 10.6: prefix bytes and member sets come only from compiled constants. A construction is named by a Construction constant, never by a value a document carries, and nothing here reads a prefix byte or a member name from a document. rule2_test.go holds this package, and each package of the new verifier it lists, to that, and fails a package that imports this one without being on its list.

This file holds the table of SPEC.md section 4.3 as compiled constants, as section 4 asks of each of Truestamp's implementations: transcribed from spec/prefixes.json and held equal to it, and to section 4.3, by the tests of prefixes_test.go. A row is named by a Construction constant, and digest, the one function that applies a row's byte, lives beside the table.

Index

Constants

View Source
const MaxPathSteps = specdata.MaxPathSteps

MaxPathSteps is MAX_PATH_STEPS (SPEC.md section 9), the most nodes a path may hold.

Variables

View Source
var (
	// ErrNotInclusionProof marks a value that is not an object with an
	// INT leaf_index, an INT tree_size and an array path.
	ErrNotInclusionProof = errors.New("registry: not a MERKLE_PROOF")
	// ErrInvalidNode marks a path node that is not HEX64.
	ErrInvalidNode = errors.New("registry: a path node is not HEX64")
	// ErrIndexOutOfRange marks a leaf_index that is not below tree_size.
	ErrIndexOutOfRange = errors.New("registry: leaf_index is not below tree_size")
	// ErrTooManySteps marks a path of more than MAX_PATH_STEPS nodes.
	ErrTooManySteps = errors.New("registry: the path has more than MAX_PATH_STEPS nodes")
	// ErrWrongPathLength marks a path whose length is not the one
	// leaf_index and tree_size imply.
	ErrWrongPathLength = errors.New("registry: the path's length does not fit leaf_index and tree_size")
	// ErrNotHex64 marks a value that is not 64 lowercase hex characters.
	ErrNotHex64 = errors.New("registry: not HEX64")
)

The walk's refusals, and those of reading a carried proof. Each names the first check that fails, in the order ReadInclusionProof and Walk make them.

View Source
var ErrNotCanonicalB64U = errors.New("registry: not the canonical base64url of its class")

ErrNotCanonicalB64U marks a value that is not a string of its base64url class in full.

View Source
var ErrNotObject = errors.New("registry: the record is not an object")

ErrNotObject marks a nil record. A record internal/strictjson parses is never nil: it parses {} as an empty map that is not nil. So a nil record is one that was never parsed, such as the zero value a failed type assertion gives for a member that is null or absent, and is refused rather than hashed as {}.

View Source
var ErrNotRecordKind = errors.New("registry: not a kind under the record rule")

ErrNotRecordKind marks a Construction that is not under the rule of SPEC.md section 4.1: the Merkle leaf and node, the key id and the prerotation commitment, which hash raw bytes rather than a record, and a value that names no row.

Functions

func B64UOctets

func B64UOctets(class B64UClass) (int, bool)

B64UOctets returns the number of octets a string of class decodes to, and false for a value that is not a class.

func B64UPattern

func B64UPattern(class B64UClass) (string, bool)

B64UPattern returns class's pattern, written bare as in SPEC.md section 2.4, and false for a value that is not a class.

func DecodeB64U32

func DecodeB64U32(text string) ([32]byte, error)

DecodeB64U32 returns the 32 octets text spells when it matches B64U32, and otherwise ErrNotCanonicalB64U.

func DecodeB64U64

func DecodeB64U64(text string) ([64]byte, error)

DecodeB64U64 returns the 64 octets text spells when it matches B64U64, and otherwise ErrNotCanonicalB64U.

func DecodeHex64

func DecodeHex64(text string) ([32]byte, error)

DecodeHex64 returns the 32 bytes text spells when it is HEX64 (SPEC.md section 2.4): exactly 64 characters, each a digit or a lowercase a to f. Any other character refuses the whole value, so no case, space or other character is skipped as some decoders skip them. The refusal is ErrNotHex64.

func EncodeB64U

func EncodeB64U(octets []byte) string

EncodeB64U returns the canonical spelling of octets: unpadded base64url.

func KeyIDOf

func KeyIDOf(key [32]byte) string

KeyIDOf returns the key id of the 32-octet public key key, as 8 lowercase hex characters (the class KID of SPEC.md section 2.4).

func MatchesB64U

func MatchesB64U(class B64UClass, text string) bool

MatchesB64U reports whether text matches class in full. A value that is not a class matches nothing.

func PrerotationCommitmentOf

func PrerotationCommitmentOf(next [32]byte) string

PrerotationCommitmentOf returns the prerotation commitment of the 32-octet public key next, as 64 lowercase hex characters (HEX64).

func RecordHash

func RecordHash(kind Construction, record map[string]any) ([32]byte, error)

RecordHash returns H(p, R), the 32 octets of SHA-256(p || JCS(record)), with p the byte of kind. It refuses, with ErrNotRecordKind, a kind that is not one of RecordKinds; with ErrNotObject, a nil record; and returns the error of jcs.Encode for a record that is not within the value profile, which no parsed value is. A parsed object is never nil, so a parsed {} is hashed as {}.

func RecordHashHex

func RecordHashHex(kind Construction, record map[string]any) (string, error)

RecordHashHex returns RecordHash as 64 lowercase hex characters, the HEX64 a proof carries.

func Walk

func Walk(leaf [32]byte, p InclusionProof) ([32]byte, error)

Walk is merkle_path(leaf, p) of SPEC.md section 5.3: the root p implies for the leaf value leaf, which the caller has recomputed and never takes from the document. It refuses, in this order, a leaf_index not below tree_size (ErrIndexOutOfRange), a path of more than MAX_PATH_STEPS nodes (ErrTooManySteps), and a path whose length is not the one the index and size imply (ErrWrongPathLength). The root is returned for the caller to compare: Walk compares nothing with a carried root, and checks nothing of tree_size but its fit with the path (section 5.4 checks it).

Types

type B64UClass

type B64UClass int

B64UClass is a base64url pattern class of SPEC.md section 2.4.

const (
	// B64U32 is the class of a 32-octet value: a public key.
	B64U32 B64UClass = iota + 1
	// B64U64 is the class of a 64-octet value: a signature.
	B64U64
)

The two base64url classes.

type Construction

type Construction int

Construction names one row of the registry of SPEC.md section 4.3. Its values are the constants below, in the order of their bytes; the zero value names no row.

const (
	// MerkleLeaf is 0x00, the Merkle leaf, used only inside [Walk].
	MerkleLeaf Construction = iota + 1
	// MerkleNode is 0x01, the Merkle node, used only inside [Walk].
	MerkleNode
	// ClaimsHash is 0x10, claims_hash.
	ClaimsHash
	// ItemHash is 0x11, item_hash.
	ItemHash
	// EntropyHash is 0x20, entropy_hash.
	EntropyHash
	// ObservationHash is 0x21, observation_hash.
	ObservationHash
	// GenesisPreviousBlockHash is 0x30, the genesis previous_block_hash.
	GenesisPreviousBlockHash
	// BlockHash is 0x31, block_hash.
	BlockHash
	// EpochHash is 0x40, epoch_hash.
	EpochHash
	// ProofHash is 0x50, proof_hash.
	ProofHash
	// KeyID is 0x60, the key id, outside H(p, R).
	KeyID
	// PrerotationCommitment is 0x61, the prerotation commitment, outside
	// H(p, R).
	PrerotationCommitment
	// Handover is 0x62, the handover a rotation's outgoing key signs.
	Handover
)

The rows of SPEC.md section 4.3, in the order of their bytes.

func RecordKinds

func RecordKinds() []Construction

RecordKinds returns the kinds under the rule, in the order of their bytes: every row of SPEC.md section 4.3 that hashes JCS of a value. Each call returns a new slice.

func (Construction) String

func (c Construction) String() string

String returns c's name in spec/prefixes.json, or "Construction(n)" when c names no row.

type InclusionProof

type InclusionProof struct {
	LeafIndex uint64
	TreeSize  uint64
	Path      [][32]byte
}

InclusionProof is a MERKLE_PROOF (SPEC.md section 5.2): the leaf's position, the number of leaves, and the sibling hashes from the leaf up to the root.

func ReadInclusionProof

func ReadInclusionProof(value any) (InclusionProof, error)

ReadInclusionProof reads a carried MERKLE_PROOF, a value as internal/strictjson parses it, into the InclusionProof Walk takes. It reads the members leaf_index, path and tree_size by those names, and no other: SHAPE (SPEC.md section 10.2, step 7) holds the object to exactly them. It refuses (ErrNotInclusionProof) a value that is not an object, a leaf_index or tree_size that is not an INT (an integer from 0 to MAX_INTEGER), and a path that is not an array; and (ErrInvalidNode) a node that is not HEX64.

Jump to

Keyboard shortcuts

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