beacons

package
v0.15.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: 6 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/kb/api/beacon-api.md.

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
)

Functions

func ValidateHash

func ValidateHash(s string) error

ValidateHash returns nil iff s is exactly 64 lowercase hex characters.

func ValidateUUIDv7

func ValidateUUIDv7(s string) error

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

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 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.

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 added in v0.14.0

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

ListOptions configures a list request; the paging fields are the ones every keyset-paged list shares (jsonapi.SetPageQuery).

type Page added in v0.14.0

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

Page is one page of beacons plus the cursors for its neighbours 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 beacons, newest first unless asked otherwise.

GET /beacons is a JSON:API index over a keyset-paginated read, the same contract as /blocks: page[limit], page[after], page[before], page[count] and sort=id|-id, answered as a resource document with links.next/prev and meta.page.total. Like every collection it clamps page[limit] to its max_page_size (250) and reports the size used in meta.page.limit; the floor is cmd/limits.go's.

Jump to

Keyboard shortcuts

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