@intentius/chant 0.124.61 → 0.124.63
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/dist/cli/handlers/approve.d.ts +18 -0
- package/dist/cli/handlers/approve.d.ts.map +1 -1
- package/dist/cli/handlers/approve.js +142 -16
- package/dist/cli/handlers/plan.d.ts +10 -0
- package/dist/cli/handlers/plan.d.ts.map +1 -0
- package/dist/cli/handlers/plan.js +71 -0
- package/dist/cli/handlers/release.d.ts +6 -4
- package/dist/cli/handlers/release.d.ts.map +1 -1
- package/dist/cli/handlers/release.js +13 -7
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/main.js +34 -5
- package/dist/cli/mcp/workspace-tools.d.ts.map +1 -1
- package/dist/cli/mcp/workspace-tools.js +2 -1
- package/dist/cli/parse-args.d.ts.map +1 -1
- package/dist/cli/parse-args.js +31 -0
- package/dist/cli/registry.d.ts +13 -1
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/config.d.ts +32 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/gate-decision.d.ts +1 -1
- package/dist/gate-decision.d.ts.map +1 -1
- package/dist/gate-decision.js +4 -2
- package/dist/gate-statement.schema.json +44 -0
- package/dist/lifecycle/__fixtures__/publish-fakes.d.ts +20 -0
- package/dist/lifecycle/__fixtures__/publish-fakes.d.ts.map +1 -1
- package/dist/lifecycle/__fixtures__/publish-fakes.js +119 -3
- package/dist/lifecycle/gate-ledger.d.ts +17 -3
- package/dist/lifecycle/gate-ledger.d.ts.map +1 -1
- package/dist/lifecycle/gate-seal.d.ts +39 -3
- package/dist/lifecycle/gate-seal.d.ts.map +1 -1
- package/dist/lifecycle/gate-seal.js +50 -10
- package/dist/lifecycle/gate-statement.d.ts +70 -0
- package/dist/lifecycle/gate-statement.d.ts.map +1 -0
- package/dist/lifecycle/gate-statement.js +74 -0
- package/dist/lifecycle/gate-webauthn.d.ts +79 -0
- package/dist/lifecycle/gate-webauthn.d.ts.map +1 -0
- package/dist/lifecycle/gate-webauthn.js +105 -0
- package/dist/lifecycle/git.d.ts +1 -1
- package/dist/lifecycle/git.d.ts.map +1 -1
- package/dist/lifecycle/git.js +24 -19
- package/dist/lifecycle/ledger-remote.d.ts +37 -0
- package/dist/lifecycle/ledger-remote.d.ts.map +1 -0
- package/dist/lifecycle/ledger-remote.js +42 -0
- package/dist/lifecycle/plan-stale.d.ts +76 -0
- package/dist/lifecycle/plan-stale.d.ts.map +1 -0
- package/dist/lifecycle/plan-stale.js +121 -0
- package/dist/lifecycle/publish-credentials.d.ts +1 -1
- package/dist/lifecycle/publish-credentials.d.ts.map +1 -1
- package/dist/lifecycle/publish-credentials.js +2 -0
- package/dist/lifecycle/publish-declaration.d.ts +87 -0
- package/dist/lifecycle/publish-declaration.d.ts.map +1 -1
- package/dist/lifecycle/publish-declaration.js +87 -1
- package/dist/lifecycle/publish-forge.d.ts +5 -1
- package/dist/lifecycle/publish-forge.d.ts.map +1 -1
- package/dist/lifecycle/publish-forge.js +14 -4
- package/dist/lifecycle/publish-github.d.ts +69 -0
- package/dist/lifecycle/publish-github.d.ts.map +1 -0
- package/dist/lifecycle/publish-github.js +153 -0
- package/dist/lifecycle/publish-homebrew.d.ts +66 -0
- package/dist/lifecycle/publish-homebrew.d.ts.map +1 -0
- package/dist/lifecycle/publish-homebrew.js +173 -0
- package/dist/lifecycle/publish-marketplace.d.ts +51 -0
- package/dist/lifecycle/publish-marketplace.d.ts.map +1 -0
- package/dist/lifecycle/publish-marketplace.js +254 -0
- package/dist/lifecycle/publish-targets.d.ts +6 -0
- package/dist/lifecycle/publish-targets.d.ts.map +1 -1
- package/dist/lifecycle/publish-targets.js +15 -0
- package/dist/lifecycle/publish-tauri.d.ts +61 -0
- package/dist/lifecycle/publish-tauri.d.ts.map +1 -0
- package/dist/lifecycle/publish-tauri.js +182 -0
- package/dist/lifecycle/release-publish.d.ts +5 -2
- package/dist/lifecycle/release-publish.d.ts.map +1 -1
- package/dist/lifecycle/snapshot-store.d.ts.map +1 -1
- package/dist/lifecycle/snapshot-store.js +17 -9
- package/dist/lifecycle/test-passkey.d.ts +25 -0
- package/dist/lifecycle/test-passkey.d.ts.map +1 -0
- package/dist/lifecycle/test-passkey.js +39 -0
- package/dist/notify.d.ts +23 -3
- package/dist/notify.d.ts.map +1 -1
- package/dist/notify.js +8 -2
- package/dist/notify.schema.json +12 -3
- package/dist/op/activities/activity-contracts.d.ts +4 -4
- package/dist/pr-forge.d.ts +20 -0
- package/dist/pr-forge.d.ts.map +1 -1
- package/dist/pr-forge.js +61 -2
- package/dist/release-floors.d.ts +1 -1
- package/dist/release-floors.js +1 -1
- package/dist/wave-runtime.mjs +331 -330
- package/dist/workspace/ci-builds.d.ts +21 -0
- package/dist/workspace/ci-builds.d.ts.map +1 -1
- package/dist/workspace/ci-builds.js +14 -0
- package/dist/workspace/ci-green-workflow.d.ts +2 -0
- package/dist/workspace/ci-green-workflow.d.ts.map +1 -1
- package/dist/workspace/ci-green-workflow.js +9 -0
- package/dist/workspace/ci-green.d.ts +45 -2
- package/dist/workspace/ci-green.d.ts.map +1 -1
- package/dist/workspace/ci-green.js +127 -9
- package/dist/workspace/ci-quarantine-report.d.ts +80 -0
- package/dist/workspace/ci-quarantine-report.d.ts.map +1 -0
- package/dist/workspace/ci-quarantine-report.js +205 -0
- package/dist/workspace/ci-quarantine.d.ts +73 -0
- package/dist/workspace/ci-quarantine.d.ts.map +1 -0
- package/dist/workspace/ci-quarantine.js +171 -0
- package/dist/workspace/ci-serve.d.ts.map +1 -1
- package/dist/workspace/ci-serve.js +7 -4
- package/dist/workspace/class-data.d.ts +3 -1
- package/dist/workspace/class-data.d.ts.map +1 -1
- package/dist/workspace/class-data.js +4 -1
- package/dist/workspace/declaration.d.ts +45 -2
- package/dist/workspace/declaration.d.ts.map +1 -1
- package/dist/workspace/declaration.js +45 -2
- package/dist/workspace/declaration.schema.json +51 -3
- package/dist/workspace/forge-work.d.ts +76 -0
- package/dist/workspace/forge-work.d.ts.map +1 -0
- package/dist/workspace/forge-work.js +160 -0
- package/dist/workspace/identity-gate-rule.d.ts +3 -2
- package/dist/workspace/identity-gate-rule.d.ts.map +1 -1
- package/dist/workspace/identity-gate-rule.js +5 -7
- package/dist/workspace/identity.d.ts +3 -2
- package/dist/workspace/identity.d.ts.map +1 -1
- package/dist/workspace/identity.js +6 -3
- package/dist/workspace/intent-cli.d.ts +3 -2
- package/dist/workspace/intent-cli.d.ts.map +1 -1
- package/dist/workspace/intent-cli.js +26 -5
- package/dist/workspace/intent-record.d.ts +3 -0
- package/dist/workspace/intent-record.d.ts.map +1 -1
- package/dist/workspace/intent-record.schema.json +32 -0
- package/dist/workspace/intent.d.ts +9 -0
- package/dist/workspace/intent.d.ts.map +1 -1
- package/dist/workspace/intent.js +3 -0
- package/dist/workspace/intent.schema.json +32 -0
- package/dist/workspace/kind-readers.d.ts.map +1 -1
- package/dist/workspace/kind-readers.js +2 -1
- package/dist/workspace/kinds.d.ts +6 -1
- package/dist/workspace/kinds.d.ts.map +1 -1
- package/dist/workspace/kinds.js +8 -3
- package/dist/workspace/plan-stale.schema.json +286 -0
- package/dist/workspace/release-candidates.d.ts +33 -6
- package/dist/workspace/release-candidates.d.ts.map +1 -1
- package/dist/workspace/release-candidates.js +49 -20
- package/dist/workspace/release-candidates.schema.json +48 -2
- package/dist/workspace/trust/policy.d.ts +10 -0
- package/dist/workspace/trust/policy.d.ts.map +1 -1
- package/dist/workspace/trust/policy.js +19 -1
- package/dist/workspace/trust/run-commits.d.ts.map +1 -1
- package/dist/workspace/trust/run-commits.js +2 -1
- package/dist/workspace/trust/seal.d.ts.map +1 -1
- package/dist/workspace/trust/seal.js +34 -3
- package/dist/workspace/trust/trust-files.d.ts.map +1 -1
- package/dist/workspace/trust/trust-files.js +6 -1
- package/package.json +2 -1
- package/src/cli/handlers/approve-external-signature.test.ts +226 -0
- package/src/cli/handlers/approve.ts +174 -16
- package/src/cli/handlers/plan.ts +74 -0
- package/src/cli/handlers/release.ts +12 -7
- package/src/cli/main.ts +34 -5
- package/src/cli/mcp/workspace-tools.ts +2 -1
- package/src/cli/parse-args.ts +24 -0
- package/src/cli/registry.ts +13 -1
- package/src/gate-decision-bundle.test.ts +4 -2
- package/src/gate-decision.ts +11 -2
- package/src/gate-statement.schema.json +44 -0
- package/src/lifecycle/__fixtures__/publish-fakes.ts +125 -5
- package/src/lifecycle/gate-ledger.ts +17 -3
- package/src/lifecycle/gate-seal.ts +62 -9
- package/src/lifecycle/gate-statement.ts +107 -0
- package/src/lifecycle/gate-webauthn.test.ts +77 -0
- package/src/lifecycle/gate-webauthn.ts +133 -0
- package/src/lifecycle/git.ts +23 -19
- package/src/lifecycle/ledger-remote.test.ts +183 -0
- package/src/lifecycle/ledger-remote.ts +46 -0
- package/src/lifecycle/plan-stale.test.ts +150 -0
- package/src/lifecycle/plan-stale.ts +173 -0
- package/src/lifecycle/publish-credentials.ts +2 -0
- package/src/lifecycle/publish-declaration.ts +93 -1
- package/src/lifecycle/publish-forge.ts +15 -4
- package/src/lifecycle/publish-github.ts +174 -0
- package/src/lifecycle/publish-homebrew.test.ts +179 -0
- package/src/lifecycle/publish-homebrew.ts +187 -0
- package/src/lifecycle/publish-marketplace.test.ts +254 -0
- package/src/lifecycle/publish-marketplace.ts +259 -0
- package/src/lifecycle/publish-target-context.test.ts +2 -2
- package/src/lifecycle/publish-targets.test.ts +23 -0
- package/src/lifecycle/publish-targets.ts +15 -0
- package/src/lifecycle/publish-tauri.test.ts +163 -0
- package/src/lifecycle/publish-tauri.ts +199 -0
- package/src/lifecycle/release-publish.ts +5 -3
- package/src/lifecycle/snapshot-store.ts +16 -9
- package/src/lifecycle/test-passkey.ts +55 -0
- package/src/notify-bundle.test.ts +3 -1
- package/src/notify.schema.json +12 -3
- package/src/notify.ts +20 -3
- package/src/override-gate-bundle.test.ts +2 -0
- package/src/pr-forge-bundle.test.ts +2 -2
- package/src/pr-forge.test.ts +38 -0
- package/src/pr-forge.ts +68 -5
- package/src/release-floors.ts +1 -1
- package/src/stage-hooks-bundle.test.ts +2 -0
- package/src/wave-runtime-bundle.test.ts +3 -2
- package/src/workspace/ci-builds.ts +27 -0
- package/src/workspace/ci-green-stale.test.ts +193 -0
- package/src/workspace/ci-green-workflow.test.ts +9 -0
- package/src/workspace/ci-green-workflow.ts +9 -0
- package/src/workspace/ci-green.ts +141 -10
- package/src/workspace/ci-quarantine-report.test.ts +146 -0
- package/src/workspace/ci-quarantine-report.ts +235 -0
- package/src/workspace/ci-quarantine.test.ts +161 -0
- package/src/workspace/ci-quarantine.ts +189 -0
- package/src/workspace/ci-serve.ts +7 -4
- package/src/workspace/class-data.ts +5 -1
- package/src/workspace/declaration.schema.json +51 -3
- package/src/workspace/declaration.test.ts +1 -0
- package/src/workspace/declaration.ts +88 -5
- package/src/workspace/forge-work.test.ts +143 -0
- package/src/workspace/forge-work.ts +195 -0
- package/src/workspace/identity-gate-rule.ts +6 -8
- package/src/workspace/identity.ts +6 -3
- package/src/workspace/intent-cli.ts +24 -5
- package/src/workspace/intent-record.schema.json +32 -0
- package/src/workspace/intent-record.ts +3 -0
- package/src/workspace/intent.schema.json +32 -0
- package/src/workspace/intent.ts +10 -0
- package/src/workspace/kind-readers.ts +2 -1
- package/src/workspace/kinds.test.ts +13 -0
- package/src/workspace/kinds.ts +12 -3
- package/src/workspace/plan-stale.schema.json +286 -0
- package/src/workspace/release-candidates.schema.json +48 -2
- package/src/workspace/release-candidates.test.ts +77 -4
- package/src/workspace/release-candidates.ts +62 -20
- package/src/workspace/trust/policy.ts +24 -1
- package/src/workspace/trust/run-commits.ts +2 -1
- package/src/workspace/trust/seal.ts +35 -3
- package/src/workspace/trust/trust-files.test.ts +5 -0
- package/src/workspace/trust/trust-files.ts +15 -1
|
@@ -242,8 +242,10 @@ export interface GateResolutionRecord {
|
|
|
242
242
|
/**
|
|
243
243
|
* An ssh signature over this approval by `resolvedBy` (#3163, ws-080):
|
|
244
244
|
* `chant approve --sign`, in the `chant-gate` namespace over the op, gate,
|
|
245
|
-
* environment, plan digest, approver and timestamp.
|
|
246
|
-
*
|
|
245
|
+
* environment, plan digest, approver and timestamp. Or the same made
|
|
246
|
+
* elsewhere, by an ssh key or a passkey, and brought with `chant approve
|
|
247
|
+
* --signature` (#4646). It attests the approver only when the signers file
|
|
248
|
+
* at base lists a key for them, or `.chant/trust.json` a passkey. A gate the
|
|
247
249
|
* declaration's `identity.gates` names counts only approvals whose seal
|
|
248
250
|
* verifies. Absent on an unsigned approval.
|
|
249
251
|
*/
|
|
@@ -291,11 +293,23 @@ export function isGateCarriedFrom(raw: unknown): raw is GateCarriedFrom {
|
|
|
291
293
|
);
|
|
292
294
|
}
|
|
293
295
|
|
|
294
|
-
/**
|
|
296
|
+
/**
|
|
297
|
+
* A gate approval's seal (#3163): who signed, the key's fingerprint (reported,
|
|
298
|
+
* never trusted), and the armored signature. A passkey's seal (#4646) has
|
|
299
|
+
* `kind: "webauthn"`, the credential id as `key`, the assertion's signature
|
|
300
|
+
* (base64url) as `signature`, and its client data and authenticator data, so
|
|
301
|
+
* it can be checked again against the passkey `.chant/trust.json` lists.
|
|
302
|
+
*/
|
|
295
303
|
export interface GateApprovalSeal {
|
|
304
|
+
/** `webauthn` for a passkey's assertion (#4646). Absent on an ssh signature. */
|
|
305
|
+
kind?: "webauthn";
|
|
296
306
|
signer: string;
|
|
297
307
|
key: string;
|
|
298
308
|
signature: string;
|
|
309
|
+
/** A passkey's clientDataJSON, base64url (#4646). */
|
|
310
|
+
clientDataJSON?: string;
|
|
311
|
+
/** A passkey's authenticatorData, base64url (#4646). */
|
|
312
|
+
authenticatorData?: string;
|
|
299
313
|
/**
|
|
300
314
|
* The seal's version (#3947). `2` on a seal over an approval that carries a
|
|
301
315
|
* `checkpointDigest`, whose payload signs the digest as one more line.
|
|
@@ -20,6 +20,9 @@
|
|
|
20
20
|
|
|
21
21
|
import { createHash, createPublicKey, verify, type KeyObject } from "node:crypto";
|
|
22
22
|
import type { Signer } from "../workspace/trust/trust-files";
|
|
23
|
+
import { verifyWebAuthnAssertion, type PasskeySigner } from "./gate-webauthn";
|
|
24
|
+
|
|
25
|
+
export { isWebAuthnAssertion, passkeyPublicKey, verifyWebAuthnAssertion, webAuthnChallenge, type PasskeySigner, type WebAuthnAssertion, type WebAuthnCheck } from "./gate-webauthn";
|
|
23
26
|
|
|
24
27
|
/**
|
|
25
28
|
* The ssh signature namespace of a gate approval's seal (#3163, ws-080), so a
|
|
@@ -248,6 +251,8 @@ export interface GateSigners {
|
|
|
248
251
|
/** Whether a signers file exists at base. False: no seal verifies, so a sealed gate passes nothing. */
|
|
249
252
|
active: boolean;
|
|
250
253
|
signers: Signer[];
|
|
254
|
+
/** The passkeys `.chant/trust.json` lists at base (#4646). Absent: none. */
|
|
255
|
+
passkeys?: PasskeySigner[];
|
|
251
256
|
/** Why the trust config could not be read, when it could not. `active` is false then. */
|
|
252
257
|
problems: string[];
|
|
253
258
|
}
|
|
@@ -269,12 +274,53 @@ export function namespaceAllowed(list: string | undefined, namespace: string): b
|
|
|
269
274
|
return allowed;
|
|
270
275
|
}
|
|
271
276
|
|
|
277
|
+
/** The seal kind of an approval signed with a passkey (#4646). A seal with no `kind` is an ssh signature. */
|
|
278
|
+
export const WEBAUTHN_SEAL_KIND = "webauthn";
|
|
279
|
+
|
|
280
|
+
/** What {@link checkGateSignature} reads: the ssh signers and the passkeys at base. */
|
|
281
|
+
export interface GateSignerKeys {
|
|
282
|
+
signers: readonly Signer[];
|
|
283
|
+
passkeys?: readonly PasskeySigner[];
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/** What {@link checkGateSignature} found. `unlisted`: nothing at base is listed for the principal. */
|
|
287
|
+
export type GateSignatureCheck = { ok: true; key: string } | { ok: false; unlisted: boolean; reason: string };
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Whether `seal`'s signature over `payload` verifies for `principal` with a
|
|
291
|
+
* key listed for them at base (#4646): an ssh signature in the `chant-gate`
|
|
292
|
+
* namespace against the signers file's keys, or, for a seal of kind
|
|
293
|
+
* `webauthn`, an assertion against the passkeys `.chant/trust.json` lists.
|
|
294
|
+
* The one check `chant approve`, the `identity.gates` rule, a sealed gate and
|
|
295
|
+
* `checkGateSeal` all make. Never throws.
|
|
296
|
+
*/
|
|
297
|
+
export function checkGateSignature(keys: GateSignerKeys, principal: string, seal: { signature: string } & Record<string, unknown>, payload: Buffer): GateSignatureCheck {
|
|
298
|
+
const name = normalise(principal);
|
|
299
|
+
if (seal.kind === WEBAUTHN_SEAL_KIND) {
|
|
300
|
+
const passkeys = (keys.passkeys ?? []).filter((p) => normalise(p.principal) === name);
|
|
301
|
+
if (passkeys.length === 0) return { ok: false, unlisted: true, reason: `${principal} has no passkey in .chant/trust.json at base` };
|
|
302
|
+
const assertion = { id: seal.key, clientDataJSON: seal.clientDataJSON, authenticatorData: seal.authenticatorData, signature: seal.signature };
|
|
303
|
+
if (typeof assertion.id !== "string" || typeof assertion.clientDataJSON !== "string" || typeof assertion.authenticatorData !== "string") {
|
|
304
|
+
return { ok: false, unlisted: false, reason: "a webauthn seal needs key (the credential id), clientDataJSON and authenticatorData" };
|
|
305
|
+
}
|
|
306
|
+
const r = verifyWebAuthnAssertion(assertion as { id: string; clientDataJSON: string; authenticatorData: string; signature: string }, payload, passkeys);
|
|
307
|
+
return r.ok ? r : { ok: false, unlisted: false, reason: r.reason };
|
|
308
|
+
}
|
|
309
|
+
if (seal.kind !== undefined) return { ok: false, unlisted: false, reason: `a seal of kind ${JSON.stringify(seal.kind)} is not one this chant reads` };
|
|
310
|
+
const listed = keys.signers.filter((s) => normalise(s.principal) === name);
|
|
311
|
+
if (listed.length === 0) return { ok: false, unlisted: true, reason: `${principal} has no key in the signers file at base` };
|
|
312
|
+
const blobs = listed.filter((s) => namespaceAllowed(s.namespaces, GATE_SEAL_NAMESPACE)).map((s) => Buffer.from(s.key.split(" ")[1] ?? "", "base64"));
|
|
313
|
+
const r = verifySshSignatureWith(seal.signature, payload, GATE_SEAL_NAMESPACE, blobs);
|
|
314
|
+
return r.ok ? r : { ok: false, unlisted: false, reason: r.reason };
|
|
315
|
+
}
|
|
316
|
+
|
|
272
317
|
/**
|
|
273
318
|
* Why this approval does not count toward a sealed gate, or null when it
|
|
274
319
|
* does: its seal verifies, for the approver it names, against a key `signers`
|
|
275
|
-
* lists for that approver in the `chant-gate` namespace
|
|
276
|
-
*
|
|
277
|
-
*
|
|
320
|
+
* lists for that approver in the `chant-gate` namespace, or a passkey
|
|
321
|
+
* `.chant/trust.json` lists for them (#4646). With no signers file at base,
|
|
322
|
+
* nothing counts. The same rule as `sealedApprovalRule` in
|
|
323
|
+
* `../../op/gate-review.ts`.
|
|
278
324
|
*/
|
|
279
325
|
export function gateSealRefusal(signers: GateSigners, a: SealedGateApproval): string | null {
|
|
280
326
|
const where = `${signers.signersPath} at base`;
|
|
@@ -289,10 +335,17 @@ export function gateSealRefusal(signers: GateSigners, a: SealedGateApproval): st
|
|
|
289
335
|
return `the seal on ${what} is malformed: it needs signer and signature`;
|
|
290
336
|
}
|
|
291
337
|
if (normalise(seal.signer) !== normalise(a.resolvedBy)) return `the seal on ${what} is by ${seal.signer}, and its approver is ${a.resolvedBy || "empty"}`;
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
338
|
+
const r = checkGateSignature(signers, a.resolvedBy, seal as { signature: string }, gateSealPayload(a));
|
|
339
|
+
if (r.ok) return null;
|
|
340
|
+
return r.unlisted ? `${a.resolvedBy} has no ${unlistedWhat(seal)} in ${unlistedWhere(seal, where)}, so the seal can't count` : `the seal does not verify for ${a.resolvedBy} against ${where}: ${r.reason}`;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** "key" or "passkey", for a refusal that names what is missing for a seal's kind. */
|
|
344
|
+
export function unlistedWhat(seal: object): string {
|
|
345
|
+
return (seal as { kind?: unknown }).kind === WEBAUTHN_SEAL_KIND ? "passkey" : "key";
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/** Where the missing key would be listed: the signers file, or `.chant/trust.json` for a passkey. */
|
|
349
|
+
export function unlistedWhere(seal: object, signersWhere: string): string {
|
|
350
|
+
return (seal as { kind?: unknown }).kind === WEBAUTHN_SEAL_KIND ? ".chant/trust.json at base" : signersWhere;
|
|
298
351
|
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A gate approval's statement, for a signature made outside chant (#4646).
|
|
3
|
+
*
|
|
4
|
+
* `chant approve --sign` signs `gateSealPayload`'s bytes with an ssh key on
|
|
5
|
+
* the machine running chant. A platform that collects the approval somewhere
|
|
6
|
+
* else (a phone with a passkey, a device key on another machine) needs the
|
|
7
|
+
* same bytes before anything is recorded: `chant approve <op> <gate>
|
|
8
|
+
* --statement` prints them as a `chant-gate-statement/v1` document
|
|
9
|
+
* (`../gate-statement.schema.json`), with the time fixed so the signature and
|
|
10
|
+
* the approval that records it cover the same line. The platform has the
|
|
11
|
+
* person sign them and hands the signature to `chant approve --signature`,
|
|
12
|
+
* with the same `--actor`, `--relayed-by` and `--at`.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { createHash } from "node:crypto";
|
|
16
|
+
import { NEXT_RELEASE } from "../release-floors";
|
|
17
|
+
import { GATE_SEAL_NAMESPACE, gateSealPayload, gateSealVersion, isWebAuthnAssertion, webAuthnChallenge, type SealedGateApproval, type WebAuthnAssertion } from "./gate-seal";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The first chant that prints a gate's statement, records an approval
|
|
21
|
+
* signed elsewhere (`chant approve --signature`), reads `passkeys` in
|
|
22
|
+
* `.chant/trust.json` and verifies a seal of kind `webauthn` (#4646). An
|
|
23
|
+
* older chant reads a trust.json with `passkeys` as invalid, which turns
|
|
24
|
+
* attestation off, and counts no passkey seal toward a gate.
|
|
25
|
+
*/
|
|
26
|
+
export const GATE_EXTERNAL_SIGNATURE_FLOOR = NEXT_RELEASE;
|
|
27
|
+
|
|
28
|
+
export const GATE_STATEMENT_SCHEMA = "chant-gate-statement/v1";
|
|
29
|
+
|
|
30
|
+
/** The `$id` of `../gate-statement.schema.json`, which the package exports as `@intentius/chant/gate-statement.schema.json`. */
|
|
31
|
+
export const GATE_STATEMENT_SCHEMA_ID = "https://intentius.io/chant/schemas/gate-statement/v1/gate-statement.schema.json";
|
|
32
|
+
|
|
33
|
+
/** What `chant approve <op> <gate> --statement` prints. */
|
|
34
|
+
export interface GateStatement {
|
|
35
|
+
schema: typeof GATE_STATEMENT_SCHEMA;
|
|
36
|
+
chantVersion: string;
|
|
37
|
+
op: string;
|
|
38
|
+
gate: string;
|
|
39
|
+
environment: string | null;
|
|
40
|
+
planDigest: string | null;
|
|
41
|
+
resolvedBy: string;
|
|
42
|
+
relayedBy: string | null;
|
|
43
|
+
timestamp: string;
|
|
44
|
+
checkpointDigest: string | null;
|
|
45
|
+
/** 1, or 2 when the statement signs a checkpoint digest. */
|
|
46
|
+
sealVersion: 1 | 2;
|
|
47
|
+
/** The ssh signature namespace an ssh key signs the statement in. */
|
|
48
|
+
namespace: typeof GATE_SEAL_NAMESPACE;
|
|
49
|
+
/** The statement's UTF-8 text, LF-joined with no final newline. */
|
|
50
|
+
text: string;
|
|
51
|
+
/** The same bytes, base64. */
|
|
52
|
+
statement: string;
|
|
53
|
+
/** `sha256:` and the bytes' SHA-256 in hex. */
|
|
54
|
+
digest: string;
|
|
55
|
+
/** The WebAuthn challenge: base64url of the bytes' SHA-256, no padding. */
|
|
56
|
+
challenge: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The statement of approval `a`, as `chant approve --statement` prints it. */
|
|
60
|
+
export function gateStatement(a: SealedGateApproval, chantVersion: string): GateStatement {
|
|
61
|
+
const bytes = gateSealPayload(a);
|
|
62
|
+
return {
|
|
63
|
+
schema: GATE_STATEMENT_SCHEMA,
|
|
64
|
+
chantVersion,
|
|
65
|
+
op: a.op,
|
|
66
|
+
gate: a.gate,
|
|
67
|
+
environment: a.environment ?? null,
|
|
68
|
+
planDigest: a.planDigest ?? null,
|
|
69
|
+
resolvedBy: a.resolvedBy,
|
|
70
|
+
relayedBy: a.relayedBy ?? null,
|
|
71
|
+
timestamp: a.timestamp,
|
|
72
|
+
checkpointDigest: a.checkpointDigest ?? null,
|
|
73
|
+
sealVersion: gateSealVersion(a),
|
|
74
|
+
namespace: GATE_SEAL_NAMESPACE,
|
|
75
|
+
text: bytes.toString("utf-8"),
|
|
76
|
+
statement: bytes.toString("base64"),
|
|
77
|
+
digest: `sha256:${createHash("sha256").update(bytes).digest("hex")}`,
|
|
78
|
+
challenge: webAuthnChallenge(bytes),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** A signature `chant approve --signature` was handed. */
|
|
83
|
+
export type ExternalSignature = { kind: "ssh"; signature: string } | { kind: "webauthn"; assertion: WebAuthnAssertion };
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Read what `--signature` names: an armored ssh signature, or a WebAuthn
|
|
87
|
+
* assertion as JSON, either `{ id, clientDataJSON, authenticatorData,
|
|
88
|
+
* signature }` or a `PublicKeyCredential`'s `toJSON()` with those three
|
|
89
|
+
* under `response`. Returns a problem when it is neither.
|
|
90
|
+
*/
|
|
91
|
+
export function readExternalSignature(text: string): ExternalSignature | { problem: string } {
|
|
92
|
+
const armored = /-----BEGIN SSH SIGNATURE-----[^-]*-----END SSH SIGNATURE-----/.exec(text);
|
|
93
|
+
if (armored) return { kind: "ssh", signature: `${armored[0]}\n` };
|
|
94
|
+
let raw: unknown;
|
|
95
|
+
try {
|
|
96
|
+
raw = JSON.parse(text);
|
|
97
|
+
} catch {
|
|
98
|
+
return { problem: "it is neither an armored ssh signature (-----BEGIN SSH SIGNATURE-----) nor a WebAuthn assertion in JSON" };
|
|
99
|
+
}
|
|
100
|
+
const o = raw as { id?: unknown; response?: Record<string, unknown> } | null;
|
|
101
|
+
const flat = o && typeof o === "object" && o.response && typeof o.response === "object" ? { id: o.id, ...o.response } : raw;
|
|
102
|
+
if (!isWebAuthnAssertion(flat)) {
|
|
103
|
+
return { problem: "a WebAuthn assertion needs id, clientDataJSON, authenticatorData and signature, each base64url" };
|
|
104
|
+
}
|
|
105
|
+
const { id, clientDataJSON, authenticatorData, signature } = flat;
|
|
106
|
+
return { kind: "webauthn", assertion: { id, clientDataJSON, authenticatorData, signature } };
|
|
107
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #4646: a passkey's assertion over a gate's statement, checked with
|
|
3
|
+
* node:crypto. Each assertion is built by hand the way an authenticator
|
|
4
|
+
* builds one: client data, authenticator data, and a signature over
|
|
5
|
+
* authenticatorData || SHA-256(clientDataJSON).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { describe, expect, test } from "vitest";
|
|
9
|
+
import { gateSealPayload, gateSealRefusal, type GateSigners, type SealedGateApproval } from "./gate-seal";
|
|
10
|
+
import { verifyWebAuthnAssertion, webAuthnChallenge, type WebAuthnAssertion } from "./gate-webauthn";
|
|
11
|
+
import { assert, passkey } from "./test-passkey";
|
|
12
|
+
import { readExternalSignature } from "./gate-statement";
|
|
13
|
+
|
|
14
|
+
const approval: SealedGateApproval = {
|
|
15
|
+
op: "deploy",
|
|
16
|
+
gate: "ship",
|
|
17
|
+
environment: "prod",
|
|
18
|
+
planDigest: `sha256:${"a".repeat(64)}`,
|
|
19
|
+
resolvedBy: "github:erin",
|
|
20
|
+
timestamp: "2026-11-01T10:00:00.000Z",
|
|
21
|
+
};
|
|
22
|
+
const statement = gateSealPayload(approval);
|
|
23
|
+
|
|
24
|
+
describe("a passkey's assertion over a gate statement (#4646)", () => {
|
|
25
|
+
test.each(["EdDSA", "ES256"] as const)("verifies with an %s passkey", (alg) => {
|
|
26
|
+
const pk = passkey("github:erin", "cred-erin", alg);
|
|
27
|
+
expect(verifyWebAuthnAssertion(assert(pk, statement), statement, [pk.signer])).toEqual({ ok: true, key: "cred-erin" });
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("refuses what WebAuthn level 2 refuses", () => {
|
|
31
|
+
const pk = passkey("github:erin", "cred-erin");
|
|
32
|
+
const why = (a: WebAuthnAssertion, over: Buffer = statement) => {
|
|
33
|
+
const r = verifyWebAuthnAssertion(a, over, [pk.signer]);
|
|
34
|
+
return r.ok ? null : r.reason;
|
|
35
|
+
};
|
|
36
|
+
expect(why(assert(pk, statement, { type: "webauthn.create" }))).toMatch(/not webauthn\.get/);
|
|
37
|
+
expect(why(assert(pk, statement, { challenge: webAuthnChallenge(Buffer.from("other")) }))).toMatch(/challenge/);
|
|
38
|
+
expect(why(assert(pk, statement, { origin: "https://evil.example" }))).toMatch(/origin "https:\/\/evil\.example"/);
|
|
39
|
+
expect(why(assert(pk, statement, { crossOrigin: true }))).toMatch(/cross-origin/);
|
|
40
|
+
expect(why(assert(pk, statement, { rpId: "evil.example" }))).toMatch(/rpIdHash/);
|
|
41
|
+
expect(why(assert(pk, statement, { flags: 0x01 }))).toMatch(/user-verified/);
|
|
42
|
+
expect(why(assert(pk, statement, { flags: 0x04 }))).toMatch(/user-present/);
|
|
43
|
+
// A different plan digest is a different statement.
|
|
44
|
+
expect(why(assert(pk, statement), gateSealPayload({ ...approval, planDigest: `sha256:${"b".repeat(64)}` }))).toMatch(/challenge/);
|
|
45
|
+
// Another key under the listed id.
|
|
46
|
+
const other = passkey("github:erin", "cred-erin");
|
|
47
|
+
expect(why(assert(other, statement))).toMatch(/does not match/);
|
|
48
|
+
// A credential nobody listed.
|
|
49
|
+
expect(why({ ...assert(pk, statement), id: "cred-unknown" })).toMatch(/does not list/);
|
|
50
|
+
// A signature over other bytes.
|
|
51
|
+
const a = assert(pk, statement);
|
|
52
|
+
expect(why({ ...a, authenticatorData: Buffer.concat([Buffer.from(a.authenticatorData, "base64url"), Buffer.from([1])]).toString("base64url") })).toMatch(/does not match/);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("a sealed gate counts the passkey's seal for its approver only", () => {
|
|
56
|
+
const pk = passkey("github:erin", "cred-erin", "ES256");
|
|
57
|
+
const a = assert(pk, statement);
|
|
58
|
+
const seal = { kind: "webauthn", signer: "github:erin", key: a.id, signature: a.signature, clientDataJSON: a.clientDataJSON, authenticatorData: a.authenticatorData };
|
|
59
|
+
const signers: GateSigners = { base: null, signersPath: ".chant/allowed_signers", active: true, signers: [], passkeys: [pk.signer], problems: [] };
|
|
60
|
+
expect(gateSealRefusal(signers, { ...approval, seal })).toBeNull();
|
|
61
|
+
expect(gateSealRefusal({ ...signers, passkeys: [] }, { ...approval, seal })).toMatch(/has no passkey in \.chant\/trust\.json at base/);
|
|
62
|
+
expect(gateSealRefusal({ ...signers, passkeys: [{ ...pk.signer, principal: "github:frank" }] }, { ...approval, seal })).toMatch(/has no passkey/);
|
|
63
|
+
expect(gateSealRefusal(signers, { ...approval, planDigest: `sha256:${"c".repeat(64)}`, seal })).toMatch(/challenge/);
|
|
64
|
+
expect(gateSealRefusal(signers, { ...approval, seal: { ...seal, kind: "x509" } })).toMatch(/kind "x509"/);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("--signature reads an ssh signature, an assertion, or a PublicKeyCredential's JSON", () => {
|
|
68
|
+
const pk = passkey("github:erin", "cred-erin");
|
|
69
|
+
const a = assert(pk, statement);
|
|
70
|
+
expect(readExternalSignature(JSON.stringify(a))).toEqual({ kind: "webauthn", assertion: a });
|
|
71
|
+
const { id, ...response } = a;
|
|
72
|
+
expect(readExternalSignature(JSON.stringify({ id, rawId: id, type: "public-key", response: { ...response, userHandle: null } }))).toEqual({ kind: "webauthn", assertion: a });
|
|
73
|
+
expect(readExternalSignature("-----BEGIN SSH SIGNATURE-----\nU1NIU0lH\n-----END SSH SIGNATURE-----\n")).toMatchObject({ kind: "ssh" });
|
|
74
|
+
expect(readExternalSignature("{}")).toHaveProperty("problem");
|
|
75
|
+
expect(readExternalSignature("nonsense")).toHaveProperty("problem");
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A gate approval signed with a passkey (#4646): a WebAuthn assertion over
|
|
3
|
+
* the gate's statement, checked with node:crypto.
|
|
4
|
+
*
|
|
5
|
+
* A platform that collects an approval on a phone asks the browser for an
|
|
6
|
+
* assertion (`navigator.credentials.get`) whose challenge is the statement's
|
|
7
|
+
* digest, `base64url(SHA-256(statement))` with no padding, where the
|
|
8
|
+
* statement is `gateSealPayload`'s bytes (`chant approve --statement` prints
|
|
9
|
+
* them). The assertion is relayed to `chant approve --signature`, checked
|
|
10
|
+
* against a passkey `.chant/trust.json` lists at base for the approver, and
|
|
11
|
+
* kept on the approval's seal, so anyone can check it again offline.
|
|
12
|
+
*
|
|
13
|
+
* The check follows WebAuthn level 2, section 7.2, for what can be checked
|
|
14
|
+
* without the relying party's state: the client data's type is
|
|
15
|
+
* `webauthn.get`, its challenge is the statement's, its origin is one the
|
|
16
|
+
* passkey lists and it is not cross-origin; the authenticator data's rpIdHash
|
|
17
|
+
* is SHA-256 of the passkey's rpId and both the user-present and
|
|
18
|
+
* user-verified flags are set; and the signature over authenticatorData ||
|
|
19
|
+
* SHA-256(clientDataJSON) verifies with the passkey's public key. The
|
|
20
|
+
* signature counter is not checked: a ledger line can't know the
|
|
21
|
+
* authenticator's last count.
|
|
22
|
+
*
|
|
23
|
+
* Like `./gate-seal.ts`, this imports node:crypto and nothing else, so a
|
|
24
|
+
* bundled gate decision carries it.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
import { createHash, createPublicKey, verify, type KeyObject } from "node:crypto";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A passkey `.chant/trust.json` lists for a person (#4646): the credential
|
|
31
|
+
* id, its public key, the relying party it was made for, and the origins an
|
|
32
|
+
* assertion may come from.
|
|
33
|
+
*/
|
|
34
|
+
export interface PasskeySigner {
|
|
35
|
+
principal: string;
|
|
36
|
+
/** The credential id (`rawId`), base64url with no padding. */
|
|
37
|
+
id: string;
|
|
38
|
+
/**
|
|
39
|
+
* The credential's public key as DER SubjectPublicKeyInfo, base64url: what
|
|
40
|
+
* `AuthenticatorAttestationResponse.getPublicKey()` gives. Ed25519 (EdDSA),
|
|
41
|
+
* P-256 (ES256) and RSA (RS256) keys verify.
|
|
42
|
+
*/
|
|
43
|
+
publicKey: string;
|
|
44
|
+
/** The relying party id the credential is scoped to, such as `example.com`. */
|
|
45
|
+
rpId: string;
|
|
46
|
+
/** Origins an assertion may come from, such as `https://control.example.com`. */
|
|
47
|
+
origins: string[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** A WebAuthn assertion as a browser returns it, each field base64url. */
|
|
51
|
+
export interface WebAuthnAssertion {
|
|
52
|
+
/** The credential id. */
|
|
53
|
+
id: string;
|
|
54
|
+
clientDataJSON: string;
|
|
55
|
+
authenticatorData: string;
|
|
56
|
+
signature: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** What {@link verifyWebAuthnAssertion} found. On success, `key` is the credential id. */
|
|
60
|
+
export type WebAuthnCheck = { ok: true; key: string } | { ok: false; reason: string };
|
|
61
|
+
|
|
62
|
+
const B64URL = /^[A-Za-z0-9_-]+={0,2}$/;
|
|
63
|
+
|
|
64
|
+
/** Whether `raw` has the shape of a {@link WebAuthnAssertion}. */
|
|
65
|
+
export function isWebAuthnAssertion(raw: unknown): raw is WebAuthnAssertion {
|
|
66
|
+
const a = raw as Partial<Record<keyof WebAuthnAssertion, unknown>> | null;
|
|
67
|
+
return (
|
|
68
|
+
!!a && typeof a === "object" && !Array.isArray(a) &&
|
|
69
|
+
(["id", "clientDataJSON", "authenticatorData", "signature"] as const).every((k) => typeof a[k] === "string" && B64URL.test(a[k] as string))
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The challenge a passkey signs for `statement`: base64url of its SHA-256, no padding. */
|
|
74
|
+
export function webAuthnChallenge(statement: Buffer): string {
|
|
75
|
+
return createHash("sha256").update(statement).digest("base64url");
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The passkey's key and the algorithm its signature is checked with, or why it can't be read. */
|
|
79
|
+
export function passkeyPublicKey(publicKey: string): { key: KeyObject; alg: "EdDSA" | "ES256" | "RS256" } | { problem: string } {
|
|
80
|
+
let key: KeyObject;
|
|
81
|
+
try {
|
|
82
|
+
key = createPublicKey({ key: Buffer.from(publicKey, "base64url"), format: "der", type: "spki" });
|
|
83
|
+
} catch (err) {
|
|
84
|
+
return { problem: `the public key is not a DER SubjectPublicKeyInfo: ${err instanceof Error ? err.message : String(err)}` };
|
|
85
|
+
}
|
|
86
|
+
if (key.asymmetricKeyType === "ed25519") return { key, alg: "EdDSA" };
|
|
87
|
+
if (key.asymmetricKeyType === "ec" && key.asymmetricKeyDetails?.namedCurve === "prime256v1") return { key, alg: "ES256" };
|
|
88
|
+
if (key.asymmetricKeyType === "rsa") return { key, alg: "RS256" };
|
|
89
|
+
return { problem: `a ${key.asymmetricKeyType}${key.asymmetricKeyDetails?.namedCurve ? ` ${key.asymmetricKeyDetails.namedCurve}` : ""} key; a passkey is Ed25519, P-256 or RSA` };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const sameId = (a: string, b: string): boolean => a.replace(/=+$/, "") === b.replace(/=+$/, "");
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Whether `assertion` signs `statement` with one of `passkeys`, chosen by
|
|
96
|
+
* credential id. Never throws.
|
|
97
|
+
*/
|
|
98
|
+
export function verifyWebAuthnAssertion(assertion: WebAuthnAssertion, statement: Buffer, passkeys: readonly PasskeySigner[]): WebAuthnCheck {
|
|
99
|
+
try {
|
|
100
|
+
const pk = passkeys.find((p) => sameId(p.id, assertion.id));
|
|
101
|
+
if (!pk) return { ok: false, reason: `signed by passkey ${assertion.id}, which the policy at base does not list for the approver` };
|
|
102
|
+
const clientData = Buffer.from(assertion.clientDataJSON, "base64url");
|
|
103
|
+
let cd: { type?: unknown; challenge?: unknown; origin?: unknown; crossOrigin?: unknown };
|
|
104
|
+
try {
|
|
105
|
+
cd = JSON.parse(clientData.toString("utf-8"));
|
|
106
|
+
} catch {
|
|
107
|
+
return { ok: false, reason: "its clientDataJSON is not JSON" };
|
|
108
|
+
}
|
|
109
|
+
if (cd.type !== "webauthn.get") return { ok: false, reason: `its client data is a ${JSON.stringify(cd.type)} ceremony, not webauthn.get` };
|
|
110
|
+
if (cd.challenge !== webAuthnChallenge(statement)) return { ok: false, reason: "its challenge is not this approval's statement digest" };
|
|
111
|
+
if (typeof cd.origin !== "string" || !pk.origins.includes(cd.origin)) {
|
|
112
|
+
return { ok: false, reason: `it comes from origin ${JSON.stringify(cd.origin)}, and the passkey allows ${pk.origins.join(", ")}` };
|
|
113
|
+
}
|
|
114
|
+
if (cd.crossOrigin === true) return { ok: false, reason: "it was made in a cross-origin frame" };
|
|
115
|
+
const authData = Buffer.from(assertion.authenticatorData, "base64url");
|
|
116
|
+
if (authData.length < 37) return { ok: false, reason: "its authenticatorData is shorter than 37 bytes" };
|
|
117
|
+
if (!authData.subarray(0, 32).equals(createHash("sha256").update(pk.rpId, "utf-8").digest())) {
|
|
118
|
+
return { ok: false, reason: `its rpIdHash is not SHA-256 of ${pk.rpId}` };
|
|
119
|
+
}
|
|
120
|
+
const flags = authData[32]!;
|
|
121
|
+
if (!(flags & 0x01)) return { ok: false, reason: "the user-present flag is unset" };
|
|
122
|
+
if (!(flags & 0x04)) return { ok: false, reason: "the user-verified flag is unset" };
|
|
123
|
+
const key = passkeyPublicKey(pk.publicKey);
|
|
124
|
+
if ("problem" in key) return { ok: false, reason: `passkey ${pk.id}: ${key.problem}` };
|
|
125
|
+
const signed = Buffer.concat([authData, createHash("sha256").update(clientData).digest()]);
|
|
126
|
+
const signature = Buffer.from(assertion.signature, "base64url");
|
|
127
|
+
// ES256 signatures are ASN.1 DER, node's default for an EC key.
|
|
128
|
+
const ok = verify(key.alg === "EdDSA" ? null : "sha256", signed, key.key, signature);
|
|
129
|
+
return ok ? { ok: true, key: pk.id } : { ok: false, reason: "the signature does not match the signed fields" };
|
|
130
|
+
} catch (err) {
|
|
131
|
+
return { ok: false, reason: err instanceof Error ? err.message : String(err) };
|
|
132
|
+
}
|
|
133
|
+
}
|
package/src/lifecycle/git.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { getRuntime } from "../runtime-adapter";
|
|
|
10
10
|
import { memberLedgerPrefix, resolveMemberLedger } from "./member-ledger";
|
|
11
11
|
import { LIFECYCLE_LOCAL_NOTE } from "./local-note";
|
|
12
12
|
import { ledgerRecordingOff, NO_RECORD_PUSH_NOTE, overlayTip, setOverlayTip } from "./no-record";
|
|
13
|
+
import { chooseLedgerRemote, lifecycleRemoteOverride, type LedgerRemoteChoice } from "./ledger-remote";
|
|
13
14
|
import type { LedgerReadPort } from "./ledger-port";
|
|
14
15
|
|
|
15
16
|
const STATE_BRANCH = "chant/lifecycle";
|
|
@@ -819,7 +820,7 @@ export async function pushLifecycleStatus(opts?: { cwd?: string }): Promise<Life
|
|
|
819
820
|
const cwd = opts?.cwd;
|
|
820
821
|
const found = await ledgerRemote(cwd);
|
|
821
822
|
if (found === null) return { status: "no-remote" };
|
|
822
|
-
if ("failed" in found) return { status: "failed", remote: "(unknown)", stderr: found.stderr };
|
|
823
|
+
if ("failed" in found) return { status: "failed", remote: found.named ?? "(unknown)", stderr: found.stderr };
|
|
823
824
|
const { remote } = found;
|
|
824
825
|
|
|
825
826
|
// Capture the lease SHA — if null, the remote ref doesn't exist yet
|
|
@@ -859,7 +860,7 @@ export async function pushLifecycleStatus(opts?: { cwd?: string }): Promise<Life
|
|
|
859
860
|
* Returns false (without throwing) when no remote is configured, or when git
|
|
860
861
|
* refused the push for a reason other than a stale lease.
|
|
861
862
|
*
|
|
862
|
-
* The remote is the ledger's ({@link ledgerRemote}: `
|
|
863
|
+
* The remote is the ledger's ({@link ledgerRemote}: the one `CHANT_LIFECYCLE_REMOTE` names, else `origin`),
|
|
863
864
|
* the same one {@link fetchLifecycleStatus} reads, and a push that lands
|
|
864
865
|
* records the tip it pushed as the remote-tracking ref, so the next push's
|
|
865
866
|
* lease is right in a single-branch clone too (#3391).
|
|
@@ -1165,21 +1166,21 @@ const NON_FAST_FORWARD_RE = /non-fast-forward|rejected/i;
|
|
|
1165
1166
|
const C_LOCALE_ENV = { LC_ALL: "C", LANGUAGE: "" };
|
|
1166
1167
|
|
|
1167
1168
|
/**
|
|
1168
|
-
* The remote the ledger lives on.
|
|
1169
|
+
* The remote the ledger lives on ({@link chooseLedgerRemote}).
|
|
1169
1170
|
*
|
|
1170
|
-
* `
|
|
1171
|
-
*
|
|
1172
|
-
*
|
|
1173
|
-
*
|
|
1174
|
-
*
|
|
1171
|
+
* The one `CHANT_LIFECYCLE_REMOTE` names (#4647), else `origin` when it
|
|
1172
|
+
* exists, rather than whichever name sorts first — a repo with a `backup`
|
|
1173
|
+
* remote alongside `origin` would otherwise fetch the ledger from `backup`.
|
|
1174
|
+
* A non-zero exit is *not* read as "no remote": a git that failed to answer
|
|
1175
|
+
* is not evidence that a project is single-machine, and treating it as one is
|
|
1176
|
+
* what lets an unreadable ledger look empty. Nor is a named remote the
|
|
1177
|
+
* repository lacks.
|
|
1175
1178
|
*/
|
|
1176
|
-
async function ledgerRemote(cwd?: string): Promise<
|
|
1179
|
+
async function ledgerRemote(cwd?: string): Promise<LedgerRemoteChoice> {
|
|
1177
1180
|
const rt = getRuntime();
|
|
1178
1181
|
const result = await rt.spawn(["git", "remote"], { cwd, env: C_LOCALE_ENV });
|
|
1179
1182
|
if (result.exitCode !== 0) return { failed: true, stderr: (result.stderr ?? "").trim() };
|
|
1180
|
-
|
|
1181
|
-
if (names.length === 0) return null;
|
|
1182
|
-
return { remote: names.includes("origin") ? "origin" : names[0] };
|
|
1183
|
+
return chooseLedgerRemote(result.stdout.trim().split("\n").map((n) => n.trim()).filter(Boolean));
|
|
1183
1184
|
}
|
|
1184
1185
|
|
|
1185
1186
|
/** A scratch ref this module owns, used to resolve the remote tip without touching the ledger branch. */
|
|
@@ -1208,7 +1209,7 @@ export async function fetchLifecycleStatus(opts?: { cwd?: string }): Promise<Lif
|
|
|
1208
1209
|
const found = await ledgerRemote(cwd);
|
|
1209
1210
|
if (found === null) return { status: "no-remote" };
|
|
1210
1211
|
if ("failed" in found) {
|
|
1211
|
-
return { status: "unreachable", remote: "(unknown)", stderr: found.stderr };
|
|
1212
|
+
return { status: "unreachable", remote: found.named ?? "(unknown)", stderr: found.stderr };
|
|
1212
1213
|
}
|
|
1213
1214
|
const { remote } = found;
|
|
1214
1215
|
|
|
@@ -1560,9 +1561,11 @@ export async function pushRefStatus(ref: string, opts?: { cwd?: string; expect?:
|
|
|
1560
1561
|
// The lease still holds in this checkout, the way it does in one with no remote.
|
|
1561
1562
|
if (ledgerRecordingOff()) return "no-remote";
|
|
1562
1563
|
const rt = getRuntime();
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1564
|
+
// #4647: the ledger's remote, so a lease ref goes where the branch does.
|
|
1565
|
+
const found = await ledgerRemote(opts?.cwd);
|
|
1566
|
+
if (found === null) return "no-remote";
|
|
1567
|
+
if ("failed" in found) return lifecycleRemoteOverride() === undefined ? "no-remote" : "rejected";
|
|
1568
|
+
const { remote } = found;
|
|
1566
1569
|
|
|
1567
1570
|
let expected: string | null;
|
|
1568
1571
|
if (opts?.expect !== undefined) {
|
|
@@ -1618,9 +1621,10 @@ export async function fetchRefIntoStatus(
|
|
|
1618
1621
|
opts?: { cwd?: string },
|
|
1619
1622
|
): Promise<FetchRefStatus> {
|
|
1620
1623
|
const rt = getRuntime();
|
|
1621
|
-
const
|
|
1622
|
-
if (
|
|
1623
|
-
|
|
1624
|
+
const found = await ledgerRemote(opts?.cwd);
|
|
1625
|
+
if (found === null) return "no-remote";
|
|
1626
|
+
if ("failed" in found) return lifecycleRemoteOverride() === undefined ? "no-remote" : "failed";
|
|
1627
|
+
const { remote } = found;
|
|
1624
1628
|
const fetchResult = await rt.spawn(["git", "fetch", remote, `+${remoteRef}:${localRef}`], { cwd: opts?.cwd, env: C_LOCALE_ENV });
|
|
1625
1629
|
if (fetchResult.exitCode === 0) return "fetched";
|
|
1626
1630
|
return NO_SUCH_REMOTE_REF_RE.test(fetchResult.stderr ?? "") ? "missing" : "failed";
|