library

package
v0.4.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 28 Imported by: 1 module, 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 library is experimental: its API and documented formats may change in a minor release; see https://nsgo.games/docs/stability/.

Package library finds shared asset packs, editor plugin packs and templates in a library and installs them into a game project.

The Index

A library is a text index anyone can add a pack or a Go plugin to with a pull request: a versioned YAML file (index.yaml, IndexFileName) listing each pack's name, kind, version, description, tags, license, source and digest and, from version 2 on, its optional authors, homepage, icon and screenshots, and each Go plugin's name, module, latest version, engine constraint, the same metadata and the digest of its plugin.yaml. A plugin entry holds metadata only, as its code stays in its Go module. ParseIndex reads versions 1 and 2 and refuses unknown fields, fields a version 1 index cannot hold, other versions, duplicate names and sources that leave the library, and EncodeIndex writes the deterministic form ParseIndex reads back unchanged, in the index's own version. Index.Search finds packs by kind and by words in their names, descriptions and tags, and Index.SearchPlugins finds plugins by words in their names, modules, descriptions and tags.

Packs

A pack is a directory holding a manifest, pack.yaml (ManifestFileName), and the files it lists. The manifest names the pack, gives its kind (asset, plugin or template, as project.PackKinds names them), its version and license, the project directory its files go to (into, by default packs/<name>), and the references installing it adds to game.yaml: autoload scenes and resources, and, for a plugin pack, the editor plugins it turns on. A pack's digest (Digest) is the SHA-256 of a sha256sum-style listing of its files, pack.yaml included, so the index pins the exact bytes of every file whatever form they were fetched in.

Fetching

Open reads an index from a directory, a file or an http(s) URL, and Library.Fetch fetches a pack from its source, relative to the index or an absolute URL, file by file as its manifest lists them, and refuses one whose digest, name, kind or version differs from its index entry. Plain http is accepted only for a loopback host, for the index and for a pack's absolute source alike; anything else must use https, every file is limited to MaxFileSize bytes, and without a Library.Client a request gives up on a server that stalls.

Signatures

A version 2 index lists publishers, each with an Ed25519 root key and a signed revocation list, and an entry may carry the publisher that signed it, the root's certificate for the release key that signed it, the signature and a review tier. The keys and signed documents are NSGo's tsx/pkg ones (GenerateKey, Certify, SignEntry, Revoke). Library.Verify checks an entry's certificate, signature and revocations, and refuses a revocation list older than one a TrustState saw; Library.VerifyInProject does so for a project, reading requireSigned from its game.yaml and keeping its TrustStateFile. Library.Review shows an entry's tier, which only the official index (DefaultIndex) may raise above community.

Installing

PlanInstall works out what installing a fetched pack does to a project, without writing anything: the files to write and remove, and the project.File afterwards, which records the pack under packs with the files it wrote and the references it added. Installing a pack again updates it, replacing its files and references with the new version's; a file that is already in the project and is not the pack's is refused rather than overwritten. A pack's files and the directory they go to must stay inside the project, outside hidden directories such as .github, with names every platform can hold and no two differing only in case, and may not be Go source or another file the Go toolchain builds. PlanRemove undoes an install. Change.Apply then writes the files and game.yaml, restoring what it changed when a write fails. Install and Remove do both for a project directory, and the game library command and the scene editor's library panel run them.

Index

Examples

Constants

View Source
const (
	// ReviewOfficial marks an entry the game project publishes itself.
	ReviewOfficial = "official"
	// ReviewReviewed marks an entry the game project's maintainers reviewed.
	ReviewReviewed = "reviewed"
	// ReviewCommunity marks an entry nobody but its publisher vouches for, the tier of every entry outside the official index.
	ReviewCommunity = "community"
)

The review tiers an index entry's review field takes. Only the official index (DefaultIndex) may mark an entry official or reviewed; Library.Review shows every other index's entries as community.

View Source
const DefaultIndex = "https://raw.githubusercontent.com/nsgo-dev/game/main/library/index.yaml"

DefaultIndex is the shared library's index, in this repository's library directory, which the game library command reads unless told otherwise.

View Source
const IndexFileName = "index.yaml"

IndexFileName is the index's file name, which Open reads from a directory.

View Source
const IndexMinVersion = 1

