Updater
Check, download, install — the updater minus the installer binary. The runtime registers it when the config has an updater section; an app with no update story carries no download-and-replace surface at all.
// crust.config.ts
updater: {
endpoint: "https://updates.jyz.land/notes.json",
pubkey: "…", // Ed25519 public key, base64; needed for any signature
allowFileUrl: false, // true permits a file: artifact — for a test, not for a shipped app
},
A test or a private transport passes its own adapter: createUpdaterPlugin(adapter, options). updater.config answers what the app pinned — { endpoint, pubkey, autoCheck, allowFileUrl } — so a page can tell which of the three refusals below would apply before it calls anything.
check
const result = await window.crust.invoke("updater", "check", {
endpoint: "https://updates.jyz.land/notes.json",
currentVersion: "1.4.0",
});
// { available: true, version: "1.5.0", url: "https://…/Notes.app.zip", notes: "…", sha256: "…" }
The endpoint answers one JSON object:
{ "version": "1.5.0", "url": "https://…/Notes.app.zip", "notes": "…", "sha256": "…" }
version and url are required; notes stays unparsed Markdown, and sha256 is 64 hex characters. Versions compare numerically, so 0.10.0 beats 0.9.0 and 1.0.0 beats 1.0.0-beta.1.
The endpoint obeys the same scheme rule as download's url: https only, and file: only when the app set updater.allowFileUrl. A page-supplied http: endpoint is refused as invalid-arguments naming check — crust: updater.check refuses a http: url: only https is fetched — with requires: "updater.allowFileUrl" for a file: one. The refusal travels in error, so check still never rejects.
A manifest that names a pubkey other than the pinned one is bad-manifest — the manifest's pubkey is not this app's — so a hostile endpoint cannot substitute its own key.
check never rejects: no update is { available: false, version }, and a failure is { available: false, error: { code, message } }.
download
const file = await window.crust.invoke("updater", "download", {
url: "https://…/Notes.app.zip",
sha256: "…",
});
// { ok: true, path: "…/crust-update-…/Notes.app.zip", bytes: 8_412_331, sha256: "…" }
path is inside a fresh temp directory the plugin made; the file name is the URL's last segment, reduced to [A-Za-z0-9._-]. The answer always carries the digest that was computed, and signer when a signature verified.
sha256 is required
An artifact nothing verified is not an artifact, so a download without a digest is refused:
crust: updater.download requires sha256, because an artifact nothing verified is no artifact
The failure carries requires: "sha256". A mismatch is hash-mismatch, naming the digest that was actually computed.
Only https, and file: by opt-in
refuses a http: url: only https is fetched
refuses a file url: only https is fetched unless updater.allowFileUrl is true
The second carries requires: "updater.allowFileUrl". file: exists for a test that serves a local artifact; a shipped app leaves it off, so a page cannot point the updater at a path on disk.
Both check and download follow up to five https redirects, because https://github.com/<owner>/<repo>/releases/latest/download/<asset> answers 302 to its object store. Every hop is checked and a hop to http: is refused with only https is followed, so the scheme rule covers the bytes actually fetched, not just the URL handed in. The security boundary is the pinned updater.pubkey over the artifact bytes rather than the host: a redirect changes where bytes come from, and the signature still decides whether they are the update.
A signature needs a pinned key
const signed = await window.crust.invoke("updater", "download", {
url: "https://…/Notes.app.zip",
sha256: "…",
signature: "…", // base64 Ed25519 over the artifact bytes
});
// { ok: true, sha256: "…", signer: "…" }
The key comes from updater.pubkey in the config and nowhere else — a pubkey a page ships is never used, so a page cannot verify its own artifact with its own key:
crust: updater.download requires updater.pubkey in crust.config.ts to verify a signature, and this app pins none, got …
A page-supplied pubkey that differs from the pinned one is refuses a pubkey that is not this app's, and bytes that do not match the signature are signature-mismatch. When the app pins updater.pubkey, a download with no signature is refused before any fetch with requires: "signature": the manifest's sha256 is not enough, because a server that answers both halves chooses both.
install
const done = await window.crust.invoke("updater", "install", {
path: "/var/folders/…/Notes.app",
appPath: "/Applications/Notes.app",
});
// { ok: true, appPath: "/Applications/Notes.app", backup: "/Applications/Notes.app.old" }
install — and relaunch below — rename a macOS .app and launch it with open -n. On Linux and Windows they refuse before touching disk with { ok: false, code: "unsupported-platform", message } naming the platform: crust: updater.install: auto-update replaces a macOS .app bundle and relaunches with open -n; platform linux has no install path, so this update cannot be applied. check and download work on every platform; only the two bundle commands are macOS-only.
Install takes only an artifact this same run downloaded and verified. The plugin keeps a receipt per path, and a path it never verified is refused rather than trusted:
crust: updater.install refuses …: no updater.download verified it in this run, so nothing proves these bytes are the update the app fetched
That is unverified-artifact. A verified artifact that changed afterwards is re-hashed before the swap and refused if the digest moved:
crust: updater.install: … changed since download — sha256 <actual>, verified <expected>
That is hash-mismatch. adapter.sha256 digests a directory as a tree, so a .app artifact's bytes are verifiable the same way a zip's are — but a signature over that tree is a separate problem, and the next section is about it.
Both paths must already be .app directories — an archive is not extracted here. The new bundle is renamed over the old one, and the old one is parked at <appPath>.old, which is replaced on the next install. One rename on one volume is atomic; a cross-volume move fails rather than degrading into a copy that is no longer atomic.
Nothing runs codesign: the signature belongs to whoever shipped the artifact.
Check ok to know whether the app came back. relaunch: true that fails answers { ok: false, code: "relaunch-failed", installed: true, appPath, backup } — the new bundle is installed but not running, and no rollback is attempted. A forward rename followed by a failed restore is rollback-failed with parkedAt: <backup>, naming the only copy of the old app.
One limitation: a bundle cannot carry a signature
updater.download records one artifact, and a signature is verified over that artifact's bytes. That splits the two artifact shapes cleanly, and the split is a design fact rather than a bug waiting on a patch:
| artifact | sha256 | Ed25519 signature |
|---|---|---|
| a file — zip, dmg, tarball | verifies over its bytes | verifies over the same bytes |
a .app bundle — a tree | verifies over the tree digest | not expressed by this contract |
A tree has no single byte sequence to sign, so there is nothing for download to hand the verifier. adapter.sha256 copes with a directory; the signature path does not, and pretending otherwise would be a check that always passes.
The shipped node adapter writes one file, so a bundle also needs an adapter whose download produces the tree — the parity probe's does exactly that, by copying the directory into the temp dir.
What an author should ship. A signed archive. Verify the signature over the archive — your own step, or as the file artifact download produces — extract it, and make the extracted .app the artifact download produced. install still demands a receipt from this run, so a bundle that appeared by any other route is refused, which is the point: the extraction has to be inside the download the plugin verified.
What the probe proves, and what it does not. bun run e2e:parity prints:
updater signed=true swapped=true unverified=refused
A signed file verified with the pinned key, the verified tree swapped, and a bundle no download had verified refused. It does not prove a signed bundle, because a signed bundle is the limitation.
relaunch
await window.crust.invoke("updater", "relaunch", { appPath: "/Applications/Notes.app" });
relaunch — and an install with relaunch: true — only touches this app's own bundle, resolved from process.execPath. Anything else is refused:
crust: updater.relaunch: … is not this app's bundle; relaunch only starts /Applications/Notes.app
A dev run has no bundle to be its own, so it refuses instead of guessing:
crust: updater.relaunch: refuses …: cannot tell which bundle is its own, because …/bun is not inside an .app
Both are not-an-app-bundle. The comparison is on realpath, so a symlink to the own bundle is accepted and a symlink pointing elsewhere is refused.
Still usable
The hardening does not close the update path. A pinned updater.pubkey, a download with sha256 over https, and an install of the path that download returned is the whole flow, and it works: the swap lands, the old bundle is parked at .old, and relaunch: true starts the new one. The signed variant is a file artifact — an archive you extract inside the download — for the reason in the section above.
Failure codes
| code | when |
|---|---|
invalid-arguments | a required string is missing, sha256 is not 64 hex, or url is not https |
check-failed | the manifest request answered non-2xx, or the fetch threw |
bad-manifest | the JSON is not an object, a field has the wrong shape, or its pubkey is not the pinned one |
download-failed | the artifact request answered non-2xx, or the write threw |
hash-mismatch | the computed digest differs — at download, or after the artifact changed |
signature-mismatch | the bytes do not match the manifest signature |
unverified-artifact | install was handed a path this run never verified |
install-failed | the rename failed, including a cross-volume move |
rollback-failed | the forward rename failed and restoring the old bundle failed too; parkedAt names its copy |
not-an-app-bundle | a path is not an existing .app, or is not this app's own bundle |
unsupported-platform | install or relaunch on Linux or Windows — no macOS .app install path |
relaunch-failed | the swap landed (installed: true) but the launcher still refused |
handler-error | an adapter threw something it could not name |
check reports the first three inside error; download and install answer { ok: false, code, message, path?, requires? }. requires names the argument or config key that would have let the call through — sha256, signature, updater.pubkey, updater.allowFileUrl — so a UI can point at the fix rather than the symptom.