proof

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: 15 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 proof fetches proofs from the Truestamp service: the exact bytes of a proof from the raw proof route, the name `proofs get --to-file` gives a proof, the service's refusals to serve one, and the shape of a subject id and the server's resolution of an id to its subject type. It reads no proof's members to verify or show it: `truestamp verify` and `truestamp inspect` read a proof through internal/verifier.

Index

Constants

View Source
const (
	// ConstructionsFull carries the text itself, the default.
	ConstructionsFull = "full"
	// ConstructionsReference carries the text's URL, which names its
	// SHA-256.
	ConstructionsReference = "reference"
	// ConstructionsNone carries neither.
	ConstructionsNone = "none"
)

The constructions modes of SPEC.md section 7.2 (Modes), as the raw proof route's `constructions` parameter spells them: how the proof carries the constructions text. Each mode is its own signed document, and the verdict never depends on it.

View Source
const (
	// GenerateCodeNoBlockCommitment means the subject's block has no
	// commitment on a public chain yet. Retryable.
	GenerateCodeNoBlockCommitment = "no_block_commitment"
	// GenerateCodeCommitmentNotFinal means the block's commitment is
	// recorded and none is final yet. Retryable.
	GenerateCodeCommitmentNotFinal = "commitment_not_final"
	// GenerateCodeEvidenceUnconfirmed means Truestamp's own chain reads did
	// not confirm the evidence the proof would carry. Retryable.
	GenerateCodeEvidenceUnconfirmed = "evidence_unconfirmed"
	// GenerateCodeSubjectNotReady means the subject is not committed in a
	// block yet. Retryable.
	GenerateCodeSubjectNotReady = "subject_not_ready"
	// GenerateCodeWitnessUnavailable means a witness the item's fingerprint
	// commits to could not be found, so no proof was served rather than one
	// without it. Retryable.
	GenerateCodeWitnessUnavailable = "witness_unavailable"
	// GenerateCodeSigningUnavailable means Truestamp's signer refused, so
	// no proof was served. Retryable.
	GenerateCodeSigningUnavailable = "signing_unavailable"
	// GenerateCodeLookupFailed means a record the proof is built from could
	// not be read. Retryable.
	GenerateCodeLookupFailed = "lookup_failed"
	// GenerateCodeSubjectRedacted means the item's claims are redacted, so
	// it has no proof until it is restored.
	GenerateCodeSubjectRedacted = "subject_redacted"
	// GenerateCodeProofTooLarge means the document would be larger than
	// the largest Truestamp serves.
	GenerateCodeProofTooLarge = "proof_too_large"
	// GenerateCodeGenerationFailed means Truestamp's records do not give a
	// proof its own verifier accepts.
	GenerateCodeGenerationFailed = "generation_failed"
)

Codes the server sends in `meta.code` when it refuses to serve a proof, the generate action's refusals.

These are deliberately not reason codes of SPEC.md section 12.1 (Reason codes): those say why a verifier refuses or fails a proof in hand, and these say why the server could not serve one.

View Source
const ConstructionsParameter = "constructions"

ConstructionsParameter is the name of the raw proof route's query parameter that gives the constructions mode, and of the `proofs get` flag that sets it. It names a request's parameter, never the proof's member: SPEC.md section 7.2, item 2, lets a verifier read that member only at SHAPE, and this constant is never an index into a document.

Variables

View Source
var (
	// ErrNotAnID is a value that is no id, item code or item_hash.
	ErrNotAnID = errors.New("not an id")
	// ErrItemCodeTypo is a value with the shape of an item code that
	// holds a U or fails the code's check.
	ErrItemCodeTypo = errors.New("an item code with a typo")
)

Why DetectIDType refused a value, for errors.Is.

ConstructionsModes is every constructions mode, in the order help text lists them.

View Source
var ErrDifferentItem = errors.New("the server returned a proof for a different item")

ErrDifferentItem is a served item proof that is not of the item asked for: CheckServedItem's refusal.

View Source
var ErrSeveralTypes = errors.New("verifiable as more than one subject type")

ErrSeveralTypes is a subject the server says is verifiable as more than one subject type: ResolveSubjectType refuses rather than picks.

Functions

func CheckServedItem added in v0.17.0

func CheckServedItem(subjectType string, shape IDType, ref string, served []byte) error

CheckServedItem checks that served, the proof served for a subject of subjectType named by ref, is a proof of that item, before anything is written. shape is ref's shape and ref its canonical form, as DetectIDType gives them. Only an item is checked: for any other subjectType it gives nil. For a UUIDv7, the id of the served record, /proof/subject/record/id (SPEC.md section 3.6 (Layouts by type)), must equal ref, and nothing else of the proof is read; for an item code, the item code of the recomputed item_hash (ServedItemHash) must; for an item_hash, the recomputed item_hash itself must, all 64 hex characters. The item_hash the document carries is never read. A mismatch is ErrDifferentItem. A served document that is not an item proof with a record is an error too, and so is a record with no string id, for a UUIDv7, or one whose item_hash cannot be recomputed, for a code or an item_hash.

A matching code shows only that the recomputed item_hash begins with the 75 bits the code is written from (SPEC.md section 3.9), so a code checks the item a person named, and an item_hash checks it whole.

func FetchRawCtx added in v0.17.0

func FetchRawCtx(ctx context.Context, apiURL, team, subjectType, id, constructions string) ([]byte, error)

FetchRawCtx reads the proof Truestamp serves of the subject id of subjectType, one of the six registry names, in the constructions mode constructions, from the raw proof route,

GET {apiURL}/proof/raw/{subjectType}/{id}?constructions={constructions}

