registry

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 18 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 registry builds, signs, fetches and verifies registry indexes.

A registry is a git repo of service definitions. CI turns it into a single index.json plus index.json.sig, an Ed25519 signature over the exact bytes of index.json. Clients only trust an index whose signature checks out against a public key they already have, so a compromised web host can't push definitions to users.

Index

Constants

View Source
const IndexSchema = 1

IndexSchema is the index format version.

View Source
const KeyPrefix = "anyserve-ed25519:"

KeyPrefix marks an Anyserve public key string.

View Source
const MainName = "main"

MainName is the name of the built-in registry.

View Source
const MainPublicKey = "anyserve-ed25519:6dJrvi7OZIf0qcvUcX0ZoPv6b+RyRSFWjTtOLRrMYOE="

MainPublicKey is the pinned key the main registry is signed with. Rotating it requires a new Anyserve release.

View Source
const MainURL = "https://jonsjava.github.io/anyserve-registry/index.json"

MainURL is where the main registry index is published: GitHub Pages for github.com/jonsjava/anyserve-registry, updated with `make publish-registry`.

Variables

View Source
var ErrBadSignature = errors.New("registry index signature does not match the trusted key; refusing to use it")

ErrBadSignature means the index was not signed by a trusted key.

Functions

func EmbeddedBytes

func EmbeddedBytes() (index, sig []byte)

EmbeddedBytes returns the raw snapshot, for seeding the cache.

func Fetch

func Fetch(ctx context.Context, src Source) (index, sig []byte, err error)

Fetch downloads and verifies a source's index, returning the raw verified bytes and signature so the caller can cache them.

func GenerateKey

func GenerateKey() (privSeed, pub string, err error)

GenerateKey creates a signing key pair. The private key is returned as a base64 seed for storing in a file or CI secret; the public key in the "anyserve-ed25519:..." form clients pin.

func ParsePublicKey

func ParsePublicKey(s string) (ed25519.PublicKey, error)

ParsePublicKey decodes an "anyserve-ed25519:..." public key.

func PrivateKeyFromSeed

func PrivateKeyFromSeed(s string) (ed25519.PrivateKey, error)

PrivateKeyFromSeed decodes a base64 seed produced by GenerateKey.

func PublicKeyString

func PublicKeyString(sk ed25519.PrivateKey) string

PublicKeyString renders a private key's public half for pinning.

func Sign

func Sign(index []byte, sk ed25519.PrivateKey) []byte

Sign returns the signature file contents for index bytes.

func Verify

func Verify(index, sigFile []byte, pub ed25519.PublicKey) error

Verify checks index bytes against a signature file and a trusted key.

Types

type Cache

type Cache struct{ Dir string }

Cache stores verified indexes on disk, one directory per registry.

func (Cache) Load

func (c Cache) Load(src Source) (*Index, error)

Load reads a cached index and verifies it again, so a tampered cache file is caught too. It returns os.ErrNotExist when nothing is cached.

func (Cache) Save

func (c Cache) Save(name string, index, sig []byte) error

Save writes verified index bytes atomically.

type Index

type Index struct {
	Schema    int                `json:"schema"`
	Name      string             `json:"name"`
	Generated time.Time          `json:"generated"`
	Services  []*spec.Definition `json:"services"`
	// Skipped lists definitions in a downloaded index that this version of
	// Anyserve can't use. Not part of the published format.
	Skipped []Skipped `json:"-"`
}

Index is the published registry index.

func Build

func Build(name, dir string, now time.Time) (*Index, error)

Build reads every *.yaml definition in dir, validates them all and returns the index. It reports every invalid file, not just the first.

func Embedded

func Embedded() (*Index, error)

Embedded returns the verified snapshot built into this binary.

func ParseIndex

func ParseIndex(data []byte) (*Index, error)

ParseIndex decodes and checks an index. Call it only on verified bytes.

Each definition is decoded on its own. One that uses fields this version of Anyserve doesn't know (a feature added later), fails its checks, or requires a newer Anyserve is skipped and listed in Skipped, so a registry that has moved ahead still offers everything else.

func VerifyAndParse

func VerifyAndParse(src Source, index, sig []byte) (*Index, error)

VerifyAndParse verifies index bytes for a source and decodes them.

func (*Index) Find

func (ix *Index) Find(id string) (*spec.Definition, bool)

Find returns the service with the given id.

func (*Index) Marshal

func (ix *Index) Marshal() ([]byte, error)

Marshal encodes an index deterministically.

type Skipped

type Skipped struct {
	ID     string
	Reason string
}

Skipped is a definition left out of a parsed index, and why.

type Source

type Source struct {
	Name string `json:"name"`
	// URL of index.json. The signature is fetched from URL + ".sig".
	// file:// URLs and plain paths work for local testing.
	URL       string `json:"url"`
	PublicKey string `json:"public_key"`
}

Source is one configured registry.

func Main

func Main() Source

Main returns the built-in registry source.

Jump to

Keyboard shortcuts

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