beacons

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package beacons is a thin client for the Truestamp Beacons JSON:API surface (GET /api/json/beacons, /beacons/latest, /beacons/:id, /beacons/by-hash/:hash). A Beacon is a compact "proof of life" projection of a finalized block: {id, hash, timestamp, previous_hash}. The server side is documented in truestamp-v2/docs/BEACONS_API_IMPLEMENTERS_GUIDE.md.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnauthorized = errors.New("not authenticated")
	ErrNotFound     = errors.New("beacon not found")
	ErrBadRequest   = errors.New("bad request")
	ErrRateLimited  = errors.New("rate limited")
	ErrServer       = errors.New("server error")
)

Errors surfaced by the client. CLI layers may errors.Is these to pick an exit code and user-facing message.

Functions

func ValidateHash

func ValidateHash(s string) error

ValidateHash returns nil iff s is exactly 64 lowercase hex characters. Exported so cobra commands can run this client-side before the network.

func ValidateUUIDv7

func ValidateUUIDv7(s string) error

ValidateUUIDv7 returns nil iff s parses as a UUID whose version nibble is 7.

Types

type APIError

type APIError struct {
	Status     int
	Detail     string // preferred; falls back to Title
	RetryAfter string // verbatim Retry-After header on 429
	// contains filtered or unexported fields
}

APIError carries HTTP status + preserved `errors[].detail` from the JSON:API envelope for display to the user. Wraps one of the sentinel errors above so callers can errors.Is() the class while still showing the detail text.

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) Unwrap

func (e *APIError) Unwrap() error

type Beacon

type Beacon struct {
	ID           string `json:"id"`            // UUIDv7
	Hash         string `json:"hash"`          // 64 lowercase hex
	Timestamp    string `json:"timestamp"`     // ISO 8601 UTC
	PreviousHash string `json:"previous_hash"` // 64 lowercase hex
}

Beacon is the JSON shape returned by every beacon endpoint. All four fields are always present on success; a missing field is treated as a parse error rather than recovered from.

func ByHash

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

ByHash fetches a single beacon by its 64-char lowercase hex hash.

func Get

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

Get fetches a single beacon by UUIDv7 id.

func Latest

func Latest(ctx context.Context, cfg Config) (*Beacon, error)

Latest fetches the most recent finalized/committed beacon.

func List

func List(ctx context.Context, cfg Config, limit int) ([]Beacon, error)

List fetches up to `limit` most-recent beacons, newest first. The server accepts 1..100; callers should pre-clamp if they want a friendly error, but the server's own 400 detail surfaces cleanly through APIError too.

type Config

type Config struct {
	APIURL string // e.g. https://www.truestamp.com/api/json
	APIKey string // Bearer token (never logged)
	Team   string // optional tenant id
}

Config carries the subset of runtime configuration needed for a request. Kept small to avoid importing the top-level config package.

Jump to

Keyboard shortcuts

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