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.
function checkDistArtifact(
data: Uint8Array,
artifact: Pick<DistArtifact, 'name' | 'sha256' | 'size'>,
): voidParameters
| Name | Type | Description |
|---|---|---|
| data | Uint8Array | The downloaded file. |
| artifact | Pick<DistArtifact, 'name' | 'sha256' | 'size'> | Its entry in a verified manifest. |
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").
function compareVersions(a: string, b: string): -1 | 0 | 1Parameters
| Name | Type | Description |
|---|---|---|
| a | string | A version (a leading |
| b | string | Another one. |
Returns
-1 | 0 | 1distBaseUrlFunction#
The feed's base URL: ZIDANE_DIST_URL when set, else DIST_BASE_URL; no trailing slash.
function distBaseUrl(env?: Record<string, string | undefined>): stringParameters
| Name | Type | Default | Description |
|---|---|---|---|
| env? | Record<string, string | undefined> | process.env | Environment to read (default |
Returns
stringdistManifestUrlFunction#
The manifest URL: the newest release's, or version's (while the feed still keeps it).
function distManifestUrl(baseUrl: string, version?: string): stringParameters
| Name | Type | Description |
|---|---|---|
| baseUrl | string | The feed's base URL. |
| version? | string | A release to pin (with or without |
Returns
stringdistPublicKeyFunction#
The public key clients trust: ZIDANE_DIST_PUBLIC_KEY when set, else DIST_PUBLIC_KEY.
function distPublicKey(env?: Record<string, string | undefined>): stringParameters
| Name | Type | Default | Description |
|---|---|---|---|
| env? | Record<string, string | undefined> | process.env | Environment to read (default |
Returns
stringdistTargetFunction#
The feed's names for this host's OS and CPU, or null when the feed has no build for it.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| platform? | string | process.platform | A |
| arch? | string | process.arch | A |
fetchDistManifestFunction#
Downloads and verifies a manifest: the newest release's, or version's.
A pinned version must be the one the manifest names.
function fetchDistManifest(
options?: { baseUrl?: string; fetch?: (url: string, init?: RequestInit) => Promise<Response>; publicKey?: string; timeoutMs?: number; version?: string },
): Promise<DistManifest>Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| 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 |
Returns
Promise<DistManifest>findDistArtifactFunction#
The artifact of kind for os / arch (default: this host), or undefined.
function findDistArtifact(
manifest: DistManifest,
kind: DistArtifactKind,
target?: { arch: DistArch; os: DistOs } | null,
): DistArtifact | undefinedParameters
| Name | Type | Description |
|---|---|---|
| manifest | DistManifest | A verified manifest. |
| kind | DistArtifactKind | What to install. |
| target? | { arch: DistArch; os: DistOs } | null | OS and CPU (default: this host's; |
Returns
DistArtifact | undefinedparseDistManifestFunction#
Parses and validates a manifest's JSON (no signature check: see verifyDistManifest).
function parseDistManifest(text: string): DistManifestParameters
| Name | Type | Description |
|---|---|---|
| text | string | The manifest's JSON. |
Returns
parseMinisignPublicKeyFunction#
Parses a public key file (minisign.pub) or its bare base64 line.
function parseMinisignPublicKey(text: string): MinisignPublicKeyParameters
| Name | Type | Description |
|---|---|---|
| text | string | The file's contents, or its base64 line. |
Returns
sha256HexFunction#
Lower-case hex SHA-256 of data.
function sha256Hex(data: Uint8Array): stringParameters
| Name | Type | Description |
|---|---|---|
| data | Uint8Array | Bytes to hash. |
Returns
stringverifyDistManifestFunction#
Checks json against its minisign signature file, then parses it. Throws a DistVerificationError when either fails.
function verifyDistManifest(
json: string | Uint8Array<ArrayBufferLike>,
signature: string,
publicKey?: string,
): DistManifestParameters
| Name | Type | Description |
|---|---|---|
| json | string | Uint8Array<ArrayBufferLike> | The manifest's bytes, exactly as served. |
| signature | string | Its |
| publicKey? | string | The trusted key (default |
Returns
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.
function verifyMinisign(
message: Uint8Array,
signatureFile: string,
publicKey: string | MinisignPublicKey,
): { trustedComment: string }Parameters
| Name | Type | Description |
|---|---|---|
| message | Uint8Array | The signed file's bytes. |
| signatureFile | string | The |
| publicKey | string | MinisignPublicKey | The trusted key. |
Returns
{ trustedComment: string }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.
class DistVerificationError extends ErrorConstructor
new DistVerificationError(message: string, options?: ErrorOptions)Creates the error.
Parameters
| Name | Type | Description |
|---|---|---|
| message | string | What did not check out. |
| options? | ErrorOptions | Optional |
Returns
Properties
| Name | Type | Default | Description |
|---|---|---|---|
| name | string | 'DistVerificationError' | Always |
Constants#
DIST_BASE_URLConstant#
Where the feed lives. ZIDANE_DIST_URL overrides it (a mirror, a test server).
const DIST_BASE_URL = 'https://zidane.si/dl'DIST_IMAGE_PATTERNConstant#
What DistManifest.image looks like: a repository pinned by digest.
const DIST_IMAGE_PATTERN: RegExpDIST_LATEST_FILEConstant#
The newest release's manifest, at the feed's root.
const DIST_LATEST_FILE = 'latest.json'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).
const DIST_PUBLIC_KEY = 'RWTeH2EIT+uzHQnG7U5bcHFzskL0m++wKuc3U5zEom2+tRn/8UukIDGk'DIST_RELEASE_FILEConstant#
A release's manifest, inside its v<version>/ folder.
const DIST_RELEASE_FILE = 'manifest.json'Interfaces#
DistArtifactInterface#
One downloadable file of a release.
interface DistArtifactProperties
| Name | Type | Description |
|---|---|---|
| arch | DistArch | CPU architecture it runs on. |
| kind | DistArtifactKind | What it is (a client looks for the kind it installs). |
| name | string | File name inside the release folder. |
| os | DistOs | Operating system it runs on. |
| sha256 | string | Lower-case hex SHA-256 of the file. |
| size | number | Size in bytes. |
| url | string | Absolute download URL. |
DistFileInterface#
A file of a release that runs nowhere (its notes).
interface DistFileProperties
| Name | Type | Description |
|---|---|---|
| name | string | File name inside the release folder. |
| sha256 | string | Lower-case hex SHA-256 of the file. |
| size | number | Size in bytes. |
| url | string | Absolute download URL. |
DistManifestInterface#
The signed manifest of one release.
interface DistManifestProperties
| Name | Type | Description |
|---|---|---|
| artifacts | DistArtifact[] | Every artifact of the release. |
| date | string | When the release was published (ISO 8601). |
| image? | string | The zidane-server image of this release, pinned by digest ( |
| notes? | DistFile | The release notes ( |
| version | string | Release version, without a leading |
MinisignPublicKeyInterface#
A minisign public key.
interface MinisignPublicKeyProperties
| Name | Type | Description |
|---|---|---|
| keyId | Uint8Array | The 8-byte key id a signature names. |
| publicKey | Uint8Array | The raw Ed25519 public key (32 bytes). |
Types#
DistArchType#
A CPU architecture the feed ships for.
type DistArch = 'arm64' | 'x64'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.
type DistArtifactKind =
| 'tui'
| 'server'
| 'desktop-dmg'
| 'desktop-zip'
| 'desktop-appimage'
| 'desktop-deb'DistOsType#
An operating system the feed ships for.
type DistOs = 'darwin' | 'linux'