@shipvo/capacitor
v0.0.4
Published
Signed over-the-air updates for Capacitor web bundles: the same release decisions and trust model as the Shipvo React Native runtime.
Downloads
1,010
Maintainers
Readme
@shipvo/capacitor
Signed over-the-air updates for the web bundle of a Capacitor app. It makes the same release decisions and keeps the same trust model as @shipvo/runtime (see docs/adapters.md).
The core is TypeScript and makes every decision: it verifies the signature and the hash, stages, promotes and rolls back. The native layer only stores bytes and switches the web view.
| Platform | Native layer |
|---|---|
| Android | android/: stores the verified bundle zip in app-private files and the state in SharedPreferences; switches the web view with Bridge.setServerBasePath to the unpacked bundle |
| iOS | Next slice, tracked in its own issue. It will use the same JavaScript core and the same boot and bootAndServe calls as Android. |
Android
android/ is a Capacitor plugin named Shipvo. It backs KeyValueStore with SharedPreferences and BundleFiles with the app-private files directory, and points the web view at the staged bundle. A web bundle is a zip of your web assets with an index.html at its root.
- Register it in
MainActivitywithregisterPlugin(ShipvoPlugin.class)beforesuper.onCreate. - Include the module in
settings.gradleand addimplementation project(':shipvo-capacitor')(seeapps/capacitor-sample/android). - When the page loads, call
bootAndServe. It runsboot()(rollback included) and tells native to serve the chosen file. Native checks the sha-256 the core verified once more before it unpacks, and refuses zip entries that leave the directory.
import { registerPlugin } from "@capacitor/core";
import { ShipvoCapacitor, NativeStore, NativeFiles, bootAndServe, bootAndSwitch } from "@shipvo/capacitor";
import type { ShipvoNativePlugin } from "@shipvo/capacitor";
const native = registerPlugin<ShipvoNativePlugin>("Shipvo");
const shipvo: ShipvoCapacitor = new ShipvoCapacitor({
appId: "tide", shellMajor: 1, shellVersion: "1.2.0", platform: "android",
publicKey: "<base64 Ed25519 key>", baseUrl: "https://cp.example.com",
store: new NativeStore(native), files: new NativeFiles(native),
onReload: async () => { await bootAndSwitch(shipvo, native); },
});
await bootAndServe(shipvo, native);
await shipvo.markHealthy();Each launch starts on the embedded bundle, then bootAndServe switches to the pending or current release. The page of a served bundle runs the same code; it resumes the release boot() already chose and does not count another trial boot.
Tests: pnpm --filter @shipvo/capacitor test runs the stage, apply, crash and rollback sequence through the native bridge. The plugin's JVM tests run with ./gradlew :shipvo-capacitor:testDebugUnitTest in apps/capacitor-sample/android (after pnpm --filter capacitor-sample sync).
Install
npm install @shipvo/capacitorExample
import { ShipvoCapacitor, MemoryStore, MemoryFiles } from "@shipvo/capacitor";
const shipvo = new ShipvoCapacitor({
appId: "tide", shellMajor: 1, shellVersion: "1.2.0", platform: "android",
publicKey: "<base64 Ed25519 key baked into the shell>",
baseUrl: "https://cp.example.com",
store: new MemoryStore(), files: new MemoryFiles(), // Android: NativeStore and NativeFiles
});
const { release, file } = await shipvo.boot(); // which bundle to serve
const r = await shipvo.checkForUpdate({ apply: false });
if (r.status === "staged") console.log("staged release", r.release);
await shipvo.markHealthy(); // promotes a pending release that is running
console.log((await shipvo.consumeEvents()).events);How a web bundle is described
The signed release pointer has kind: "web" (new, optional field in @shipvo/schema). core is the one archive file: url, size and sha256. This package refuses a pointer without kind: "web", so a React Native pointer cannot be replayed into a web shell.
API
ShipvoCapacitor implements ShipvoCapacitorPlugin, the same methods as Native in packages/runtime/src/index.ts, all async:
| Method | What it does |
|---|---|
| getState() | Cohort, band, running, current, pending, previous and blocked release |
| checkForUpdate({ apply }) | Fetch the pointer, verify, download, verify, stage. apply: true then calls onReload |
| markHealthy() | Promotes the pending release if it is the one running |
| consumeEvents() | Returns and clears queued events: applied, rolled_back, crash_loop_revert, verify_failed, download_failed, pointer_rejected:<why> |
| rollback() | Drops pending, blocks current, goes back to previous |
| reload() | Calls onReload |
| boot() | Native layer only. Picks pending (3 trial boots), else current, else the embedded bundle (release 0). Applies the crash-loop window and the new-shell reset |
| markStable() | Native layer only. Clears the boot counter after the app stayed up |
Checks, in order: Ed25519 signature of the exact body bytes (WebCrypto), kind, platform, app and major, band, newer than current/pending/blocked, min_shell_version, then size and sha-256 of the bundle. A bad signature or hash is never staged. A hash mismatch also blocks that release.
Not shared yet: bsdiff patches (rule 9) and Hermes bytecode (rule 6, not relevant to plain web assets). Needs Node 20+ or a web view with WebCrypto Ed25519.