IndexMinVersion is the oldest index schema version ParseIndex reads; an index keeps the version it was read with, and EncodeIndex writes it back.

View Source
const IndexSchemaComment = "# yaml-language-server: $schema=" + IndexSchemaURL

IndexSchemaComment is the first line EncodeIndex writes for a version 1 index: a YAML comment that points a YAML language server at IndexSchemaURL. ParseIndex ignores it like any other comment.

View Source
const IndexSchemaCommentV2 = "# yaml-language-server: $schema=" + IndexSchemaURLV2

IndexSchemaCommentV2 is the first line EncodeIndex writes for a version 2 index, pointing a YAML language server at IndexSchemaURLV2.

View Source
const IndexSchemaURL = "https://nsgo.games/schemas/library.v1.json"

IndexSchemaURL is where the JSON Schema of version 1 library indexes is published. EncodeIndex names it, or IndexSchemaURLV2 for a version 2 index, in a yaml-language-server comment on the index's first line, so editors and AI tools validate and complete it as it is written.

View Source
const IndexSchemaURLV2 = "https://nsgo.games/schemas/library.v2.json"

IndexSchemaURLV2 is where the JSON Schema of version 2 library indexes is published.

View Source
const IndexVersion = 2

IndexVersion is the newest index schema version, which a new index states: version 2 adds the plugins list, the publishers list, the packs' optional authors, homepage, icon and screenshots, and the packs' publisher, certificate, signature and review.

View Source
const ManifestFileName = "pack.yaml"

ManifestFileName is a pack's manifest, at the root of its directory.

View Source
const ManifestVersion = 1

ManifestVersion is the manifest schema version this package reads and writes.

View Source
const MaxFileSize = 64 << 20

MaxFileSize is the largest file a pack may hold, in bytes.

View Source
const MaxFiles = 4096

MaxFiles is the most files a pack's manifest may list.

View Source
const PublicKeyPrefix = "ed25519:"

PublicKeyPrefix starts a publisher's root public key in an index, as in "ed25519:<base64>".

View Source
const SchemaComment = "# yaml-language-server: $schema=" + SchemaURL

SchemaComment is the first line EncodeManifest writes: a YAML comment that points a YAML language server at SchemaURL. ParseManifest ignores it like any other comment.

View Source
const SchemaURL = "https://nsgo.games/schemas/pack.v1.json"

SchemaURL is where the JSON Schema of version 1 pack manifests is published. EncodeManifest names it in a yaml-language-server comment on pack.yaml's first line, so editors and AI tools validate and complete the manifest as it is written.

View Source
const SecretKeyPrefix = "ed25519-secret:"

SecretKeyPrefix starts a secret key file game library keygen writes, so that a secret key pasted where a public one belongs is refused rather than published.

View Source
const TrustStateFile = ".game/library-trust.yaml"

TrustStateFile is where a project keeps its TrustState, relative to the project directory. It sits under .game, which projects do not commit, as the file only remembers what this checkout saw.

View Source
const TrustStateVersion = 1

TrustStateVersion is the version of the trust state file this package reads and writes.

Variables

View Source
var (
	// ErrUnsigned refuses an entry without a signature where signed entries are required (project.File.RequireSigned).
	ErrUnsigned = errors.New("library: the entry is not signed")
	// ErrSignature refuses an entry whose certificate or signature does not verify against its publisher's root, or says something other than the entry.
	ErrSignature = errors.New("library: the entry's signature does not verify")
	// ErrRevoked refuses an entry whose release key or digest its publisher's revocation list names.
	ErrRevoked = errors.New("library: revoked by its publisher")
	// ErrStaleRevocations refuses every entry of a publisher whose revocation list is older than one the project saw before, or missing after one was seen: an index serving it may be replaying an old list to undo a revocation.
	ErrStaleRevocations = errors.New("library: the publisher's revocation list is older than one seen before")
)

Why an entry is refused; Verify's errors wrap them with the details.

ReviewTiers are the values an entry's review field takes, from the most to the least trusted.

Functions

func Certify

func Certify(root ed25519.PrivateKey, publisher string, release ed25519.PublicKey, notBefore, notAfter time.Time) (string, error)

Certify has the publisher's root certify release to sign the publisher's entries between notBefore and notAfter, and returns the certificate as an entry's certificate field holds it.

func DecodePublicKey

