entropy

package
v0.14.0 Latest Latest
Warning

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

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

Documentation

Overview

Package entropy is a thin client for the Truestamp entropy observations JSON:API surface (GET /api/json/entropy_observations and /entropy_observations/:id).

An entropy observation is a witness: a public random value Truestamp captured from an independent source (a NIST Randomness Beacon pulse, a Stellar ledger close, a Bitcoin block) together with the moment it was captured. Item submission commits the newest observation per source into the item's metadata, which is what opens the submitted-after edge of the submission window: the item cannot have been submitted before a value that did not yet exist. Each observation is also a proof subject in its own right (`proofs get --type entropy_*`), and this package is the discovery path to the ids those proofs are asked for by.

Two things the server does not offer, worked around here the way internal/blocks does:

  • There is no /latest route: latest is a sort plus a limit of one.
  • There is no by-hash route: a hash lookup is filter[entropy_hash], and the hex shape is validated before the request is sent.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnauthorized = jsonapi.ErrUnauthorized
	ErrForbidden    = jsonapi.ErrForbidden
	ErrNotFound     = jsonapi.ErrNotFound
	ErrBadRequest   = jsonapi.ErrBadRequest
	ErrRateLimited  = jsonapi.ErrRateLimited
	ErrServer       = jsonapi.ErrServer
)
View Source
var ErrAmbiguousHash = errors.New("more than one entropy observation matches that hash")

ErrAmbiguousHash is returned when a by-hash lookup matches more than one row. The server does not assume hash uniqueness, so this is reported rather than resolved by picking one.

View Source
var Sources = []string{"entropy_nist", "entropy_stellar", "entropy_bitcoin"}

Sources is the closed set of entropy sources, in the order the CLI lists them. They are the wire names, identical to the proof subject types `proofs get --type` takes, so one vocabulary names both.

Functions

func ValidateHash

func ValidateHash(h string) error

ValidateHash rejects anything that is not exactly 64 lowercase hex characters, before it can reach filter[entropy_hash].

func ValidateSource

func ValidateSource(s string) error

ValidateSource rejects a --source value outside Sources.

func ValidateUUIDv7

func ValidateUUIDv7(id string) error

ValidateUUIDv7 rejects an id that is not a UUIDv7.

Types

type APIError

type APIError = jsonapi.APIError

The transport, the class sentinels and APIError live in internal/jsonapi; these aliases keep this client's surface stable for the commands that errors.Is its classes.

type Config

type Config = jsonapi.Config

The transport, the class sentinels and APIError live in internal/jsonapi; these aliases keep this client's surface stable for the commands that errors.Is its classes.

type ListOptions

type ListOptions struct {
	Source      string
	Limit       int
	After       string // continue forward from a Page.NextCursor
	Before      string // continue backward from a Page.PrevCursor
	OldestFirst bool   // walk from the beginning instead of the newest row
	Count       bool
}

ListOptions configures a list request. Source empty means every source; otherwise it must be one of Sources. The paging fields are the ones every keyset-paged list shares (jsonapi.SetPageQuery).

type Observation

type Observation struct {
	ID                string         `json:"id"`
	Source            string         `json:"source"`
	State             string         `json:"state"`
	EntropyHash       string         `json:"entropy_hash"`
	ObservationHash   string         `json:"observation_hash"`
	MetadataHash      string         `json:"metadata_hash"`
	SigningKeyID      string         `json:"signing_key_id"`
	Signature         string         `json:"signature"`
	CaptureMethod     string         `json:"capture_method"`
	SourcePublishedAt string         `json:"source_published_at"`
	InsertedAt        string         `json:"inserted_at"`
	BlockID           string         `json:"block_id,omitempty"`
	Entropy           map[string]any `json:"entropy"`
	Metadata          map[string]any `json:"metadata"`
}

Observation is the public shape of one entropy observation. Entropy is the source's own record under its own field names (a Stellar ledger's sequence and closed_at, a NIST pulse's index, a Bitcoin block's height) and is rendered as published, never renamed. Its numbers are decoded as json.Number so a ledger sequence is never re-printed as a float.

func ByHash

func ByHash(ctx context.Context, cfg Config, hash string) (*Observation, error)

ByHash fetches one observation by its 64-hex entropy hash. There is no by-hash route, so this filters; see the package doc.

func Get

func Get(ctx context.Context, cfg Config, id string) (*Observation, error)

Get fetches one observation by UUIDv7 id.

func Latest

func Latest(ctx context.Context, cfg Config, source string) (*Observation, error)

Latest fetches the newest observation: the most recently captured from any source, or from one source when source is set.

type Page

type Page struct {
	Observations []Observation
	NextCursor   string
	PrevCursor   string
	Total        int
	Limit        int // the page size the server actually used
}

Page is one page of observations plus the cursor for the next and, when asked for, the server's total.

func List

func List(ctx context.Context, cfg Config, opts ListOptions) (*Page, error)

List fetches one page of observations, newest first.

Jump to

Keyboard shortcuts

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