itemcode

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: 1 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 itemcode writes the item code of SPEC.md section 3.9 (The item code): a short name for an item, for people and links, computed from the 32 bytes of a recomputed item_hash, and read back from what a person types or pastes. No proof carries it, no verification step reads it, and it is never a verdict input, a report member or evidence; a match shows only that two item_hash values begin with the same 75 bits.

Index

Constants

View Source
const Alphabet = "0123456789ABCDEFGHJKMNPQRSTVWXYZ"

Alphabet is the 32 symbols of SPEC.md section 3.9, step 3: a value's symbol is the character at its position.

View Source
const Length = 16

Length is the number of symbols in an item code: 15 values of 5 bits and the check value.

Variables

This section is empty.

Functions

func FromItemHash

func FromItemHash(h [32]byte) string

FromItemHash returns the item code of the item whose item_hash is the 32 bytes h, in its one spelling: 16 uppercase symbols with no separator.

Step 1 takes the leftmost 75 bits of h, most significant bit of the first byte first, as 15 values of 5 bits. Step 2 runs r = m(r) XOR v over them, from r = 0, where m multiplies by x in GF(2^5) modulo x^5 + x^2 + 1 (shift left one bit, and XOR with 37 when the result is 32 or more); the check value is m(r), the final m included. Step 3 writes the 15 values and the check value with Alphabet.

func ItemHashOfRecord

func ItemHashOfRecord(record map[string]any) ([32]byte, error)

ItemHashOfRecord returns the item_hash of the item whose record is record, recomputed as H(0x11, JCS(record)), the row item_hash of SPEC.md section 4.3 (The table) that DERIVE recomputes (SPEC.md section 10.2, step 9), the one input of the item code. It returns the registry's refusal of a record it cannot hash.

func OfItemRecord

func OfItemRecord(record map[string]any) (string, error)

OfItemRecord returns the item code of the item whose record is record, the value an item proof carries at /proof/subject/record: the code of its item_hash recomputed as H(0x11, JCS(record)), the row item_hash of SPEC.md section 4.3 (The table), never a hash a document carries. It returns the registry's refusal of a record it cannot hash.

func Parse

func Parse(s string) (string, error)

Parse reads a typed or pasted item code as SPEC.md section 3.9 (The item code) lets a reader, and nothing more, and returns it in its one spelling.

The value is read exactly as given: nothing is trimmed. It must be ASCII, 16 letters or digits in four groups of four with at most one separator, a space, a hyphen or an underscore, at each of the three places between the groups and nowhere else, so it is at most 19 characters. A tab, a line feed, any other character and any character that is not ASCII make it not a code, ErrNotACode. Letters may be in any case, and I and L read as 1 and O as 0, in either case. A value of that shape whose 16 symbols are not all of Alphabet, or for which the loop of step 2 run over all 16 values does not end with r = 0, is ErrTypo.

Types

type ParseError

type ParseError string

ParseError is why Parse refused a value, one of the two constants below, which errors.Is compares.

const (
	// ErrNotACode is a value that is not an item code at all.
	ErrNotACode ParseError = "not an item code"
	// ErrTypo is a value with the shape of an item code, four groups of
	// four ASCII letters or digits, that holds a letter outside
	// [Alphabet] (a U) or fails the check: a mistyped symbol or two
	// symbols exchanged.
	ErrTypo ParseError = "an item code with a mistyped or exchanged symbol"
)

func (ParseError) Error

func (e ParseError) Error() string

Jump to

Keyboard shortcuts

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