func DecodePublicKey(text string) (ed25519.PublicKey, error)

DecodePublicKey reads a key EncodePublicKey wrote.

func DecodeSecretKey

func DecodeSecretKey(text string) (ed25519.PrivateKey, error)

DecodeSecretKey reads a key EncodeSecretKey wrote, ignoring surrounding spaces and line breaks.

func DefaultDir

func DefaultDir(name string) string

DefaultDir is the project directory a pack called name installs into when neither its manifest nor the installer names one.

func Digest

func Digest(files map[string][]byte) string

Digest returns the digest of a pack's files: the SHA-256, in lower-case hexadecimal, of one line per file sorted by path, each the file's own SHA-256 in lower-case hexadecimal, two spaces and its slash-separated path, ended by a newline. The listing is what sha256sum prints for the files named in byte order, so the digest can be checked without this package; the game library digest command prints it for a pack's directory.

func EncodeIndex

func EncodeIndex(idx *Index) ([]byte, error)

EncodeIndex validates idx and serializes it as deterministic 2-space YAML that ParseIndex reads back unchanged, in idx's own version, under the schema comment of that version.

func EncodeManifest

func EncodeManifest(m *Manifest) ([]byte, error)

EncodeManifest validates m and serializes it as deterministic 2-space YAML that ParseManifest reads back unchanged.

func EncodePublicKey

func EncodePublicKey(key ed25519.PublicKey) string

EncodePublicKey writes key as an index's publisher root holds it: PublicKeyPrefix followed by base64.

func EncodeSecretKey

func EncodeSecretKey(key ed25519.PrivateKey) string

EncodeSecretKey writes key as a key file holds it: SecretKeyPrefix followed by the base64 of its seed.

func EncodeTrustState

func EncodeTrustState(s *TrustState) ([]byte, error)

EncodeTrustState validates s and serializes it as deterministic 2-space YAML that ParseTrustState reads back unchanged.

func GenerateKey

func GenerateKey() (ed25519.PrivateKey, error)

GenerateKey makes a root or release key, as tsx/pkg makes the keys that sign NSGo packages.

func KeyID

func KeyID(key ed25519.PublicKey) string

