Skip to content

zidane/dist-feed

import { … } from 'zidane/dist-feed'src/dist/manifest.ts

Functions#

checkDistArtifactFunction#

Throws a DistVerificationError unless data has the artifact's size and SHA-256.

TypeScript
function checkDistArtifact(
  data: Uint8Array,
  artifact: Pick<DistArtifact, 'name' | 'sha256' | 'size'>,
): void
Parameters
NameTypeDescription
dataUint8Array

The downloaded file.

artifactPick<DistArtifact, 'name' | 'sha256' | 'size'>

Its entry in a verified manifest.

src/dist/manifest.ts:290

compareVersionsFunction#

Semver order of two versions (-1, 0, 1): a release is newer than its prereleases, numeric prerelease parts compare as numbers. Unparseable versions compare equal (never "newer").

TypeScript
function compareVersions(a: string, b: string): -1 | 0 | 1
Parameters
NameTypeDescription
astring

A version (a leading v is ignored).

bstring

Another one.

-1 | 0 | 1

src/dist/manifest.ts:311

distBaseUrlFunction#

The feed's base URL: ZIDANE_DIST_URL when set, else DIST_BASE_URL; no trailing slash.

TypeScript
function distBaseUrl(env?: Record<string, string | undefined>): string
Parameters
NameTypeDefaultDescription
env?Record<string, string | undefined>process.env

Environment to read (default process.env).

string

src/dist/manifest.ts:100

distManifestUrlFunction#

The manifest URL: the newest release's, or version's (while the feed still keeps it).

TypeScript
function distManifestUrl(baseUrl: string, version?: string): string
Parameters
NameTypeDescription
baseUrlstring

The feed's base URL.

version?string

A release to pin (with or without v); omitted: latest.json.

string

src/dist/manifest.ts:119

distPublicKeyFunction#

The public key clients trust: ZIDANE_DIST_PUBLIC_KEY when set, else DIST_PUBLIC_KEY.

TypeScript
function distPublicKey(env?: Record<string, string | undefined>): string
Parameters
NameTypeDefaultDescription
env?Record<string, string | undefined>process.env

Environment to read (default process.env).

string

src/dist/manifest.ts:109

distTargetFunction#

The feed's names for this host's OS and CPU, or null when the feed has no build for it.

TypeScript
function distTarget(
  platform?: string,
  arch?: string,
): { arch: DistArch; os: DistOs } | null
Parameters
NameTypeDefaultDescription
platform?stringprocess.platform

