@bitkyc08/opencodex 2.99.0 → 2.100.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS_INSTALL.md +19 -1
- package/README.md +37 -33
- package/SPONSORS.md +5 -1
- package/bin/ocx.mjs +1 -1
- package/gui/dist/assets/{App-C1hGwaN1.css → App-COo8Yopd.css} +1 -1
- package/gui/dist/assets/App-g3Cm2xhZ.js +59 -0
- package/gui/dist/assets/Tray-BMDkAiXy.js +1 -0
- package/gui/dist/assets/brand-mark-nr3ziR-T.js +1 -0
- package/gui/dist/assets/index-Bziu8gTy.css +2 -0
- package/gui/dist/assets/index-OYzhQUNP.js +94 -0
- package/gui/dist/assets/{segment-thumb-features-fYEMxBaW.js → segment-thumb-features-DKCVUUTi.js} +1 -1
- package/gui/dist/classic/assets/App-CgPBKUP-.js +58 -0
- package/gui/dist/classic/assets/{Tray-BqZueZOx.js → Tray-BedmOsE7.js} +1 -1
- package/gui/dist/classic/assets/index-BR-HhNrp.js +94 -0
- package/gui/dist/classic/assets/quota-summary-CXKhvSmQ.js +1 -0
- package/gui/dist/classic/index.html +1 -1
- package/gui/dist/index.html +2 -2
- package/native/ocx-child/Cargo.lock +215 -0
- package/native/ocx-child/Cargo.toml +31 -0
- package/native/ocx-child/src/cli.rs +1901 -0
- package/native/ocx-child/src/codex_home.rs +429 -0
- package/native/ocx-child/src/codex_settings.rs +231 -0
- package/native/ocx-child/src/daemon.rs +363 -0
- package/native/ocx-child/src/http_wire.rs +619 -0
- package/native/ocx-child/src/journal.rs +977 -0
- package/native/ocx-child/src/lib.rs +22 -0
- package/native/ocx-child/src/main.rs +9 -0
- package/native/ocx-child/src/parity.rs +102 -0
- package/native/ocx-child/src/platform.rs +1487 -0
- package/native/ocx-child/src/relay.rs +1288 -0
- package/native/ocx-child/src/relay_auth.rs +166 -0
- package/native/ocx-child/src/routes.rs +236 -0
- package/native/ocx-child/src/state.rs +190 -0
- package/native/ocx-child/src/test_hooks.rs +58 -0
- package/native/ocx-child/src/toml_surgeon.rs +1156 -0
- package/package.json +8 -2
- package/src/adapters/anthropic-image-normalize.ts +1 -1
- package/src/adapters/anthropic.ts +28 -2
- package/src/adapters/claude-cli/adapter.ts +5 -25
- package/src/adapters/claude-cli/instruction-images.ts +31 -0
- package/src/adapters/claude-cli/stable-replay.ts +42 -14
- package/src/adapters/claude-cli/usage-admission.ts +53 -64
- package/src/adapters/client-fingerprint.ts +1 -1
- package/src/adapters/coding-agent/protocol.ts +1 -1
- package/src/adapters/devin/live-models.ts +3 -0
- package/src/adapters/google-http.ts +3 -0
- package/src/adapters/google-vertex-key-project.ts +10 -2
- package/src/adapters/google.ts +40 -8
- package/src/adapters/kiro/usage.ts +3 -13
- package/src/adapters/openai-chat/mistral-image-limit.ts +28 -15
- package/src/adapters/openai-chat-images.ts +100 -0
- package/src/adapters/openai-chat.ts +6 -9
- package/src/adapters/openai-responses/passthrough.ts +5 -2
- package/src/adapters/openai-responses/request-strips.ts +32 -0
- package/src/adapters/openai-responses/tool-schema.ts +9 -4
- package/src/chat/inbound.ts +1 -1
- package/src/claude/auth-detect.ts +26 -8
- package/src/claude/inbound-content-options.ts +18 -3
- package/src/claude/inbound.ts +5 -2
- package/src/cli/bundled-bun-diagnostic.ts +91 -0
- package/src/cli/capabilities-agents-routing.ts +2 -2
- package/src/cli/capabilities-observe-system.ts +60 -0
- package/src/cli/combo-input.ts +6 -0
- package/src/cli/combo-result.ts +1 -1
- package/src/cli/combo.ts +4 -0
- package/src/cli/config-command.ts +16 -2
- package/src/cli/connect.ts +12 -10
- package/src/cli/dispatch.ts +4 -0
- package/src/cli/doctor.ts +11 -0
- package/src/cli/help.ts +1 -0
- package/src/cli/init.ts +4 -0
- package/src/cli/link-enrollment.ts +152 -25
- package/src/cli/link-local-control.ts +49 -0
- package/src/cli/link.ts +37 -10
- package/src/cli/provider-lifecycle-runtime.ts +4 -2
- package/src/cli/registry.ts +13 -0
- package/src/cli/star-prompt.ts +2 -0
- package/src/cli/status.ts +1 -1
- package/src/cli/telemetry-profile.ts +206 -0
- package/src/cli/telemetry.ts +260 -0
- package/src/client/hub-relay.ts +26 -0
- package/src/client/machine-api.ts +3 -0
- package/src/clients/config-export/t3code.ts +44 -5
- package/src/clients/omo-role-models.ts +1 -1
- package/src/codex/catalog/bundled.ts +44 -2
- package/src/codex/runtime.ts +12 -0
- package/src/codex/shim-restore-lock.ts +67 -30
- package/src/combos/types.ts +21 -1
- package/src/config/atomic-write.ts +24 -1
- package/src/config/diagnostics.ts +15 -0
- package/src/config/live-reconcile.ts +17 -0
- package/src/config/load-degrade.ts +16 -0
- package/src/config/provider-validation.ts +29 -0
- package/src/config/schema/config-schema.ts +24 -0
- package/src/config/schema/leaf-validators.ts +17 -0
- package/src/config/telemetry-carry.ts +30 -0
- package/src/config.ts +13 -1
- package/src/generated/compatibility-version.json +422 -170
- package/src/generated/model-metadata.ts +3 -3
- package/src/integrations/aside-profiles.ts +7 -1
- package/src/integrations/owned-refresh.ts +9 -2
- package/src/lab/artifacts/secure-fs.ts +12 -11
- package/src/lab/fabric/scratch.ts +11 -9
- package/src/lab/public/community.ts +2 -3
- package/src/lab/public/file-safety.ts +18 -20
- package/src/lab/public/mutation-lock.ts +109 -337
- package/src/lab/public/private-file.ts +4 -3
- package/src/lib/bun-runtime-preflight.ts +1 -1
- package/src/lib/codex-catalog-read-only.ts +122 -0
- package/src/lib/config-ownership.ts +56 -18
- package/src/lib/errors.ts +11 -0
- package/src/lib/gcp-adc.ts +167 -48
- package/src/lib/jsonc.ts +4 -2
- package/src/lib/local-control-socket.ts +88 -0
- package/src/lib/privacy.ts +15 -0
- package/src/lib/provider-client-headers.ts +3 -0
- package/src/lib/token-estimate.ts +13 -2
- package/src/link/child-binary-source.ts +228 -0
- package/src/link/ephemeral-child.ts +45 -0
- package/src/link/remote-plant.ts +306 -0
- package/src/link/remote-windows.ts +59 -5
- package/src/link/ssh-argv.ts +71 -8
- package/src/link/status-projection.ts +2 -0
- package/src/link/store.ts +5 -1
- package/src/oauth/anthropic-model-quota.ts +12 -0
- package/src/oauth/anthropic-routing.ts +11 -4
- package/src/oauth/claude-keychain-read.ts +165 -0
- package/src/oauth/kiro-iam-identity-center.ts +4 -1
- package/src/oauth/local-token-detect.ts +14 -17
- package/src/protocols/envelope.ts +20 -2
- package/src/providers/api-key-selection.ts +8 -2
- package/src/providers/claude-cli-identity.ts +9 -3
- package/src/providers/claude-cli-usage-state.ts +93 -0
- package/src/providers/claude-cli-usage.ts +3 -2
- package/src/providers/github-copilot-auto.ts +25 -5
- package/src/providers/meta-muse-plan-refusal.ts +94 -0
- package/src/providers/model-rename-fields.ts +3 -0
- package/src/providers/quota/anthropic-family-headers.ts +8 -1
- package/src/providers/quota/anthropic-usage-windows.ts +49 -2
- package/src/providers/quota/vendor-probes-key.ts +23 -4
- package/src/providers/quota/vendor-probes-oauth.ts +59 -0
- package/src/providers/quota/workbuddy.ts +2 -2
- package/src/providers/quota-types.ts +7 -0
- package/src/providers/quota.ts +25 -18
- package/src/providers/registry/entries-core.ts +7 -4
- package/src/providers/registry/entries-extended.ts +42 -8
- package/src/providers/registry/model-ids.ts +1 -0
- package/src/providers/registry/model-seeds.ts +10 -2
- package/src/providers/registry/types.ts +6 -0
- package/src/providers/resolved-model-policy.ts +4 -0
- package/src/providers/routed-config.ts +30 -3
- package/src/providers/stale-no-vision-seed-migration.ts +7 -0
- package/src/providers/vertex-environment-authority.ts +50 -0
- package/src/providers/workbuddy-credit-balance.ts +38 -6
- package/src/quota-pool/assemble.ts +14 -6
- package/src/responses/retained-compaction.ts +31 -5
- package/src/router.ts +1 -0
- package/src/server/adapter-resolve.ts +11 -6
- package/src/server/audio-dictation.ts +21 -7
- package/src/server/auth-cors.ts +19 -0
- package/src/server/background-lifecycle.ts +71 -0
- package/src/server/chat-completions.ts +2 -0
- package/src/server/claude-messages.ts +30 -3
- package/src/server/index/live-sideband.ts +15 -1
- package/src/server/index/local-control-listener.ts +515 -0
- package/src/server/index/optional-listeners.ts +21 -1
- package/src/server/index/serve-options.ts +4 -3
- package/src/server/index/websocket-handler.ts +2 -0
- package/src/server/index.ts +3 -0
- package/src/server/management/combo-routes.ts +6 -1
- package/src/server/management/context.ts +1 -0
- package/src/server/management/link-child-preflight.ts +74 -0
- package/src/server/management/link-enrollment.ts +190 -25
- package/src/server/management/link-route-state.ts +6 -1
- package/src/server/management/link-routes.ts +27 -9
- package/src/server/management/model-rows.ts +4 -0
- package/src/server/management/oauth-account-routes.ts +9 -4
- package/src/server/management/provider-overwrite-carry.ts +9 -2
- package/src/server/management/provider-routes.ts +14 -0
- package/src/server/management/provider-thinking-display-patch.ts +54 -0
- package/src/server/management/route-registry.ts +7 -0
- package/src/server/management/session-routes.ts +4 -1
- package/src/server/management/telemetry-routes.ts +37 -0
- package/src/server/management/usage-aggregate-cache.ts +290 -67
- package/src/server/management-api.ts +11 -2
- package/src/server/messages-native-preflight.ts +166 -0
- package/src/server/messages-native.ts +143 -43
- package/src/server/messages-shared.ts +14 -0
- package/src/server/proxy-liveness.ts +99 -6
- package/src/server/request-log-conversation.ts +18 -2
- package/src/server/request-log.ts +7 -2
- package/src/server/responses/adapter-continuation.ts +1 -0
- package/src/server/responses/adapter-dispatch.ts +11 -28
- package/src/server/responses/adapter-failure-message.ts +68 -0
- package/src/server/responses/combo-stream-preflight.ts +14 -2
- package/src/server/responses/compact.ts +13 -1
- package/src/server/responses/core-auth.ts +26 -5
- package/src/server/responses/core-codex-account.ts +8 -1
- package/src/server/responses/core-combo-failure.ts +6 -1
- package/src/server/responses/core-combo-native.ts +150 -37
- package/src/server/responses/core-combo.ts +15 -9
- package/src/server/responses/core-normalize.ts +1 -0
- package/src/server/responses/core-options.ts +7 -1
- package/src/server/responses/core-pipeline.ts +21 -1
- package/src/server/responses/fetch-helpers.ts +5 -0
- package/src/server/responses/opengateway-completion-guard.ts +7 -3
- package/src/server/responses/passthrough-delivery.ts +8 -1
- package/src/server/responses/passthrough-error.ts +22 -0
- package/src/server/responses/request-prepare.ts +7 -1
- package/src/server/responses/request-transport.ts +28 -5
- package/src/server/responses/run-turn-execution.ts +13 -0
- package/src/server/sse-frame-buffer.ts +5 -0
- package/src/server/ws-bridge.ts +10 -0
- package/src/service/launchd.ts +78 -4
- package/src/telemetry/aggregate.ts +348 -0
- package/src/telemetry/consent.ts +128 -0
- package/src/telemetry/contract.ts +403 -0
- package/src/telemetry/disclosure.ts +19 -0
- package/src/telemetry/install-id.ts +226 -0
- package/src/telemetry/payload.ts +129 -0
- package/src/telemetry/profile/client.ts +150 -0
- package/src/telemetry/profile/contract.ts +288 -0
- package/src/telemetry/profile/disclosure.ts +14 -0
- package/src/telemetry/profile/paths.ts +13 -0
- package/src/telemetry/profile/routes.ts +99 -0
- package/src/telemetry/profile/service.ts +234 -0
- package/src/telemetry/profile/state.ts +189 -0
- package/src/telemetry/profile/sync.ts +276 -0
- package/src/telemetry/routes.ts +183 -0
- package/src/telemetry/scheduler.ts +386 -0
- package/src/telemetry/sender.ts +97 -0
- package/src/telemetry/state.ts +334 -0
- package/src/types/combo-jev-effort-mode.ts +11 -0
- package/src/types/config.ts +3 -0
- package/src/types/provider.ts +11 -1
- package/src/types/request.ts +2 -0
- package/src/types/telemetry.ts +15 -0
- package/src/types/wire.ts +10 -0
- package/src/types.ts +5 -0
- package/src/update/index.ts +7 -1
- package/src/update/minisign.d.mts +17 -0
- package/src/update/minisign.mjs +88 -0
- package/src/update/signed-supply.d.mts +59 -0
- package/src/update/signed-supply.mjs +289 -0
- package/src/update/trust-root.json +38 -0
- package/src/update/update-bounded-json.d.mts +4 -0
- package/src/update/update-bounded-json.mjs +113 -0
- package/src/update/update-bytes.d.mts +2 -0
- package/src/update/update-bytes.mjs +23 -0
- package/src/update/update-candidate-id.d.mts +2 -0
- package/src/update/update-candidate-id.mjs +23 -0
- package/src/update/update-checkpoint-codec.d.mts +33 -0
- package/src/update/update-checkpoint-codec.mjs +217 -0
- package/src/update/update-contracts.d.mts +24 -0
- package/src/update/update-contracts.mjs +207 -0
- package/src/update/update-signature-threshold.d.mts +12 -0
- package/src/update/update-signature-threshold.mjs +47 -0
- package/src/update/update-signed-version.d.mts +5 -0
- package/src/update/update-signed-version.mjs +25 -0
- package/src/update/update-trust-anchor.d.mts +2 -0
- package/src/update/update-trust-anchor.mjs +2 -0
- package/src/usage/cache-diagnostic.ts +195 -50
- package/src/usage/expected-prices.ts +20 -2
- package/src/usage/filter-index.ts +1469 -0
- package/src/usage/ledger-scanner.ts +245 -4
- package/src/usage/source-filter.ts +10 -2
- package/src/usage/summary.ts +16 -0
- package/src/web-search/parse.ts +265 -38
- package/gui/dist/assets/App-BepstgEN.js +0 -59
- package/gui/dist/assets/Tray-BinxbEZo.js +0 -1
- package/gui/dist/assets/brand-mark-wzPe3R-J.js +0 -1
- package/gui/dist/assets/index-C-9X2yaI.js +0 -94
- package/gui/dist/assets/index-bnUWypyz.css +0 -2
- package/gui/dist/classic/assets/App-DX88_GCW.js +0 -58
- package/gui/dist/classic/assets/index-fSP71pLB.js +0 -94
- package/gui/dist/classic/assets/quota-summary-y2fl0WBv.js +0 -1
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
// Canonical checkpoint data only. This module never authenticates or grants update authority.
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { snapshotUpdateBytes } from "./update-bytes.mjs";
|
|
4
|
+
import { parseRootTransitionEnvelope, parseUpdateDocument } from "./update-contracts.mjs";
|
|
5
|
+
import { sameSignedVersion } from "./update-signed-version.mjs";
|
|
6
|
+
|
|
7
|
+
const PREFIX = Buffer.from("ocx.update.checkpoint/1\0", "ascii");
|
|
8
|
+
const MAX_PAYLOAD = 64 * 1024 * 1024;
|
|
9
|
+
const MAX_ROOT = 65536, MAX_ENVELOPE = 262144;
|
|
10
|
+
const CHANNELS = ["latest", "preview", "nightly"];
|
|
11
|
+
const OWNERS = ["desktop", "npm", "pnpm", "bun", "standalone", "service"];
|
|
12
|
+
const KEYS = ["namespaceDigest", "principalDigest", "ownerKind", "consentGeneration", "identityKind", "identityBytes", "generation", "rootRevision", "rootDigest", "rootBytes", "history", "channels", "firstSeen", "clockHighWaterMs", "securityEpoch"];
|
|
13
|
+
const HISTORY_KEYS = ["previousRevision", "previousDigest", "nextRevision", "nextDigest", "acceptedAtMs", "rootBytes", "envelopeBytes"];
|
|
14
|
+
const FLOOR_KEYS = ["sequence", "releaseDigest", "version"];
|
|
15
|
+
const SEEN_KEYS = ["candidateDigest", "firstSeenMs"];
|
|
16
|
+
const fail = () => { throw new Error("Invalid checkpoint payload"); };
|
|
17
|
+
|
|
18
|
+
function record(value, keys) {
|
|
19
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) fail();
|
|
20
|
+
// JavaScript must enumerate own keys to reject extras; executable proxies can
|
|
21
|
+
// still make that enumeration expensive. Do not materialize extra descriptors.
|
|
22
|
+
const names = Reflect.ownKeys(value);
|
|
23
|
+
if (names.length !== keys.length || names.some((key) => typeof key !== "string" || !keys.includes(key))) fail();
|
|
24
|
+
const result = Object.create(null);
|
|
25
|
+
for (const key of keys) {
|
|
26
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
27
|
+
if (!descriptor || !("value" in descriptor)) fail();
|
|
28
|
+
result[key] = descriptor.value;
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
function list(value, max) {
|
|
33
|
+
if (!Array.isArray(value)) fail();
|
|
34
|
+
const length = Object.getOwnPropertyDescriptor(value, "length")?.value;
|
|
35
|
+
if (!Number.isSafeInteger(length) || length < 0 || length > max) fail();
|
|
36
|
+
const names = Reflect.ownKeys(value);
|
|
37
|
+
if (names.length !== length + 1 || names.some((key) => key !== "length" && (typeof key !== "string" || !/^(0|[1-9][0-9]*)$/.test(key) || Number(key) >= length))) fail();
|
|
38
|
+
const result = [];
|
|
39
|
+
for (let i = 0; i < length; i++) {
|
|
40
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, String(i));
|
|
41
|
+
if (!descriptor || !("value" in descriptor)) fail();
|
|
42
|
+
result.push(descriptor.value);
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
function number(value, positive = false) {
|
|
47
|
+
if (!Number.isSafeInteger(value) || value < (positive ? 1 : 0)) fail();
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
function bytes(value, max, exact = false) {
|
|
51
|
+
const copy = snapshotUpdateBytes(value, max);
|
|
52
|
+
if (copy.length === 0 || (exact && copy.length !== max)) fail();
|
|
53
|
+
return Buffer.from(copy);
|
|
54
|
+
}
|
|
55
|
+
const digest = (value) => bytes(value, 32, true);
|
|
56
|
+
const hash = (value) => createHash("sha256").update(value).digest();
|
|
57
|
+
function root(bytesValue, revision, expectedDigest) {
|
|
58
|
+
if (!hash(bytesValue).equals(expectedDigest)) fail();
|
|
59
|
+
const parsed = parseUpdateDocument(bytesValue, "ocx.update.root/1");
|
|
60
|
+
if (parsed.revision !== revision) fail();
|
|
61
|
+
}
|
|
62
|
+
function capture(input) {
|
|
63
|
+
const data = record(input, KEYS);
|
|
64
|
+
const owner = OWNERS.indexOf(data.ownerKind);
|
|
65
|
+
if (owner < 0 || (data.identityKind !== "posix" && data.identityKind !== "windows")) fail();
|
|
66
|
+
const identitySize = data.identityKind === "posix" ? 16 : 24;
|
|
67
|
+
const result = {
|
|
68
|
+
namespaceDigest: digest(data.namespaceDigest), principalDigest: digest(data.principalDigest),
|
|
69
|
+
ownerKind: data.ownerKind, consentGeneration: number(data.consentGeneration),
|
|
70
|
+
identityKind: data.identityKind, identityBytes: bytes(data.identityBytes, identitySize, true),
|
|
71
|
+
generation: number(data.generation, true), rootRevision: number(data.rootRevision, true),
|
|
72
|
+
rootDigest: digest(data.rootDigest), rootBytes: bytes(data.rootBytes, MAX_ROOT),
|
|
73
|
+
history: [], channels: {}, firstSeen: {}, clockHighWaterMs: number(data.clockHighWaterMs),
|
|
74
|
+
securityEpoch: number(data.securityEpoch, true),
|
|
75
|
+
};
|
|
76
|
+
root(result.rootBytes, result.rootRevision, result.rootDigest);
|
|
77
|
+
let previous = null;
|
|
78
|
+
for (const item of list(data.history, 128)) {
|
|
79
|
+
const h = record(item, HISTORY_KEYS);
|
|
80
|
+
const entry = {
|
|
81
|
+
previousRevision: number(h.previousRevision, true), previousDigest: digest(h.previousDigest),
|
|
82
|
+
nextRevision: number(h.nextRevision, true), nextDigest: digest(h.nextDigest),
|
|
83
|
+
acceptedAtMs: number(h.acceptedAtMs), rootBytes: bytes(h.rootBytes, MAX_ROOT),
|
|
84
|
+
envelopeBytes: bytes(h.envelopeBytes, MAX_ENVELOPE),
|
|
85
|
+
};
|
|
86
|
+
if (entry.nextRevision <= entry.previousRevision || (previous && (entry.previousRevision !== previous.nextRevision || !entry.previousDigest.equals(previous.nextDigest) || entry.acceptedAtMs < previous.acceptedAtMs))) fail();
|
|
87
|
+
root(entry.rootBytes, entry.nextRevision, entry.nextDigest);
|
|
88
|
+
parseRootTransitionEnvelope(entry.envelopeBytes);
|
|
89
|
+
result.history.push(entry);
|
|
90
|
+
previous = entry;
|
|
91
|
+
}
|
|
92
|
+
if (previous && (previous.nextRevision !== result.rootRevision || !previous.nextDigest.equals(result.rootDigest))) fail();
|
|
93
|
+
const floors = record(data.channels, CHANNELS), observations = record(data.firstSeen, CHANNELS);
|
|
94
|
+
for (const channel of CHANNELS) {
|
|
95
|
+
const floor = floors[channel];
|
|
96
|
+
if (floor === null) result.channels[channel] = null;
|
|
97
|
+
else {
|
|
98
|
+
const f = record(floor, FLOOR_KEYS);
|
|
99
|
+
if (typeof f.version !== "string" || !sameSignedVersion(f.version, f.version)) fail();
|
|
100
|
+
result.channels[channel] = { sequence: number(f.sequence, true), releaseDigest: digest(f.releaseDigest), version: f.version };
|
|
101
|
+
}
|
|
102
|
+
const entries = [];
|
|
103
|
+
for (const item of list(observations[channel], 4096)) {
|
|
104
|
+
const s = record(item, SEEN_KEYS);
|
|
105
|
+
const entry = { candidateDigest: digest(s.candidateDigest), firstSeenMs: number(s.firstSeenMs) };
|
|
106
|
+
if (entry.firstSeenMs > result.clockHighWaterMs || (entries.length && Buffer.compare(entries[entries.length - 1].candidateDigest, entry.candidateDigest) >= 0)) fail();
|
|
107
|
+
entries.push(entry);
|
|
108
|
+
}
|
|
109
|
+
result.firstSeen[channel] = entries;
|
|
110
|
+
}
|
|
111
|
+
return result;
|
|
112
|
+
}
|
|
113
|
+
const u8 = (value) => Buffer.from([value]);
|
|
114
|
+
function u16(value) { const out = Buffer.allocUnsafe(2); out.writeUInt16BE(value); return out; }
|
|
115
|
+
function u32(value) { const out = Buffer.allocUnsafe(4); out.writeUInt32BE(value); return out; }
|
|
116
|
+
function u64(value) { const out = Buffer.allocUnsafe(8); out.writeBigUInt64BE(BigInt(value)); return out; }
|
|
117
|
+
const lengthOf = (chunks) => chunks.reduce((total, chunk) => total + chunk.length, 0);
|
|
118
|
+
function sized(chunks) { return [u32(lengthOf(chunks)), ...chunks]; }
|
|
119
|
+
function encodeCaptured(data) {
|
|
120
|
+
const fields = [
|
|
121
|
+
[data.namespaceDigest, data.principalDigest],
|
|
122
|
+
[u8(OWNERS.indexOf(data.ownerKind) + 1), u64(data.consentGeneration), u8(data.identityKind === "posix" ? 1 : 2), u16(data.identityBytes.length), data.identityBytes],
|
|
123
|
+
[u64(data.generation), u64(data.rootRevision), data.rootDigest],
|
|
124
|
+
[data.rootBytes],
|
|
125
|
+
[u32(data.history.length)], [], [], [u64(data.clockHighWaterMs), u64(data.securityEpoch)],
|
|
126
|
+
];
|
|
127
|
+
for (const item of data.history) {
|
|
128
|
+
fields[4].push(...sized([u64(item.previousRevision), item.previousDigest, u64(item.nextRevision), item.nextDigest, u64(item.acceptedAtMs), ...sized([item.rootBytes]), ...sized([item.envelopeBytes])]));
|
|
129
|
+
}
|
|
130
|
+
for (const channel of CHANNELS) {
|
|
131
|
+
const floor = data.channels[channel];
|
|
132
|
+
if (!floor) fields[5].push(u8(0));
|
|
133
|
+
else { const version = Buffer.from(floor.version, "ascii"); fields[5].push(u8(1), u64(floor.sequence), floor.releaseDigest, u8(version.length), version); }
|
|
134
|
+
const seen = data.firstSeen[channel];
|
|
135
|
+
fields[6].push(u32(seen.length));
|
|
136
|
+
for (const entry of seen) fields[6].push(entry.candidateDigest, u64(entry.firstSeenMs));
|
|
137
|
+
}
|
|
138
|
+
const chunks = [PREFIX];
|
|
139
|
+
for (let i = 0; i < fields.length; i++) chunks.push(u16(i + 1), ...sized(fields[i]));
|
|
140
|
+
const length = lengthOf(chunks);
|
|
141
|
+
if (length > MAX_PAYLOAD) fail();
|
|
142
|
+
return new Uint8Array(Buffer.concat(chunks, length));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
class Reader {
|
|
146
|
+
constructor(bytesValue) { this.data = bytesValue; this.offset = 0; }
|
|
147
|
+
take(length) {
|
|
148
|
+
if (!Number.isSafeInteger(length) || length < 0 || length > this.data.length - this.offset) fail();
|
|
149
|
+
const value = this.data.subarray(this.offset, this.offset + length); this.offset += length; return value;
|
|
150
|
+
}
|
|
151
|
+
byte() { return this.take(1)[0]; }
|
|
152
|
+
short() { return this.take(2).readUInt16BE(); }
|
|
153
|
+
uint() { return this.take(4).readUInt32BE(); }
|
|
154
|
+
long() { const value = this.take(8).readBigUInt64BE(); if (value > BigInt(Number.MAX_SAFE_INTEGER)) fail(); return Number(value); }
|
|
155
|
+
end() { if (this.offset !== this.data.length) fail(); }
|
|
156
|
+
blob(max) { const length = this.uint(); if (length < 1 || length > max) fail(); return new Uint8Array(this.take(length)); }
|
|
157
|
+
}
|
|
158
|
+
function decodeSnapshot(snapshot) {
|
|
159
|
+
const input = new Reader(Buffer.from(snapshot));
|
|
160
|
+
if (!input.take(PREFIX.length).equals(PREFIX)) fail();
|
|
161
|
+
const fields = [];
|
|
162
|
+
for (let tag = 1; tag <= 8; tag++) {
|
|
163
|
+
if (input.short() !== tag) fail();
|
|
164
|
+
fields.push(new Reader(input.take(input.uint())));
|
|
165
|
+
}
|
|
166
|
+
input.end();
|
|
167
|
+
const [a,b,c,d,e,f,g,h] = fields;
|
|
168
|
+
const namespaceDigest = new Uint8Array(a.take(32)), principalDigest = new Uint8Array(a.take(32)); a.end();
|
|
169
|
+
const owner = b.byte(), consentGeneration = b.long(), identity = b.byte(), identityLength = b.short();
|
|
170
|
+
if (!OWNERS[owner - 1] || ![1, 2].includes(identity) || identityLength !== (identity === 1 ? 16 : 24)) fail();
|
|
171
|
+
const identityBytes = new Uint8Array(b.take(identityLength)); b.end();
|
|
172
|
+
const generation = c.long(), rootRevision = c.long(), rootDigest = new Uint8Array(c.take(32)); c.end();
|
|
173
|
+
if (d.data.length < 1 || d.data.length > MAX_ROOT) fail();
|
|
174
|
+
const rootBytes = new Uint8Array(d.take(d.data.length)); d.end();
|
|
175
|
+
const count = e.uint(); if (count > 128) fail();
|
|
176
|
+
const history = [];
|
|
177
|
+
for (let i = 0; i < count; i++) {
|
|
178
|
+
const size = e.uint(); if (size > 88 + 4 + MAX_ROOT + 4 + MAX_ENVELOPE) fail();
|
|
179
|
+
const item = new Reader(e.take(size));
|
|
180
|
+
history.push({ previousRevision: item.long(), previousDigest: new Uint8Array(item.take(32)), nextRevision: item.long(), nextDigest: new Uint8Array(item.take(32)), acceptedAtMs: item.long(), rootBytes: item.blob(MAX_ROOT), envelopeBytes: item.blob(MAX_ENVELOPE) });
|
|
181
|
+
item.end();
|
|
182
|
+
}
|
|
183
|
+
e.end();
|
|
184
|
+
const channels = {}, firstSeen = {};
|
|
185
|
+
for (const channel of CHANNELS) {
|
|
186
|
+
const present = f.byte(); if (present > 1) fail();
|
|
187
|
+
if (!present) channels[channel] = null;
|
|
188
|
+
else {
|
|
189
|
+
const sequence = f.long(), releaseDigest = new Uint8Array(f.take(32)), size = f.byte();
|
|
190
|
+
if (!size || size > 64) fail();
|
|
191
|
+
const version = f.take(size); if (version.some((byte) => byte > 127)) fail();
|
|
192
|
+
channels[channel] = { sequence, releaseDigest, version: version.toString("ascii") };
|
|
193
|
+
}
|
|
194
|
+
const seenCount = g.uint(); if (seenCount > 4096) fail();
|
|
195
|
+
const seen = [];
|
|
196
|
+
for (let i = 0; i < seenCount; i++) seen.push({ candidateDigest: new Uint8Array(g.take(32)), firstSeenMs: g.long() });
|
|
197
|
+
firstSeen[channel] = seen;
|
|
198
|
+
}
|
|
199
|
+
f.end(); g.end();
|
|
200
|
+
const clockHighWaterMs = h.long(), securityEpoch = h.long(); h.end();
|
|
201
|
+
const value = { namespaceDigest, principalDigest, ownerKind: OWNERS[owner - 1], consentGeneration, identityKind: identity === 1 ? "posix" : "windows", identityBytes, generation, rootRevision, rootDigest, rootBytes, history, channels, firstSeen, clockHighWaterMs, securityEpoch };
|
|
202
|
+
// Re-encoding validates all semantic rules and the canonical representation.
|
|
203
|
+
const canonical = encodeCaptured(capture(value));
|
|
204
|
+
if (!Buffer.from(canonical).equals(Buffer.from(snapshot))) fail();
|
|
205
|
+
return value;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** Structurally encode unverified checkpoint data; no trust or installation authority is issued. */
|
|
209
|
+
export function encodeCheckpointPayload(input) { return encodeCaptured(capture(input)); }
|
|
210
|
+
/** Decode and validate a private snapshot; returned buffers are detached from the input. */
|
|
211
|
+
export function decodeCheckpointPayload(input) { return decodeSnapshot(snapshotUpdateBytes(input, MAX_PAYLOAD)); }
|
|
212
|
+
/** Hash exactly the private snapshot whose canonical structure was validated. */
|
|
213
|
+
export function checkpointPayloadDigest(input) {
|
|
214
|
+
const snapshot = snapshotUpdateBytes(input, MAX_PAYLOAD);
|
|
215
|
+
decodeSnapshot(snapshot);
|
|
216
|
+
return hash(snapshot).toString("hex");
|
|
217
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Closed wire records are unverified data and convey no update authority. */
|
|
2
|
+
export type Channel = "latest" | "preview" | "nightly";
|
|
3
|
+
export type UpdateRole = "release" | "tree" | "desktop-artifact" | "standalone-artifact" | "guardian-artifact";
|
|
4
|
+
export interface DigestSize { sha256: string; size: number }
|
|
5
|
+
export interface RootKey { keyId: string; algorithm: "minisign-ed25519-blake2b512/1"; publicKey: string }
|
|
6
|
+
export interface ReleaseKey extends RootKey { channels: Channel[]; roles: UpdateRole[] }
|
|
7
|
+
export interface UpdateRoot { schema: "ocx.update.root/1"; revision: number; expiresAt: string; rootKeys: RootKey[]; rootThreshold: number; releaseKeys: ReleaseKey[]; releaseThreshold: number; channels: Channel[] }
|
|
8
|
+
export interface SignatureEnvelope { schema: "ocx.update.signatures/1"; signatures: { keyFingerprint: string; signatureBox: string }[] }
|
|
9
|
+
export interface RootTransitionEnvelope { schema: "ocx.update.root-transition-signatures/1"; signatures: { keyFingerprint: string; signatureBox: string }[] }
|
|
10
|
+
export interface UpdateTarget { id: string; platform: "macos" | "linux" | "windows"; arch: "x64" | "arm64"; owner: "desktop" | "npm" | "pnpm" | "bun" | "standalone"; artifactKind: "tauri" | "tree" | "standalone" | "guardian"; bundleKind: "app-tar-gz" | "msi" | "appimage" | "deb" | "zip" | "tar-gz" | "binary"; assetName: string; artifact: DigestSize & { signatureBox: string; signerFingerprint: string }; tree: DigestSize | null; capabilities: DigestSize }
|
|
11
|
+
export interface UpdateRelease { schema: "ocx.update.release/1"; version: string; channel: Channel; sequence: number; sourceCommit: string; rolloutNotBefore: string; receipt: DigestSize; releaseNotes: {title: string; body: string}[]; targets: UpdateTarget[] }
|
|
12
|
+
export interface UpdateReceipt { schema: "ocx.update.verification/1"; sourceCommit: string; version: string; channel: Channel; workflowRunId: number; workflowAttempt: number; versionSources: {path: string; sha256: string}[]; assets: {name: string; sha256: string; size: number}[]; universalProofs: {assetName: string; artifactSha256: string; architectures: ["arm64", "x64"]; inspectionSha256: string}[]; architectureProofs: {targetId: string; assetName: string; artifactSha256: string; arch: "arm64" | "x64"; inspectionSha256: string}[] }
|
|
13
|
+
export type TreeEntry = {path: string; type: "file"; mode: number; size: number; sha256: string} | {path: string; type: "directory"; mode: number} | {path: string; type: "symlink"; target: string};
|
|
14
|
+
export interface UpdateTree {schema: "ocx.update.tree/1"; version: string; target: string; entries: TreeEntry[]}
|
|
15
|
+
export interface Capability {id: string; version: number}
|
|
16
|
+
export interface UpdateCapabilities {schema: "ocx.link-capabilities/1"; version: string; channel: Channel; target: string; artifactSha256: string; homeProvides: Capability[]; childRequires: Capability[]; updateActions: Capability[]; installerAdapters: Capability[]; recoveryProtocols: Capability[]; fleetJournalReaders: Capability[]; compatibilityEpoch: number; compatibilityVectorSha256: string}
|
|
17
|
+
export interface UpdatePolicy {schema: "ocx.update.policy/1"; revision: number; channel: Channel; check: "automatic" | "manual"; download: "automatic" | "manual"; install: "manual" | "on-quit" | "when-idle"}
|
|
18
|
+
export type OwnerKind = "desktop" | "service" | "unmanaged";
|
|
19
|
+
export interface UpdatePrepared {schema: "ocx.update.prepared/1"; operationId: string; candidateDigest: string; stageIdentity: string; stageDigest: string; installationId: string; ownerKind: OwnerKind; policyRevision: number}
|
|
20
|
+
export type UpdateActivation = {schema: "ocx.update.activation/1"; operationId: string; generation: number; runtimeInstance: string; pid: number; port: number; installationId: string; ownerKind: OwnerKind; candidateDigest: string; stageDigest: string; policyRevision: number; deadlineMs: number} & ({action: "reserve" | "inspect"} | {action: "commit" | "cancel"; permit: string});
|
|
21
|
+
export interface UpdateDocumentSchemas {"ocx.update.root/1": UpdateRoot; "ocx.update.signatures/1": SignatureEnvelope; "ocx.update.root-transition-signatures/1": RootTransitionEnvelope; "ocx.update.release/1": UpdateRelease; "ocx.update.verification/1": UpdateReceipt; "ocx.update.tree/1": UpdateTree; "ocx.link-capabilities/1": UpdateCapabilities; "ocx.update.policy/1": UpdatePolicy; "ocx.update.prepared/1": UpdatePrepared; "ocx.update.activation/1": UpdateActivation}
|
|
22
|
+
export function parseUpdateDocument<S extends keyof UpdateDocumentSchemas>(bytes: Uint8Array, expectedSchema: S): UpdateDocumentSchemas[S];
|
|
23
|
+
export function parseSignatureEnvelope(bytes: Uint8Array): SignatureEnvelope;
|
|
24
|
+
export function parseRootTransitionEnvelope(bytes: Uint8Array): RootTransitionEnvelope;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
// These parsers validate wire shape only. Their results are not authenticated.
|
|
2
|
+
import { parseBoundedJson } from "./update-bounded-json.mjs";
|
|
3
|
+
import { decodePublicKey } from "./minisign.mjs";
|
|
4
|
+
import { sameSignedVersion } from "./update-signed-version.mjs";
|
|
5
|
+
|
|
6
|
+
const CAPS = Object.freeze({
|
|
7
|
+
"ocx.update.root/1": 65536, "ocx.update.signatures/1": 65536,
|
|
8
|
+
"ocx.update.root-transition-signatures/1": 262144,
|
|
9
|
+
"ocx.update.release/1": 1048576, "ocx.update.verification/1": 1048576,
|
|
10
|
+
"ocx.update.tree/1": 16777216, "ocx.link-capabilities/1": 1048576,
|
|
11
|
+
"ocx.update.policy/1": 4096, "ocx.update.prepared/1": 8192,
|
|
12
|
+
"ocx.update.activation/1": 8192,
|
|
13
|
+
});
|
|
14
|
+
const CHANNELS = ["latest", "preview", "nightly"];
|
|
15
|
+
const ROLES = ["release", "tree", "desktop-artifact", "standalone-artifact", "guardian-artifact"];
|
|
16
|
+
const OWNERS = ["desktop", "service", "unmanaged"];
|
|
17
|
+
const HASH = /^[a-f0-9]{64}$/;
|
|
18
|
+
const ASCII_ID = /^[A-Za-z0-9][A-Za-z0-9._+-]*$/;
|
|
19
|
+
const UUID = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
|
20
|
+
const VERSION_PATHS = ["package.json", "desktop/src-tauri/tauri.conf.json", "desktop/src-tauri/Cargo.toml", "desktop/src-tauri/Cargo.lock"];
|
|
21
|
+
const FAIL = () => { throw new Error("Invalid update document"); };
|
|
22
|
+
const text = (v, max = 4096) => typeof v === "string" && Buffer.byteLength(v, "utf8") <= max;
|
|
23
|
+
const id = (v) => text(v, 128) && ASCII_ID.test(v);
|
|
24
|
+
const assetName = (v) => text(v, 255) && ASCII_ID.test(v);
|
|
25
|
+
const hash = (v) => typeof v === "string" && HASH.test(v);
|
|
26
|
+
const integer = (v, min, max = Number.MAX_SAFE_INTEGER) => Number.isSafeInteger(v) && v >= min && v <= max;
|
|
27
|
+
const oneOf = (v, values) => values.includes(v);
|
|
28
|
+
const version = (v) => typeof v === "string" && sameSignedVersion(v, v);
|
|
29
|
+
const obj = (v, keys) => v !== null && typeof v === "object" && !Array.isArray(v)
|
|
30
|
+
&& Object.keys(v).length === keys.length && keys.every((k) => Object.hasOwn(v, k));
|
|
31
|
+
const array = (v, min, max) => Array.isArray(v) && v.length >= min && v.length <= max;
|
|
32
|
+
const unique = (values) => new Set(values).size === values.length;
|
|
33
|
+
const enumSet = (v, options) => array(v, 1, options.length) && unique(v) && v.every((x) => oneOf(x, options));
|
|
34
|
+
const exact = (condition) => { if (!condition) FAIL(); };
|
|
35
|
+
const validDate = (v) => {
|
|
36
|
+
if (typeof v !== "string" || !/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ$/.test(v)) return false;
|
|
37
|
+
const time = Date.parse(v);
|
|
38
|
+
return Number.isFinite(time) && new Date(time).toISOString() === v.replace("Z", ".000Z");
|
|
39
|
+
};
|
|
40
|
+
function base64(v, max) {
|
|
41
|
+
if (typeof v !== "string" || !v || v.length > Math.ceil(max / 3) * 4) FAIL();
|
|
42
|
+
const b = Buffer.from(v, "base64");
|
|
43
|
+
exact(b.length <= max && b.toString("base64") === v);
|
|
44
|
+
return b;
|
|
45
|
+
}
|
|
46
|
+
function utf8(b) {
|
|
47
|
+
try { return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(b); } catch { return FAIL(); }
|
|
48
|
+
}
|
|
49
|
+
function signature(v) {
|
|
50
|
+
const s = utf8(base64(v, 4096));
|
|
51
|
+
const lines = s.replace(/\r\n/g, "\n").replace(/\n$/, "").split("\n");
|
|
52
|
+
exact(lines.length === 4 && lines[0].startsWith("untrusted comment: ")
|
|
53
|
+
&& lines[2].startsWith("trusted comment: ") && !s.replace(/\r\n/g, "").includes("\r"));
|
|
54
|
+
const packet = base64(lines[1], 74);
|
|
55
|
+
exact(packet.length === 74 && packet.subarray(0, 2).toString() === "ED" && base64(lines[3], 64).length === 64);
|
|
56
|
+
}
|
|
57
|
+
function key(v, release) {
|
|
58
|
+
exact(obj(v, release ? ["keyId", "algorithm", "publicKey", "channels", "roles"] : ["keyId", "algorithm", "publicKey"]));
|
|
59
|
+
exact(hash(v.keyId) && v.algorithm === "minisign-ed25519-blake2b512/1");
|
|
60
|
+
const box = utf8(base64(v.publicKey, 4096));
|
|
61
|
+
let decoded;
|
|
62
|
+
try { decoded = decodePublicKey(box); } catch { FAIL(); }
|
|
63
|
+
exact(decoded.fingerprint === v.keyId);
|
|
64
|
+
if (release) exact(enumSet(v.channels, CHANNELS) && enumSet(v.roles, ROLES));
|
|
65
|
+
}
|
|
66
|
+
function root(v) {
|
|
67
|
+
exact(obj(v, ["schema", "revision", "expiresAt", "rootKeys", "rootThreshold", "releaseKeys", "releaseThreshold", "channels"]));
|
|
68
|
+
exact(integer(v.revision, 1) && validDate(v.expiresAt) && enumSet(v.channels, CHANNELS));
|
|
69
|
+
exact(array(v.rootKeys, 1, 16) && array(v.releaseKeys, 1, 16));
|
|
70
|
+
v.rootKeys.forEach((x) => key(x, false)); v.releaseKeys.forEach((x) => key(x, true));
|
|
71
|
+
exact(unique(v.rootKeys.map((x) => x.keyId)) && unique(v.releaseKeys.map((x) => x.keyId)));
|
|
72
|
+
exact(integer(v.rootThreshold, 1, v.rootKeys.length) && integer(v.releaseThreshold, 1, 16));
|
|
73
|
+
for (const channel of v.channels) {
|
|
74
|
+
for (const role of ROLES) {
|
|
75
|
+
const count = v.releaseKeys.filter((k) => k.channels.includes(channel) && k.roles.includes(role)).length;
|
|
76
|
+
if (count || role === "release") exact(count >= v.releaseThreshold);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function envelope(v, limit = 16) {
|
|
81
|
+
exact(obj(v, ["schema", "signatures"]) && array(v.signatures, 1, limit));
|
|
82
|
+
for (const entry of v.signatures) {
|
|
83
|
+
exact(obj(entry, ["keyFingerprint", "signatureBox"]) && hash(entry.keyFingerprint)); signature(entry.signatureBox);
|
|
84
|
+
}
|
|
85
|
+
exact(unique(v.signatures.map((x) => x.keyFingerprint)));
|
|
86
|
+
}
|
|
87
|
+
function digestSize(v, max) {
|
|
88
|
+
exact(obj(v, ["sha256", "size"]) && hash(v.sha256) && integer(v.size, 1, max));
|
|
89
|
+
}
|
|
90
|
+
const platforms = [["macos", "x64"], ["macos", "arm64"], ["windows", "x64"], ["linux", "x64"], ["linux", "arm64"]];
|
|
91
|
+
function targetTuple(t) {
|
|
92
|
+
const { platform: p, arch: a, owner: o, artifactKind: k, bundleKind: b } = t;
|
|
93
|
+
if (!platforms.some(([x, y]) => x === p && y === a)) return null;
|
|
94
|
+
const prefix = `${p}-${a}`;
|
|
95
|
+
if (o === "desktop" && k === "tauri") {
|
|
96
|
+
if (p === "macos" && b === "app-tar-gz") return `${prefix}-desktop-tauri`;
|
|
97
|
+
if (p === "windows" && b === "msi") return `${prefix}-desktop-tauri`;
|
|
98
|
+
if (p === "linux" && a === "x64" && (b === "appimage" || b === "deb")) return `${prefix}-desktop-${b}`;
|
|
99
|
+
}
|
|
100
|
+
if (o === "standalone" && k === "standalone" && b === (p === "windows" ? "zip" : "tar-gz")) return `${prefix}-standalone`;
|
|
101
|
+
if (["npm", "pnpm", "bun"].includes(o) && k === "tree" && b === "tar-gz") return `${prefix}-${o}`;
|
|
102
|
+
if (k === "guardian" && b === "binary" && (o === "standalone" || (o === "desktop" && !(p === "linux" && a === "arm64")))) return `${prefix}-${o}-guardian`;
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
function expectedAsset(t, ver, channel) {
|
|
106
|
+
if (t.artifactKind === "guardian" || t.artifactKind === "tree") return `ocx-update-${ver}-${channel}-${t.id}${t.artifactKind === "tree" ? ".tar.gz" : ""}`;
|
|
107
|
+
if (t.artifactKind === "standalone") return `ocx-${ver}-bun-${t.platform === "macos" ? "darwin" : t.platform}-${t.arch}.${t.platform === "windows" ? "zip" : "tar.gz"}`;
|
|
108
|
+
const suffix = t.platform === "macos" ? "macos.app.tar.gz" : t.platform === "windows" ? "windows-x64.msi" : t.bundleKind === "deb" ? "linux-amd64.deb" : "linux-x86_64.AppImage";
|
|
109
|
+
return `OpenCodex-${ver}-${suffix}`;
|
|
110
|
+
}
|
|
111
|
+
function target(t, ver, channel) {
|
|
112
|
+
exact(obj(t, ["id", "platform", "arch", "owner", "artifactKind", "bundleKind", "assetName", "artifact", "tree", "capabilities"]));
|
|
113
|
+
exact(id(t.id) && t.id === targetTuple(t) && assetName(t.assetName) && t.assetName === expectedAsset(t, ver, channel));
|
|
114
|
+
exact(obj(t.artifact, ["sha256", "size", "signatureBox", "signerFingerprint"]) && hash(t.artifact.sha256) && hash(t.artifact.signerFingerprint) && integer(t.artifact.size, 1, 1073741824));
|
|
115
|
+
signature(t.artifact.signatureBox);
|
|
116
|
+
if (t.artifactKind === "tauri" || t.artifactKind === "guardian") exact(t.tree === null); else digestSize(t.tree, 16777216);
|
|
117
|
+
digestSize(t.capabilities, 1048576);
|
|
118
|
+
}
|
|
119
|
+
function release(v) {
|
|
120
|
+
exact(obj(v, ["schema", "version", "channel", "sequence", "sourceCommit", "rolloutNotBefore", "receipt", "releaseNotes", "targets"]));
|
|
121
|
+
exact(version(v.version) && oneOf(v.channel, CHANNELS) && integer(v.sequence, 1) && typeof v.sourceCommit === "string" && /^[a-f0-9]{40}$/.test(v.sourceCommit) && validDate(v.rolloutNotBefore));
|
|
122
|
+
digestSize(v.receipt, 1048576);
|
|
123
|
+
exact(array(v.releaseNotes, 0, 256));
|
|
124
|
+
for (const n of v.releaseNotes) exact(obj(n, ["title", "body"]) && text(n.title, 16384) && text(n.body, 16384));
|
|
125
|
+
exact(array(v.targets, 1, 64)); v.targets.forEach((t) => target(t, v.version, v.channel));
|
|
126
|
+
exact(unique(v.targets.map((t) => t.id)));
|
|
127
|
+
}
|
|
128
|
+
function receipt(v) {
|
|
129
|
+
exact(obj(v, ["schema", "sourceCommit", "version", "channel", "workflowRunId", "workflowAttempt", "versionSources", "assets", "universalProofs", "architectureProofs"]));
|
|
130
|
+
exact(version(v.version) && oneOf(v.channel, CHANNELS) && typeof v.sourceCommit === "string" && /^[a-f0-9]{40}$/.test(v.sourceCommit) && integer(v.workflowRunId, 1) && integer(v.workflowAttempt, 1));
|
|
131
|
+
exact(array(v.versionSources, 4, 4));
|
|
132
|
+
for (const x of v.versionSources) exact(obj(x, ["path", "sha256"]) && VERSION_PATHS.includes(x.path) && hash(x.sha256));
|
|
133
|
+
exact(unique(v.versionSources.map((x) => x.path)) && array(v.assets, 1, 4096));
|
|
134
|
+
for (const x of v.assets) exact(obj(x, ["name", "sha256", "size"]) && assetName(x.name) && hash(x.sha256) && integer(x.size, 1));
|
|
135
|
+
exact(v.assets.every((x, i) => i === 0 || v.assets[i - 1].name < x.name));
|
|
136
|
+
exact(array(v.universalProofs, 0, 4096) && array(v.architectureProofs, 0, 4096));
|
|
137
|
+
for (const x of v.universalProofs) exact(obj(x, ["assetName", "artifactSha256", "architectures", "inspectionSha256"]) && assetName(x.assetName) && hash(x.artifactSha256) && hash(x.inspectionSha256) && array(x.architectures, 2, 2) && x.architectures[0] === "arm64" && x.architectures[1] === "x64");
|
|
138
|
+
for (const x of v.architectureProofs) exact(obj(x, ["targetId", "assetName", "artifactSha256", "arch", "inspectionSha256"]) && id(x.targetId) && assetName(x.assetName) && hash(x.artifactSha256) && hash(x.inspectionSha256) && oneOf(x.arch, ["x64", "arm64"]));
|
|
139
|
+
exact(unique(v.universalProofs.map((x) => JSON.stringify([x.assetName, x.artifactSha256, x.architectures, x.inspectionSha256])))
|
|
140
|
+
&& unique(v.architectureProofs.map((x) => JSON.stringify([x.targetId, x.assetName, x.artifactSha256, x.arch, x.inspectionSha256]))));
|
|
141
|
+
}
|
|
142
|
+
function path(v) {
|
|
143
|
+
return text(v, 1024) && v.length > 0 && !v.includes("\\") && !v.includes("\0") && !v.startsWith("/") && !/^[A-Za-z]:/.test(v) && v.split("/").every((x) => x && x !== "." && x !== "..");
|
|
144
|
+
}
|
|
145
|
+
function linkTarget(v) {
|
|
146
|
+
return text(v, 1024) && v.length > 0 && !v.includes("\\") && !v.includes("\0") && !v.startsWith("/") && !/^[A-Za-z]:/.test(v);
|
|
147
|
+
}
|
|
148
|
+
function tree(v) {
|
|
149
|
+
exact(obj(v, ["schema", "version", "target", "entries"]) && version(v.version) && id(v.target) && array(v.entries, 0, 4096));
|
|
150
|
+
const paths = new Map();
|
|
151
|
+
for (const e of v.entries) {
|
|
152
|
+
exact(e && typeof e === "object" && path(e.path) && !paths.has(e.path));
|
|
153
|
+
if (e.type === "file") exact(obj(e, ["path", "type", "mode", "size", "sha256"]) && integer(e.mode, 0, 511) && integer(e.size, 0, 1073741824) && hash(e.sha256));
|
|
154
|
+
else if (e.type === "directory") exact(obj(e, ["path", "type", "mode"]) && integer(e.mode, 0, 511));
|
|
155
|
+
else if (e.type === "symlink") exact(obj(e, ["path", "type", "target"]) && linkTarget(e.target));
|
|
156
|
+
else FAIL();
|
|
157
|
+
paths.set(e.path, e.type);
|
|
158
|
+
}
|
|
159
|
+
for (const name of paths.keys()) {
|
|
160
|
+
const separator = name.lastIndexOf("/");
|
|
161
|
+
if (separator !== -1) exact(paths.get(name.slice(0, separator)) === "directory");
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function capability(v) {
|
|
165
|
+
const fields = ["homeProvides", "childRequires", "updateActions", "installerAdapters", "recoveryProtocols", "fleetJournalReaders"];
|
|
166
|
+
exact(obj(v, ["schema", "version", "channel", "target", "artifactSha256", ...fields, "compatibilityEpoch", "compatibilityVectorSha256"]));
|
|
167
|
+
exact(version(v.version) && oneOf(v.channel, CHANNELS) && id(v.target) && hash(v.artifactSha256) && hash(v.compatibilityVectorSha256) && integer(v.compatibilityEpoch, 1));
|
|
168
|
+
for (const field of fields) {
|
|
169
|
+
const a = v[field]; exact(array(a, 0, 4096));
|
|
170
|
+
for (const x of a) exact(obj(x, ["id", "version"]) && id(x.id) && integer(x.version, 1));
|
|
171
|
+
exact(unique(a.map((x) => `${x.id}\0${x.version}`)));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function policy(v) {
|
|
175
|
+
exact(obj(v, ["schema", "revision", "channel", "check", "download", "install"]) && integer(v.revision, 0) && oneOf(v.channel, CHANNELS) && oneOf(v.check, ["automatic", "manual"]) && oneOf(v.download, ["automatic", "manual"]) && oneOf(v.install, ["manual", "on-quit", "when-idle"]));
|
|
176
|
+
}
|
|
177
|
+
function token(v) {
|
|
178
|
+
if (typeof v !== "string" || !/^[A-Za-z0-9_-]{43}$/.test(v)) return false;
|
|
179
|
+
const b = Buffer.from(v, "base64url"); return b.length === 32 && b.toString("base64url") === v;
|
|
180
|
+
}
|
|
181
|
+
function identity(v) { return typeof v === "string" && UUID.test(v); }
|
|
182
|
+
function prepared(v) {
|
|
183
|
+
exact(obj(v, ["schema", "operationId", "candidateDigest", "stageIdentity", "stageDigest", "installationId", "ownerKind", "policyRevision"]) && identity(v.operationId) && hash(v.candidateDigest) && token(v.stageIdentity) && hash(v.stageDigest) && id(v.installationId) && oneOf(v.ownerKind, OWNERS) && integer(v.policyRevision, 0));
|
|
184
|
+
}
|
|
185
|
+
function activation(v) {
|
|
186
|
+
const fields = ["schema", "action", "operationId", "generation", "runtimeInstance", "pid", "port", "installationId", "ownerKind", "candidateDigest", "stageDigest", "policyRevision", "deadlineMs"];
|
|
187
|
+
const permit = v && (v.action === "commit" || v.action === "cancel");
|
|
188
|
+
exact(obj(v, permit ? [...fields, "permit"] : fields) && oneOf(v.action, ["reserve", "inspect", "commit", "cancel"]) && identity(v.operationId) && integer(v.generation, 1) && id(v.runtimeInstance) && integer(v.pid, 1, 2147483647) && integer(v.port, 1, 65535) && id(v.installationId) && oneOf(v.ownerKind, OWNERS) && hash(v.candidateDigest) && hash(v.stageDigest) && integer(v.policyRevision, 0) && integer(v.deadlineMs, 0) && (!permit || token(v.permit)));
|
|
189
|
+
}
|
|
190
|
+
const VALIDATORS = Object.freeze({
|
|
191
|
+
"ocx.update.root/1": root, "ocx.update.signatures/1": envelope,
|
|
192
|
+
"ocx.update.root-transition-signatures/1": (value) => envelope(value, 32),
|
|
193
|
+
"ocx.update.release/1": release, "ocx.update.verification/1": receipt,
|
|
194
|
+
"ocx.update.tree/1": tree, "ocx.link-capabilities/1": capability,
|
|
195
|
+
"ocx.update.policy/1": policy, "ocx.update.prepared/1": prepared,
|
|
196
|
+
"ocx.update.activation/1": activation,
|
|
197
|
+
});
|
|
198
|
+
/** Parse a closed schema as unverified data; this does not authenticate it. */
|
|
199
|
+
export function parseUpdateDocument(bytes, expectedSchema) {
|
|
200
|
+
if (typeof expectedSchema !== "string" || !Object.hasOwn(CAPS, expectedSchema)) FAIL();
|
|
201
|
+
const value = parseBoundedJson(bytes, CAPS[expectedSchema]);
|
|
202
|
+
exact(value !== null && typeof value === "object" && !Array.isArray(value) && value.schema === expectedSchema);
|
|
203
|
+
VALIDATORS[expectedSchema](value);
|
|
204
|
+
return value;
|
|
205
|
+
}
|
|
206
|
+
export function parseSignatureEnvelope(bytes) { return parseUpdateDocument(bytes, "ocx.update.signatures/1"); }
|
|
207
|
+
export function parseRootTransitionEnvelope(bytes) { return parseUpdateDocument(bytes, "ocx.update.root-transition-signatures/1"); }
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface SignatureThresholdKey {
|
|
2
|
+
keyId: string;
|
|
3
|
+
algorithm: string;
|
|
4
|
+
publicKey: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface SignatureThresholdEnvelope {
|
|
8
|
+
signatures: { keyFingerprint: string; signatureBox: string }[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Cryptographic checking only: the caller establishes key authority and policy. */
|
|
12
|
+
export function verifySignatureThreshold(bytes: Uint8Array, envelope: SignatureThresholdEnvelope, keys: SignatureThresholdKey[], threshold: number): void;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { decodePublicKey, verifyMinisignBytes } from "./minisign.mjs";
|
|
2
|
+
|
|
3
|
+
const FINGERPRINT = /^[0-9a-f]{64}$/;
|
|
4
|
+
|
|
5
|
+
/** Verify a supplied signer set; callers must separately establish its authority. */
|
|
6
|
+
export function verifySignatureThreshold(bytes, envelope, keys, threshold) {
|
|
7
|
+
if (!(bytes instanceof Uint8Array) || !Array.isArray(keys) || keys.length < 1 || keys.length > 16
|
|
8
|
+
|| !Number.isSafeInteger(threshold) || threshold < 1 || threshold > keys.length
|
|
9
|
+
|| !Array.isArray(envelope?.signatures) || envelope.signatures.length < 1 || envelope.signatures.length > 16) {
|
|
10
|
+
throw new Error("Invalid signature threshold input");
|
|
11
|
+
}
|
|
12
|
+
const authorized = new Map();
|
|
13
|
+
for (const entry of keys) {
|
|
14
|
+
if (!entry || typeof entry.keyId !== "string" || !FINGERPRINT.test(entry.keyId)
|
|
15
|
+
|| entry.algorithm !== "minisign-ed25519-blake2b512/1" || typeof entry.publicKey !== "string"
|
|
16
|
+
|| !entry.publicKey || entry.publicKey.length > 5464 || authorized.has(entry.keyId)) {
|
|
17
|
+
throw new Error("Invalid signature threshold key");
|
|
18
|
+
}
|
|
19
|
+
const encoded = Buffer.from(entry.publicKey, "base64");
|
|
20
|
+
if (encoded.length > 4096 || encoded.toString("base64") !== entry.publicKey) {
|
|
21
|
+
throw new Error("Invalid signature threshold key encoding");
|
|
22
|
+
}
|
|
23
|
+
const text = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(encoded);
|
|
24
|
+
const key = decodePublicKey(text);
|
|
25
|
+
if (key.fingerprint !== entry.keyId) throw new Error("Signature threshold key fingerprint mismatch");
|
|
26
|
+
authorized.set(entry.keyId, key);
|
|
27
|
+
}
|
|
28
|
+
const seen = new Set();
|
|
29
|
+
let verified = 0;
|
|
30
|
+
for (const signature of envelope.signatures) {
|
|
31
|
+
if (!signature || typeof signature.keyFingerprint !== "string" || !FINGERPRINT.test(signature.keyFingerprint)
|
|
32
|
+
|| typeof signature.signatureBox !== "string" || !signature.signatureBox
|
|
33
|
+
|| signature.signatureBox.length > 5464 || seen.has(signature.keyFingerprint)) {
|
|
34
|
+
throw new Error("Invalid signature threshold envelope");
|
|
35
|
+
}
|
|
36
|
+
seen.add(signature.keyFingerprint);
|
|
37
|
+
const raw = Buffer.from(signature.signatureBox, "base64");
|
|
38
|
+
if (raw.length > 4096 || raw.toString("base64") !== signature.signatureBox) {
|
|
39
|
+
throw new Error("Invalid signature threshold envelope encoding");
|
|
40
|
+
}
|
|
41
|
+
const key = authorized.get(signature.keyFingerprint);
|
|
42
|
+
if (!key) continue; // Root rotation may carry signatures from both key sets.
|
|
43
|
+
verifyMinisignBytes(bytes, signature.signatureBox, key);
|
|
44
|
+
verified++;
|
|
45
|
+
}
|
|
46
|
+
if (verified < threshold) throw new Error("Signature threshold not met");
|
|
47
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Strict full version equality, including build metadata; this grants no authority. */
|
|
2
|
+
export function sameSignedVersion(releaseVersion: string, signedVersion: string): boolean;
|
|
3
|
+
|
|
4
|
+
/** Caller must authenticate the trusted comment before relying on this result. */
|
|
5
|
+
export function trustedCommentMatchesVersion(comment: string, releaseVersion: string): boolean;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const MAX_CORE = 18446744073709551615n;
|
|
2
|
+
const VERSION = /^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/;
|
|
3
|
+
|
|
4
|
+
function validVersion(value) {
|
|
5
|
+
if (typeof value !== "string" || value.length > 64) return false;
|
|
6
|
+
const match = VERSION.exec(value);
|
|
7
|
+
if (!match || match[0] !== value) return false;
|
|
8
|
+
if ([match[1], match[2], match[3]].some((part) => BigInt(part) > MAX_CORE)) return false;
|
|
9
|
+
if (match[4]?.split(".").some((part) => /^[0-9]+$/.test(part) && part.length > 1 && part[0] === "0")) return false;
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Compare complete signed version identity; no update authority is implied. */
|
|
14
|
+
export function sameSignedVersion(releaseVersion, signedVersion) {
|
|
15
|
+
if (!validVersion(releaseVersion) || typeof signedVersion !== "string") return false;
|
|
16
|
+
const normalized = signedVersion.startsWith("v") ? signedVersion.slice(1) : signedVersion;
|
|
17
|
+
return validVersion(normalized) && releaseVersion === normalized;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Compare a version field only after the caller authenticates the comment. */
|
|
21
|
+
export function trustedCommentMatchesVersion(comment, releaseVersion) {
|
|
22
|
+
if (typeof comment !== "string" || Buffer.byteLength(comment, "utf8") > 4096) return false;
|
|
23
|
+
const versions = comment.split("\t").filter((field) => field.startsWith("version:"));
|
|
24
|
+
return versions.length === 1 && sameSignedVersion(releaseVersion, versions[0].slice("version:".length));
|
|
25
|
+
}
|