KeyID is the ID of a public key, as revocation lists and Verification name release keys: the first 8 bytes of its SHA-256, in hex (tsx/pkg's KeyID).

func Revoke

func Revoke(root ed25519.PrivateKey, list RevocationList) (string, error)

Revoke has the publisher's root sign list, whose Publisher and Sequence (1 or more) must be set, and returns it as a publisher's revocations field holds it. Keys and digests are lower-cased, sorted and made unique, and IssuedAt is set to now when it is zero.

func SignEntry

func SignEntry(e *Entry, release ed25519.PrivateKey, certificate string, at time.Time) error

SignEntry signs e with release, which certificate certifies, at time at: it sets e's publisher, certificate and signature. It refuses a certificate whose key is not release's or whose time does not cover at.

func ValidateIndex

func ValidateIndex(idx *Index) error

ValidateIndex checks that idx conforms to the schema of its version: version 1 holds packs without the optional metadata version 2 added, and version 2 adds plugins and that metadata.

func ValidateManifest

func ValidateManifest(m *Manifest) error

ValidateManifest checks that m conforms to the version 1 schema.

func WriteTrustState

func WriteTrustState(projectDir string, s *TrustState) error

WriteTrustState writes s as the trust state of the project in projectDir.

Types

type Autoload

type Autoload struct {
	// Scenes are scene files to autoload; each path is one of Manifest.Files, ending in .yaml or .yml.
	Scenes []project.Entry `yaml:"scenes,omitempty"`
	// Resources are other files to autoload; each path is one of Manifest.Files.
	Resources []project.Entry `yaml:"resources,omitempty"`
}

Autoload lists the pack files installing a pack autoloads.

type Certificate

type Certificate struct {
	// Publisher is the ID of the publisher whose root signed the certificate.
	Publisher string
	// Key is the release key.
	Key ed25519.PublicKey
	// NotBefore and NotAfter bound when the key may sign entries.
	NotBefore, NotAfter time.Time
}

Certificate is what a publisher's root says about a release key: whose it is and when it may sign.

func ParseCertificate

func ParseCertificate(text string) (Certificate, error)

ParseCertificate reads a certificate without checking who signed it, for showing what it says; Verify checks it against the publisher's root.

type Change

type Change struct {
	// Project is the project file afterwards.
	Project *project.File
	// Pack is the pack's record: the one Project holds after an install, or the one it held before a removal.
	Pack project.Pack
	// Write maps each file to write, by its slash-separated path from the project root, to its content.
	Write map[string][]byte
	// Remove lists the files to remove, by their slash-separated paths from the project root, sorted.
	Remove []string
	// contains filtered or unexported fields
}

Change is what installing or removing a pack does to a project, worked out by PlanInstall or PlanRemove and carried out by Apply.

func Install

func Install(projectDir string, p *Pack, dir string) (*Change, error)

Install installs p into the Go project in projectDir, whose game.yaml it reads, as PlanInstall and Change.Apply describe, and returns what it did. An install that changes nothing, such as the same release of a pack installed again, writes nothing.

func PlanInstall

func PlanInstall(fsys fs.FS, f *project.File, p *Pack, dir string) (*Change, error)

PlanInstall works out what installing p into the project at the root of fsys, whose project file is f, does, without writing anything. The pack's files go under dir; when dir is empty, an update keeps them in the directory the installed version went to, and a first install puts them in the manifest's into or DefaultDir. The directory must stay inside the project, and none of its elements may be hidden (start with '.') or be a name some platform cannot hold.

When f already records the pack, the install updates it: the files of the old version the new one lacks are removed, the others replaced, and the autoload entries it added are replaced by the new version's, keeping their places. A file the project already has is refused unless the old version wrote it or it has the content the pack would write, and so is a file another pack wrote; an autoload scene or resource of the pack's name that the project already has is refused too. Every plugin the pack names under plugins must already be listed under plugins: in game.yaml; a missing plugin is refused with a hint to run game plugin add.

f is not changed; the returned Change's Project is a validated copy.

Example

A library is an index of packs, each a directory with a pack.yaml; PlanInstall shows what installing one would write and how game.yaml would record it.

package main

import (
	"context"
	"fmt"
	"testing/fstest"

	"github.com/nsgo-dev/game/pkg/project"
	"github.com/nsgo-dev/game/pkg/tooling/library"
)

func main() {
	manifest := []byte(`version: 1
name: coins
kind: asset
packVersion: 1.0.0
description: A spinning coin.
license: CC0-1.0
files: [coin.png]
autoload:
  resources:
    - name: coin
      path: coin.png
`)
	libFiles := fstest.MapFS{
		"packs/coins/pack.yaml": {Data: manifest},
		"packs/coins/coin.png":  {Data: []byte("PNG")},
	}
	pack, err := library.ReadPack(libFiles, "packs/coins")
	if err != nil {
		fmt.Println(err)
		return
	}
	index := fmt.Sprintf(`version: 1
packs:
  - name: coins
    kind: asset
    packVersion: 1.0.0
    description: A spinning coin.
    license: CC0-1.0
    source: packs/coins
    sha256: %s
`, pack.Digest())
	libFiles["index.yaml"] = &fstest.MapFile{Data: []byte(index)}

	lib, err := library.OpenFS(libFiles, "index.yaml")
	if err != nil {
		fmt.Println(err)
		return
	}
	for _, e := range lib.Index.Search("asset", "coin") {
		fmt.Println("found", e.Name, e.PackVersion)
	}
	pack, err = lib.Fetch(context.Background(), "coins")
	if err != nil {
		fmt.Println(err)
		return
	}

	game := project.MustParse([]byte("version: 2\nname: Coin Run\nid: dev.example.coinrun\nappVersion: 0.1.0\nwindow: {width: 320, height: 180}\n"))
	change, err := library.PlanInstall(fstest.MapFS{}, game, pack, "")
	if err != nil {
		fmt.Println(err)
		return
	}
	for _, name := range []string{"packs/coins/coin.png", "packs/coins/pack.yaml"} {
		fmt.Println("write", name, len(change.Write[name]), "bytes")
	}
	fmt.Println("autoload", change.Project.Autoload.Resources[0].Name, change.Project.Autoload.Resources[0].Path)
	rec := change.Project.FindPack("coins")
	fmt.Println("record", rec.Name, rec.Kind, rec.PackVersion, rec.Dir, rec.Files)
}
Output:
found coins 1.0.0
write packs/coins/coin.png 3 bytes
write packs/coins/pack.yaml 180 bytes
autoload coin packs/coins/coin.png
record coins asset 1.0.0 packs/coins [coin.png pack.yaml]

func PlanRemove

func PlanRemove(fsys fs.FS, f *project.File, name string) (*Change, error)

PlanRemove works out what removing the installed pack called name from the project at the root of fsys, whose project file is f, does, without writing anything: its files are removed, edited or not, and so are the autoload entries it added. A main scene that was the pack's is unset. Entries under plugins: in game.yaml are left intact.

func Remove

func Remove(projectDir, name string) (*Change, error)

Remove removes the installed pack called name from the project in projectDir, as PlanRemove and Change.Apply describe, and returns what it did.

func (*Change) Apply

func (c *Change) Apply(projectDir string) error

Apply carries out c in the project directory projectDir: it removes and writes c's files, deleting the directories a removal leaves empty inside the pack's directory (and packs, for a pack in its DefaultDir), then writes c.Project to game.yaml in the canonical form project.Encode writes, which keeps no comments. When a step fails, it restores the files it had changed and returns the error.

func (*Change) ApplyFiles

func (c *Change) ApplyFiles(projectDir string) (undo func() error, err error)

ApplyFiles removes and writes c's files in the project directory projectDir, leaving game.yaml to the caller, such as an editor that saves its open project. It removes first, so that an update may put a file where the old version had a directory or the other way round, and deletes the directories a removal leaves empty inside the pack's directory (and packs, for a pack in its DefaultDir), never above it. It returns undo, which restores every file it changed, for when saving the project then fails. When ApplyFiles itself fails, it has already restored them.

func (*Change) NoOp

func (c *Change) NoOp() bool

NoOp reports whether applying c would change nothing: no file to write or remove, and the same project file.

type Entry

type Entry struct {
	// Name identifies the pack, as project.ValidatePackName accepts it; it is unique in the index and equals the name in the pack's manifest.
	Name string `yaml:"name" schema:"required"`
	// Kind is one of project.PackKinds and equals the manifest's.
	Kind string `yaml:"kind" schema:"required"`
	// PackVersion is the version the index offers, which equals the manifest's.
	PackVersion string `yaml:"packVersion" schema:"required"`
	// Description says in one line what the pack holds.
	Description string `yaml:"description" schema:"required"`
	// Tags are lower-case words a search also matches, such as 2d or tiles.
	Tags []string `yaml:"tags,omitempty,flow"`
	// License is the license of the pack's files, as an SPDX identifier such as CC0-1.0 or MIT.
	License string `yaml:"license" schema:"required"`
	// Authors name the people or organizations who made the pack (version 2).
	Authors []string `yaml:"authors,omitempty,flow"`
	// Homepage is an http or https URL of a page about the pack (version 2).
	Homepage string `yaml:"homepage,omitempty"`
	// Icon is an https URL of a square image that represents the pack (version 2).
	Icon string `yaml:"icon,omitempty"`
	// Screenshots are https URLs of images that show the pack (version 2).
	Screenshots []string `yaml:"screenshots,omitempty"`
	// Source is the directory holding the pack's pack.yaml: a slash-separated path relative to the index's directory that stays inside it, or an absolute https URL.
	Source string `yaml:"source" schema:"required"`
	// SHA256 is the pack's digest (Digest), 64 lower-case hexadecimal digits; a fetched pack whose digest differs is refused.
	SHA256 string `yaml:"sha256" schema:"required"`
	// Publisher is the ID of the publisher, listed under publishers, whose release key signed the entry (version 2). It is set together with certificate and signature, and all three are empty for an unsigned entry.
	Publisher string `yaml:"publisher,omitempty"`
	// Certificate is the base64 certificate in which the publisher's root certifies the release key that signed the entry, as game library keygen writes it (version 2).
	Certificate string `yaml:"certificate,omitempty"`
	// Signature is the base64 signature of the release key over the entry's publisher, name, kind, version and digest, as game library sign writes it (version 2). The display metadata (description, tags, license, authors, homepage, icon and screenshots) is not signed.
	Signature string `yaml:"signature,omitempty"`
	// Review is the entry's review tier, one of ReviewTiers (version 2). Only the official index's tier counts; Library.Review shows every other index's entries as community.
	Review string `yaml:"review,omitempty" schema:"enum=official|reviewed|community"`
}

Entry is one pack of a library.

type Index

type Index struct {
	// Version is the schema version: IndexMinVersion (1) or IndexVersion (2).
	Version int `yaml:"version" schema:"required"`
	// Publishers are the publishers whose root keys the signed entries are checked against, in the order the index lists them (version 2).
	Publishers []Publisher `yaml:"publishers,omitempty"`
	// Packs are the library's packs, in the order the index lists them.
	Packs []Entry `yaml:"packs,omitempty"`
	// Plugins are the Go plugins the library lists, in the order the index lists them (version 2). An entry holds a plugin's metadata only: its code stays in the author's Go module, which game plugin add fetches.
	Plugins []PluginEntry `yaml:"plugins,omitempty"`
}

Index is a library's versioned index file.

func ParseIndex

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

ParseIndex decodes a YAML index and validates it. Unknown fields and trailing YAML documents are refused.

func (*Index) Find

func (idx *Index) Find(name string) (Entry, bool)

Find returns the pack called name, or false.

func (*Index) FindPlugin

func (idx *Index) FindPlugin(name string) (PluginEntry, bool)

FindPlugin returns the plugin called name, or false.

func (*Index) FindPublisher

func (idx *Index) FindPublisher(id string) (*Publisher, bool)

FindPublisher returns the publisher with ID id, or false.

func (*Index) Search

func (idx *Index) Search(kind, query string) []Entry

Search returns the packs of kind, or of every kind when kind is empty, whose name, description or tags contain every word of query, ignoring case, sorted by name. An empty query matches every pack. SearchPlugins searches the plugins the same way.

func (*Index) SearchPlugins

func (idx *Index) SearchPlugins(query string) []PluginEntry

SearchPlugins returns the plugins whose name, module, description or tags contain every word of query, ignoring case, sorted by name. An empty query matches every plugin.

type Library

type Library struct {
	// Index is the library's parsed index.
	Index *Index
	// Location is where the index was read from: a URL, a file path, or the name of the index in an fs.FS.
	Location string
	// Client fetches http(s) indexes and packs; nil uses a client that gives up on a server that does not connect within 30 seconds or answer within a minute, and on any one file after 10 minutes.
	Client *http.Client
	// contains filtered or unexported fields
}

Library is an index together with where it was read from, so that its entries' relative sources resolve.

func Open

func Open(ctx context.Context, location string) (*Library, error)

Open reads the index at location: an http(s) URL of an index file, a local index file, or a local directory holding index.yaml. Plain http is accepted only for a loopback host, such as a test server's.

func OpenFS

func OpenFS(fsys fs.FS, name string) (*Library, error)

OpenFS reads the index called name in fsys, whose relative sources resolve from name's directory in fsys.

func (*Library) Fetch

func (l *Library) Fetch(ctx context.Context, name string) (*Pack, error)

Fetch fetches the pack called name from its source and checks it against its index entry: its digest, name, kind and version must all be the entry's.

func (*Library) Official

func (l *Library) Official() bool

Official reports whether l is the official library, the one DefaultIndex names, whose entries alone may be marked official or reviewed.

func (*Library) Remote

func (l *Library) Remote() bool

Remote reports whether fetching from l, or from any of its packs, may reach the network, so that a caller with a user interface fetches off its event loop.

func (*Library) Review

func (l *Library) Review(e Entry) string

Review returns the review tier e shows in l: its review field in the official library, and community everywhere else or when the field is empty.

func (*Library) RevokedDigest

func (l *Library) RevokedDigest(publisher, digest string) bool

RevokedDigest reports whether the revocation list of the publisher with ID publisher names digest, as Verify consults only the list of an entry's own publisher; an unknown publisher, or a list that does not verify, revokes nothing here, and Verify refuses the entries of a publisher whose list does not verify.

func (*Library) Verify

func (l *Library) Verify(name string, state *TrustState, requireSigned bool) (Verification, error)

Verify checks the entry called name: its certificate against its publisher's root, its signature against the release key the certificate names, and neither the key nor the entry's digest revoked by the publisher's list. An unsigned entry verifies, as Verification.Signed reports, unless requireSigned is set, when it is refused with ErrUnsigned. When state is not nil, a publisher's list older than one state saw before is refused with ErrStaleRevocations, and a newer one is recorded in state, even when the entry is then refused.

func (*Library) VerifyInProject

func (l *Library) VerifyInProject(projectDir string, f *project.File, name string) (Verification, error)

VerifyInProject verifies the entry called name for the project in projectDir, whose game.yaml is f: it refuses an unsigned entry when f.RequireSigned is set, and keeps the project's TrustState in TrustStateFile, writing it back when Verify saw a newer revocation list. f may be nil for a directory without a project, which requires nothing and remembers nothing.

type Manifest

type Manifest struct {
	// Version is the schema version; it must equal ManifestVersion (1).
	Version int `yaml:"version" schema:"required"`
	// Name identifies the pack, as project.ValidatePackName accepts it.
	Name string `yaml:"name" schema:"required"`
	// Kind is one of project.PackKinds.
	Kind string `yaml:"kind" schema:"required"`
	// PackVersion is the pack's own version, such as 1.2.0.
	PackVersion string `yaml:"packVersion" schema:"required"`
	// Description says in one line what the pack holds.
	Description string `yaml:"description" schema:"required"`
	// License is the license of the pack's files, as an SPDX identifier such as CC0-1.0.
	License string `yaml:"license" schema:"required"`
	// Into is the slash-separated project directory the pack's files are written to; empty is DefaultDir(Name).
	Into string `yaml:"into,omitempty"`
	// Files are the slash-separated paths of the pack's files relative to its directory, pack.yaml aside; no path may be another's directory.
	Files []string `yaml:"files,omitempty"`
	// Autoload lists the pack's files that installing it adds to game.yaml's autoload section; nil adds none.
	Autoload *Autoload `yaml:"autoload,omitempty"`
	// Plugins names the plugins from game.yaml's plugins: list that a plugin pack uses; a plugin pack names at least one, and the other kinds none.
	Plugins []string `yaml:"plugins,omitempty,flow"`
}

Manifest is a pack's versioned pack.yaml.

func ParseManifest

func ParseManifest(data []byte) (*Manifest, error)

ParseManifest decodes a YAML pack manifest and validates it. Unknown fields and trailing YAML documents are refused.

type Pack

type Pack struct {
	// Manifest is the parsed pack.yaml.
	Manifest *Manifest
	// Files maps each file's slash-separated path in the pack to its content, pack.yaml included.
	Files map[string][]byte
}

Pack is a pack read into memory: its manifest and the content of every file it holds.

func ReadPack

func ReadPack(fsys fs.FS, dir string) (*Pack, error)

ReadPack reads the pack whose directory is dir in fsys: its pack.yaml and every file the manifest lists. A file the manifest does not list is not part of the pack.

func (*Pack) Digest

func (p *Pack) Digest() string

Digest returns p's digest, as the package function Digest computes it from p.Files.

func (*Pack) Names

func (p *Pack) Names() []string

Names returns the paths of p's files, pack.yaml included, sorted.

type PluginEntry

type PluginEntry struct {
	// Name is the plugin's name, as manifest.ValidateName accepts it; it is unique among the index's plugins and equals the name in the plugin's plugin.yaml.
	Name string `yaml:"name" schema:"required"`
	// Module is the plugin's Go module path, which equals the module in its plugin.yaml; it is unique among the index's plugins.
	Module string `yaml:"module" schema:"required"`
	// Version is the latest version of the module the index offers, a semantic version without a leading v, such as 1.2.0; the version a project builds with stays the one its go.mod requires.
	Version string `yaml:"version" schema:"required"`
	// Engine is the semantic version constraint on github.com/nsgo-dev/game that the plugin's plugin.yaml states at Version, such as ">=0.4.0 <0.5.0".
	Engine string `yaml:"engine" schema:"required"`
	// Description says in one line what the plugin does.
	Description string `yaml:"description" schema:"required"`
	// Tags are lower-case words a search also matches, such as gameplay or editor.
	Tags []string `yaml:"tags,omitempty,flow"`
	// License is the plugin's license, as an SPDX expression such as MIT.
	License string `yaml:"license" schema:"required"`
	// Authors name the people or organizations who maintain the plugin.
	Authors []string `yaml:"authors,omitempty,flow"`
	// Homepage is an http or https URL of a page about the plugin.
	Homepage string `yaml:"homepage,omitempty"`
	// Icon is an https URL of a square image that represents the plugin.
	Icon string `yaml:"icon,omitempty"`
	// Screenshots are https URLs of images that show the plugin.
	Screenshots []string `yaml:"screenshots,omitempty"`
	// ManifestSHA256 is the SHA-256 of the plugin's plugin.yaml at Version, 64 lower-case hexadecimal digits, so a fetched module whose manifest differs is refused.
	ManifestSHA256 string `yaml:"manifestSHA256" schema:"required"`
}

PluginEntry is one Go plugin of a library (version 2): what a search shows of it, the module to fetch it from and the digest of the plugin.yaml that module must hold.

type Publisher

type Publisher struct {
	// ID names the publisher, as a pack name is written (project.ValidatePackName); it is unique in the index and entries name it in their publisher field.
	ID string `yaml:"id" schema:"required"`
	// Root is the publisher's root public key, PublicKeyPrefix followed by the base64 of the 32-byte Ed25519 key. Its secret half stays offline and only certifies release keys and signs revocation lists.
	Root string `yaml:"root" schema:"required"`
	// Revocations is the publisher's newest revocation list as game library revoke writes it: the base64 of a document its root signed, naming release keys and pack digests that must not install. Empty when the publisher has revoked nothing.
	Revocations string `yaml:"revocations,omitempty"`
}

Publisher is one publisher an index's signed entries name: the root key that certifies its release keys, and its newest revocation list.

func (*Publisher) RevocationList

func (p *Publisher) RevocationList() (*RevocationList, error)

RevocationList returns the publisher's revocation list once its root verifies it, or nil when it has none.

func (*Publisher) RootKey

func (p *Publisher) RootKey() (ed25519.PublicKey, error)

RootKey returns the publisher's root key.

type RevocationList

type RevocationList struct {
	// Publisher is the ID of the publisher whose root signed the list.
	Publisher string
	// Sequence orders a publisher's lists, counting from 1: a project refuses a list older than one it saw (ErrStaleRevocations).
	Sequence uint64
	// IssuedAt is when the list was signed.
	IssuedAt time.Time
	// Keys are the IDs of revoked release keys (KeyID), and Digests the SHA-256 digests of revoked packs, each sorted and unique.
	Keys, Digests []string
}

RevocationList is what a publisher's revocation list says.

type SeenRevocations

type SeenRevocations struct {
	// Root is the root's key ID (KeyID); a root is tracked by its key, not its publisher ID, which another index may give someone else.
	Root string `yaml:"root"`
	// Publisher is the ID the index gave the root's publisher when the list was seen, for people reading the file.
	Publisher string `yaml:"publisher"`
	// Sequence is the sequence number of the newest list seen.
	Sequence uint64 `yaml:"sequence"`
}

SeenRevocations is the newest revocation list a project saw of one publisher root.

type TrustState

type TrustState struct {
	// Version is the schema version; it must equal TrustStateVersion (1).
	Version int `yaml:"version"`
	// Revocations are the newest list seen of each root, sorted by root.
	Revocations []SeenRevocations `yaml:"revocations,omitempty"`
}

TrustState remembers, for a project, the newest revocation list it saw of each publisher root, so that an index serving an older list, or none, cannot undo a revocation (ErrStaleRevocations). Library.Verify updates it; VerifyInProject reads and writes it in TrustStateFile.

func NewTrustState

func NewTrustState() *TrustState

NewTrustState returns an empty state.

func ParseTrustState

func ParseTrustState(data []byte) (*TrustState, error)

ParseTrustState decodes a trust state file and validates it. Unknown fields and trailing YAML documents are refused.

func ReadTrustState

func ReadTrustState(projectDir string) (*TrustState, error)

ReadTrustState reads the trust state of the project in projectDir, or returns an empty one when the project has none.

type Verification

type Verification struct {
	// Signed reports whether the entry carries a signature, which then verified.
	Signed bool
	// Publisher is the ID of the publisher that signed the entry, empty when it is unsigned.
	Publisher string
	// ReleaseKey is the ID of the release key that signed the entry, empty when it is unsigned.
	ReleaseKey string
	// Review is the entry's review tier as Library.Review shows it.
	Review string
}

Verification is what Library.Verify found out about an entry.

Jump to

Keyboard shortcuts

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