A process.platform value (default: this host's).

arch?stringprocess.arch

A process.arch value (default: this host's).

{ arch: DistArch; os: DistOs } | null

src/dist/manifest.ts:130

fetchDistManifestFunction#

Downloads and verifies a manifest: the newest release's, or version's. A pinned version must be the one the manifest names.

TypeScript
function fetchDistManifest(
  options?: { baseUrl?: string; fetch?: (url: string, init?: RequestInit) => Promise<Response>; publicKey?: string; timeoutMs?: number; version?: string },
): Promise<DistManifest>
Parameters
NameTypeDefaultDescription
options?{ baseUrl?: string; fetch?: (url: string, init?: RequestInit) => Promise<Response>; publicKey?: string; timeoutMs?: number; version?: string }{}

The release to pin, the feed, the key, the fetch and the timeout (all optional).

Promise<DistManifest>

src/dist/manifest.ts:228

findDistArtifactFunction#

The artifact of kind for os / arch (default: this host), or undefined.

TypeScript
function findDistArtifact(
  manifest: DistManifest,
  kind: DistArtifactKind,
  target?: { arch: DistArch; os: DistOs } | null,
): DistArtifact | undefined
Parameters
NameTypeDescription
manifestDistManifest

A verified manifest.

kindDistArtifactKind

What to install.

target?{ arch: DistArch; os: DistOs } | null

OS and CPU (default: this host's; null finds nothing).

DistArtifact | undefined

src/dist/manifest.ts:271

parseDistManifestFunction#

Parses and validates a manifest's JSON (no signature check: see verifyDistManifest).

TypeScript
function parseDistManifest(text: string): DistManifest
Parameters
NameTypeDescription
textstring

The manifest's JSON.

src/dist/manifest.ts:165

parseMinisignPublicKeyFunction#

Parses a public key file (minisign.pub) or its bare base64 line.

TypeScript
function parseMinisignPublicKey(text: string): MinisignPublicKey
Parameters
NameTypeDescription
textstring

The file's contents, or its base64 line.

src/dist/minisign.ts:88

sha256HexFunction#

Lower-case hex SHA-256 of data.

TypeScript
function sha256Hex(data: Uint8Array): string
Parameters
NameTypeDescription
dataUint8Array

Bytes to hash.

string

src/dist/manifest.ts:280

verifyDistManifestFunction#

Checks json against its minisign signature file, then parses it. Throws a DistVerificationError when either fails.

TypeScript
function verifyDistManifest(
  json: string | Uint8Array<ArrayBufferLike>,
  signature: string,
  publicKey?: string,
): DistManifest
Parameters
NameTypeDescription
jsonstring | Uint8Array<ArrayBufferLike>

The manifest's bytes, exactly as served.

signaturestring

Its .minisig file.

publicKey?string

The trusted key (default distPublicKey).

src/dist/manifest.ts:211

verifyMinisignFunction#

Checks a minisign signature file against message and publicKey (a minisign.pub file, its base64 line, or a parsed key): the key id, the signature of the prehashed message, then the trusted comment's signature. Returns the trusted comment; throws on any mismatch.

TypeScript
function verifyMinisign(
  message: Uint8Array,
  signatureFile: string,
  publicKey: string | MinisignPublicKey,
): { trustedComment: string }
Parameters
NameTypeDescription
messageUint8Array

The signed file's bytes.

signatureFilestring

The .minisig file's contents.

publicKeystring | MinisignPublicKey

The trusted key.

{ trustedComment: string }

src/dist/minisign.ts:118

Classes#

DistVerificationErrorClass#

A manifest or artifact that does not check out: a bad or missing signature, a malformed manifest, another release than asked for, a wrong checksum or size. Not a network failure: something served is not what was signed.

TypeScript
class DistVerificationError extends Error
TypeScript
new DistVerificationError(message: string, options?: ErrorOptions)

Creates the error.

Parameters
NameTypeDescription
messagestring

What did not check out.

options?ErrorOptions

Optional cause.

DistVerificationError properties
NameTypeDefaultDescription
namestring'DistVerificationError'

Always 'DistVerificationError'.

src/dist/manifest.ts:141

Constants#

DIST_BASE_URLConstant#

Where the feed lives. ZIDANE_DIST_URL overrides it (a mirror, a test server).

TypeScript
const DIST_BASE_URL = 'https://zidane.si/dl'

src/dist/manifest.ts:22

DIST_IMAGE_PATTERNConstant#

What DistManifest.image looks like: a repository pinned by digest.

TypeScript
const DIST_IMAGE_PATTERN: RegExp

src/dist/manifest.ts:93

DIST_LATEST_FILEConstant#

The newest release's manifest, at the feed's root.

TypeScript
const DIST_LATEST_FILE = 'latest.json'

src/dist/manifest.ts:32

DIST_PUBLIC_KEYConstant#

The minisign public key that signs the feed (src/dist/minisign.pub). Check by hand: minisign -Vm latest.json -P <this>. ZIDANE_DIST_PUBLIC_KEY overrides it (a test feed).

TypeScript
const DIST_PUBLIC_KEY = 'RWTeH2EIT+uzHQnG7U5bcHFzskL0m++wKuc3U5zEom2+tRn/8UukIDGk'

src/dist/manifest.ts:29

DIST_RELEASE_FILEConstant#

A release's manifest, inside its v<version>/ folder.

TypeScript
const DIST_RELEASE_FILE = 'manifest.json'

src/dist/manifest.ts:34

Interfaces#

DistArtifactInterface#

One downloadable file of a release.

TypeScript
interface DistArtifact
DistArtifact properties
NameTypeDescription
archDistArch

CPU architecture it runs on.

kindDistArtifactKind

What it is (a client looks for the kind it installs).

namestring

File name inside the release folder.

osDistOs

Operating system it runs on.

sha256string

Lower-case hex SHA-256 of the file.

sizenumber

Size in bytes.

urlstring

Absolute download URL.

src/dist/manifest.ts:49

DistFileInterface#

A file of a release that runs nowhere (its notes).

TypeScript
interface DistFile
DistFile properties
NameTypeDescription
namestring

File name inside the release folder.

sha256string

Lower-case hex SHA-256 of the file.

sizenumber

Size in bytes.

urlstring

Absolute download URL.

src/dist/manifest.ts:67

DistManifestInterface#

The signed manifest of one release.

TypeScript
interface DistManifest
DistManifest properties
NameTypeDescription
artifactsDistArtifact[]

Every artifact of the release.

datestring

When the release was published (ISO 8601).

image?string

The zidane-server image of this release, pinned by digest (ghcr.io/<owner>/zidane-server@sha256:<hex>), when the release pushed one.

notes?DistFile

The release notes (NOTES.md, Markdown: this release's and the one before), when the release wrote them.

versionstring

Release version, without a leading v.

src/dist/manifest.ts:79

MinisignPublicKeyInterface#

A minisign public key.

TypeScript
interface MinisignPublicKey
MinisignPublicKey properties
NameTypeDescription
keyIdUint8Array

The 8-byte key id a signature names.

publicKeyUint8Array

The raw Ed25519 public key (32 bytes).

src/dist/minisign.ts:37

Types#

DistArchType#

A CPU architecture the feed ships for.

TypeScript
type DistArch = 'arm64' | 'x64'

src/dist/manifest.ts:41

DistArtifactKindType#

What an artifact is: the TUI binary archive, the server binary archive, or one of the desktop app's packages. Clients skip kinds they do not know.

TypeScript
type DistArtifactKind =
  | 'tui'
  | 'server'
  | 'desktop-dmg'
  | 'desktop-zip'
  | 'desktop-appimage'
  | 'desktop-deb'

src/dist/manifest.ts:46

DistOsType#

An operating system the feed ships for.

TypeScript
type DistOs = 'darwin' | 'linux'

src/dist/manifest.ts:39