and returns the body exactly as served: the served form of SPEC.md section 3.1 (The envelope), never decoded, re-encoded or re-indented, so a file written from it holds the bytes Truestamp signed and served. Only a 200 is a proof. A refusal is a *GenerateAPIError when it names a detail, a rate limit the *jsonapi.APIError of a 429, and a body over MAX_READ_OCTETS, which no verifier reads, an error. The credential is applied by the process-wide auth.Authorizer and team is sent as the tenant header.

func FileName added in v0.17.0

func FileName(subjectType, id string, served []byte) (string, error)

FileName is the name `proofs get --to-file` gives the proof served of the subject id of subjectType: `<CODE>.proof.json` for an item, with CODE its item code (SPEC.md section 3.9 (The item code)), and `<id>.proof.json` for every other subject, with `.proof.json` the extension SPEC.md section 3.1 (The envelope) gives a proof file. The constructions mode adds nothing to the name.

An item's code is computed from its recomputed item_hash (ServedItemHash), never from the id given or from any hash the document carries; a served document that is not an item proof with a record gives no name. An id that holds a path separator, or is empty, "." or "..", gives no name either, so a file is only ever written in the current directory.

func ResolveSubjectType added in v0.14.0

func ResolveSubjectType(ctx context.Context, apiURL, team, id string) (string, error)

ResolveSubjectType asks the server what a bare UUIDv7 refers to, so `proofs get <id>` does not have to require --type.

This is the one place id-shape dispatch cannot work. Items, blocks, beacons and entropy observations all use UUIDv7, so nothing client-side can tell them apart. The server can: POST /utilities/resolve-id returns one match for a UUIDv7 it can show, the first of an item, a block, an entropy observation and a team, with its `proof_type`, exactly the value --type takes, and `also_verifiable_as`, the other types the same subject is verifiable as: a block's is ["beacon"], since a block is also verifiable as a beacon. id is sent as the caller gives it, which cmd/proofs_get.go makes the UUIDv7's canonical lowercase text.

The types a match names, its proof_type and then each of its also_verifiable_as, are the answer: one is the type returned, and more than one, a block's, is refused with ErrSeveralTypes, since which proof the caller meant changes what the proof commits to: a block id needs --type block or --type beacon. A match with no proof_type, a team, names none.

It is deliberately a fallback, not the default path. Passing --type is one fewer round trip, and it keeps an id-classification service out of the loop for a tool whose whole thesis is not taking the server's word for things. The classification only decides which proof to ASK for; the proof that comes back is still verified against its own signed type.

Resolution is visibility-gated server-side: an id you cannot see returns no match rather than revealing that it exists.

func ServedItemHash added in v0.17.0

func ServedItemHash(served []byte) ([32]byte, error)

ServedItemHash is the item_hash of the item proof served, recomputed from its subject's record as H(0x11, JCS(proof.subject.record)), the row item_hash of SPEC.md section 4.3 (The table) that DERIVE recomputes (SPEC.md section 10.2, step 9), never the item_hash the document carries. A served document the strict reader refuses, or that is not an item proof with a record, gives an error.

Types

type GenerateAPIError added in v0.13.0

type GenerateAPIError struct {
	StatusCode int
	Code       string
	Detail     string
	// Header is the request header the refusal names in
	// `source.header`, "tenant" when the server refused the team.
	Header string
}

GenerateAPIError is a refusal of the raw proof route carrying the server's `meta.code` when one was sent, for example `no_block_commitment` for a subject whose block is not committed yet.

func (*GenerateAPIError) Error added in v0.13.0

func (e *GenerateAPIError) Error() string

type IDType

type IDType string

IDType is the syntactic shape of a subject id. It is NOT the subject's semantic kind (item / entropy / block / beacon): the raw proof route, GET /proof/raw/{type}/{id}, takes the type in its path, and ResolveSubjectType asks the server for it when the caller gives none (see cmd/proofs_get.go's id-shape default). The authoritative label for a proof in hand is its own signed `type` (SPEC.md section 3.2 (Members of `proof`)), which internal/verifier reads once the strict reader of internal/strictjson has parsed the file, and checks at SHAPE (SPEC.md section 10.2, step 7). Use DetectIDType for pre-flight validation and for sanity-checking positional args.

const (
	// IDTypeUUIDv7 is the 36-character text of a UUIDv7 (RFC 9562 section
	// 5.7), the id of every item, block, entropy observation and beacon
	// (SPEC.md section 2.4, the UUID7 class).
	IDTypeUUIDv7 IDType = "uuidv7"
	// IDTypeItemCode is an item code as SPEC.md section 3.9 (The item
	// code) lets a reader take it, which names only an item.
	IDTypeItemCode IDType = "item_code"
	// IDTypeItemHash is 64 hex characters, which names a subject only as
	// an item's item_hash, so a caller takes it only where the subject is
	// known to be an item.
	IDTypeItemHash IDType = "item_hash"
)

func DetectIDType

func DetectIDType(id string) (IDType, string, error)

DetectIDType returns the syntactic shape of id and its canonical form: a UUIDv7 or an item_hash in lowercase, an item code in its one uppercase spelling.

id is classified exactly as given, as the app's Truestamp.IdShape does: nothing is trimmed and no character is mapped, so a leading space or a trailing line feed makes a value no id. A UUID is only its 36-character text with hyphens, in either case, and only of version 7 with the RFC 9562 variant, by ids.IsUUIDv7Text, the one UUIDv7 rule of every command: its 32-hex, braced and urn: forms and every other version are no id. An item code is read by itemcode.Parse, as SPEC.md section 3.9 (The item code) lets a reader read one; a value with its shape that holds a U or fails the check is ErrItemCodeTypo. Every other value is ErrNotAnID, whose message says what the value is and not what is expected: each command takes its own forms, so the caller names them.

Jump to

Keyboard shortcuts

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