owenloop 0.4.1 → 0.5.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/CHANGELOG.md +71 -0
- package/README.md +182 -53
- package/bin/owenloop.mjs +50 -2
- package/dist/packages/work/src/agent/brief.d.ts +176 -0
- package/dist/packages/work/src/agent/brief.js +197 -0
- package/dist/packages/work/src/agent/loop.d.ts +141 -0
- package/dist/packages/work/src/agent/loop.js +669 -0
- package/dist/packages/work/src/agent/model-policy.d.ts +49 -0
- package/dist/packages/work/src/agent/model-policy.js +138 -0
- package/dist/packages/work/src/agent/workdir.d.ts +210 -0
- package/dist/packages/work/src/agent/workdir.js +319 -0
- package/dist/packages/work/src/bundle/cache.d.ts +92 -0
- package/dist/packages/work/src/bundle/cache.js +338 -0
- package/dist/packages/work/src/bundle/fetch.d.ts +87 -0
- package/dist/packages/work/src/bundle/fetch.js +345 -0
- package/dist/packages/work/src/bundle/types.d.ts +164 -0
- package/dist/packages/work/src/bundle/types.js +1 -0
- package/dist/packages/work/src/consumed-verifier.d.ts +45 -0
- package/dist/packages/work/src/consumed-verifier.js +205 -0
- package/dist/packages/work/src/credentials/owenloop.d.ts +11 -0
- package/dist/packages/work/src/credentials/owenloop.js +28 -0
- package/dist/packages/work/src/credentials/reader.d.ts +36 -0
- package/dist/packages/work/src/credentials/reader.js +32 -0
- package/dist/packages/work/src/credentials/resolve.d.ts +19 -0
- package/dist/packages/work/src/credentials/resolve.js +56 -0
- package/dist/packages/work/src/exec/instructions.d.ts +99 -0
- package/dist/packages/work/src/exec/instructions.js +323 -0
- package/dist/packages/work/src/exec/loop.d.ts +40 -0
- package/dist/packages/work/src/exec/loop.js +332 -0
- package/dist/packages/work/src/exec/payload.d.ts +29 -0
- package/dist/packages/work/src/exec/payload.js +54 -0
- package/dist/packages/work/src/exec/receipt.d.ts +41 -0
- package/dist/packages/work/src/exec/receipt.js +32 -0
- package/dist/packages/work/src/exec/runner.d.ts +71 -0
- package/dist/packages/work/src/exec/runner.js +256 -0
- package/dist/packages/work/src/harness/child-env.d.ts +100 -0
- package/dist/packages/work/src/harness/child-env.js +134 -0
- package/dist/packages/work/src/harness/claude.d.ts +140 -0
- package/dist/packages/work/src/harness/claude.js +837 -0
- package/dist/packages/work/src/harness/codex.d.ts +111 -0
- package/dist/packages/work/src/harness/codex.js +1024 -0
- package/dist/packages/work/src/harness/contract.d.ts +308 -0
- package/dist/packages/work/src/harness/contract.js +32 -0
- package/dist/packages/work/src/harness/fake.d.ts +59 -0
- package/dist/packages/work/src/harness/fake.js +91 -0
- package/dist/packages/work/src/harness/jsonrpc-stdio.d.ts +108 -0
- package/dist/packages/work/src/harness/jsonrpc-stdio.js +351 -0
- package/dist/packages/work/src/harness/permissions.d.ts +75 -0
- package/dist/packages/work/src/harness/permissions.js +182 -0
- package/dist/packages/work/src/harness/registry.d.ts +47 -0
- package/dist/packages/work/src/harness/registry.js +45 -0
- package/dist/packages/work/src/harness/session-store.d.ts +181 -0
- package/dist/packages/work/src/harness/session-store.js +523 -0
- package/dist/packages/work/src/harness/types.d.ts +29 -0
- package/dist/packages/work/src/harness/types.js +14 -0
- package/dist/packages/work/src/harnesses.d.ts +38 -0
- package/dist/packages/work/src/harnesses.js +38 -0
- package/dist/packages/work/src/hold/loop.d.ts +36 -0
- package/dist/packages/work/src/hold/loop.js +23 -0
- package/dist/packages/work/src/hold/mcp.d.ts +75 -0
- package/dist/packages/work/src/hold/mcp.js +264 -0
- package/dist/packages/work/src/hub/client.d.ts +23 -0
- package/dist/packages/work/src/hub/client.js +91 -0
- package/dist/packages/work/src/hub/types.d.ts +326 -0
- package/dist/packages/work/src/hub/types.js +26 -0
- package/dist/packages/work/src/lease/loop.d.ts +94 -0
- package/dist/packages/work/src/lease/loop.js +277 -0
- package/dist/packages/work/src/main.d.ts +1 -0
- package/dist/packages/work/src/main.js +48 -0
- package/dist/packages/work/src/mcp/server.d.ts +125 -0
- package/dist/packages/work/src/mcp/server.js +320 -0
- package/dist/packages/work/src/owenloop-bin.d.ts +1 -0
- package/dist/packages/work/src/owenloop-bin.js +18 -0
- package/dist/packages/work/src/roles/agent-run.d.ts +124 -0
- package/dist/packages/work/src/roles/agent-run.js +529 -0
- package/dist/packages/work/src/roles/exec.d.ts +48 -0
- package/dist/packages/work/src/roles/exec.js +228 -0
- package/dist/packages/work/src/roles/hold.d.ts +72 -0
- package/dist/packages/work/src/roles/hold.js +363 -0
- package/dist/packages/work/src/roles/join.d.ts +18 -0
- package/dist/packages/work/src/roles/join.js +204 -0
- package/dist/packages/work/src/roles/lint.d.ts +58 -0
- package/dist/packages/work/src/roles/lint.js +234 -0
- package/dist/packages/work/src/roles/prepare.d.ts +1 -0
- package/dist/packages/work/src/roles/prepare.js +249 -0
- package/dist/packages/work/src/roles/release.d.ts +48 -0
- package/dist/packages/work/src/roles/release.js +137 -0
- package/dist/packages/work/src/roles/sessions.d.ts +61 -0
- package/dist/packages/work/src/roles/sessions.js +180 -0
- package/dist/packages/work/src/roles/settings.d.ts +6 -0
- package/dist/packages/work/src/roles/settings.js +71 -0
- package/dist/packages/work/src/roles/shift.d.ts +13 -0
- package/dist/packages/work/src/roles/shift.js +250 -0
- package/dist/packages/work/src/roles/signals.d.ts +55 -0
- package/dist/packages/work/src/roles/signals.js +62 -0
- package/dist/packages/work/src/settings/provision.d.ts +21 -0
- package/dist/packages/work/src/settings/provision.js +47 -0
- package/dist/packages/work/src/settings/settings.d.ts +136 -0
- package/dist/packages/work/src/settings/settings.js +155 -0
- package/dist/packages/work/src/shift/client.d.ts +24 -0
- package/dist/packages/work/src/shift/client.js +124 -0
- package/dist/packages/work/src/shift/loop.d.ts +131 -0
- package/dist/packages/work/src/shift/loop.js +751 -0
- package/dist/packages/work/src/shift/protocol.d.ts +95 -0
- package/dist/packages/work/src/shift/protocol.js +24 -0
- package/dist/packages/work/src/shift/routing.d.ts +35 -0
- package/dist/packages/work/src/shift/routing.js +50 -0
- package/dist/packages/work/src/shift/runtime.d.ts +45 -0
- package/dist/packages/work/src/shift/runtime.js +337 -0
- package/dist/packages/work/src/shift/server.d.ts +23 -0
- package/dist/packages/work/src/shift/server.js +716 -0
- package/dist/packages/work/src/shift/spawn.d.ts +109 -0
- package/dist/packages/work/src/shift/spawn.js +158 -0
- package/dist/packages/work/src/shift/state.d.ts +79 -0
- package/dist/packages/work/src/shift/state.js +385 -0
- package/dist/packages/work/src/submit-proof.d.ts +36 -0
- package/dist/packages/work/src/submit-proof.js +93 -0
- package/dist/packages/work/src/usage.d.ts +6 -0
- package/dist/packages/work/src/usage.js +175 -0
- package/dist/src/add.d.ts +189 -0
- package/dist/src/add.js +300 -0
- package/dist/src/archive.d.ts +97 -0
- package/dist/src/archive.js +591 -0
- package/dist/src/bundle/index.d.ts +64 -0
- package/dist/src/bundle/index.js +508 -0
- package/dist/src/bundle/manifest.d.ts +50 -0
- package/dist/src/bundle/manifest.js +435 -0
- package/dist/src/bundle/runtime.d.ts +26 -0
- package/dist/src/bundle/runtime.js +64 -0
- package/dist/src/bundle/tar.d.ts +62 -0
- package/dist/src/bundle/tar.js +238 -0
- package/dist/src/bundle/types.d.ts +105 -0
- package/dist/src/bundle/types.js +21 -0
- package/dist/{cli.d.ts → src/cli.d.ts} +92 -7
- package/dist/src/cli.js +5968 -0
- package/dist/{credentials.d.ts → src/credentials.d.ts} +22 -15
- package/dist/{credentials.js → src/credentials.js} +35 -31
- package/dist/src/crypto/allowed-signers.d.ts +68 -0
- package/dist/src/crypto/allowed-signers.js +307 -0
- package/dist/src/crypto/canonical.d.ts +8 -0
- package/dist/src/crypto/canonical.js +92 -0
- package/dist/src/crypto/chain.d.ts +65 -0
- package/dist/src/crypto/chain.js +377 -0
- package/dist/src/crypto/dsse.d.ts +209 -0
- package/dist/src/crypto/dsse.js +282 -0
- package/dist/src/crypto/enrollment.d.ts +78 -0
- package/dist/src/crypto/enrollment.js +186 -0
- package/dist/src/crypto/index.d.ts +48 -0
- package/dist/src/crypto/index.js +44 -0
- package/dist/src/crypto/keys.d.ts +258 -0
- package/dist/src/crypto/keys.js +908 -0
- package/dist/src/crypto/org-root.d.ts +33 -0
- package/dist/src/crypto/org-root.js +78 -0
- package/dist/src/crypto/origin-rules.d.ts +56 -0
- package/dist/src/crypto/origin-rules.js +143 -0
- package/dist/src/crypto/policy-floor.d.ts +98 -0
- package/dist/src/crypto/policy-floor.js +353 -0
- package/dist/src/crypto/records.d.ts +316 -0
- package/dist/src/crypto/records.js +157 -0
- package/dist/src/crypto/scope.d.ts +49 -0
- package/dist/src/crypto/scope.js +83 -0
- package/dist/src/crypto/ssh.d.ts +171 -0
- package/dist/src/crypto/ssh.js +396 -0
- package/dist/src/crypto/submission.d.ts +33 -0
- package/dist/src/crypto/submission.js +47 -0
- package/dist/src/crypto/trust-roots.d.ts +29 -0
- package/dist/src/crypto/trust-roots.js +39 -0
- package/dist/src/crypto/verify-consumed.d.ts +67 -0
- package/dist/src/crypto/verify-consumed.js +259 -0
- package/dist/src/crypto/verify-origin.d.ts +50 -0
- package/dist/src/crypto/verify-origin.js +151 -0
- package/dist/src/crypto/verify-publication.d.ts +60 -0
- package/dist/src/crypto/verify-publication.js +150 -0
- package/dist/{defs.d.ts → src/defs.d.ts} +24 -1
- package/dist/{defs.js → src/defs.js} +181 -61
- package/dist/{engine.d.ts → src/engine.d.ts} +105 -9
- package/dist/{engine.js → src/engine.js} +251 -47
- package/dist/{factory.d.ts → src/factory.d.ts} +16 -0
- package/dist/{factory.js → src/factory.js} +16 -4
- package/dist/src/global-config.d.ts +59 -0
- package/dist/src/global-config.js +84 -0
- package/dist/{hub.d.ts → src/hub.d.ts} +280 -31
- package/dist/{hub.js → src/hub.js} +493 -52
- package/dist/src/index.d.ts +47 -0
- package/dist/src/index.js +41 -0
- package/dist/src/install.d.ts +538 -0
- package/dist/src/install.js +1981 -0
- package/dist/src/lock.d.ts +38 -0
- package/dist/src/lock.js +325 -0
- package/dist/src/mcp/serve.d.ts +109 -0
- package/dist/{mcp → src/mcp}/serve.js +335 -75
- package/dist/{mcp → src/mcp}/server.d.ts +6 -9
- package/dist/{mcp → src/mcp}/server.js +18 -10
- package/dist/{model.d.ts → src/model.d.ts} +15 -0
- package/dist/{model.js → src/model.js} +112 -2
- package/dist/src/order-resolver.d.ts +184 -0
- package/dist/src/order-resolver.js +252 -0
- package/dist/src/package-version.d.ts +10 -0
- package/dist/src/package-version.js +42 -0
- package/dist/{paths.d.ts → src/paths.d.ts} +14 -1
- package/dist/{paths.js → src/paths.js} +18 -0
- package/dist/src/schemas/enrollment-grant.v1.schema.json +90 -0
- package/dist/src/schemas/index.d.ts +1416 -0
- package/dist/src/schemas/index.js +31 -0
- package/dist/src/schemas/order.v1.schema.json +106 -0
- package/dist/src/schemas/origin.v1.schema.json +68 -0
- package/dist/src/schemas/policy-floor.v1.schema.json +29 -0
- package/dist/src/schemas/publication.v1.schema.json +31 -0
- package/dist/src/schemas/revocation.v1.schema.json +39 -0
- package/dist/src/schemas/submission.v1.schema.json +61 -0
- package/dist/src/store/def-source.d.ts +52 -0
- package/dist/src/store/def-source.js +335 -0
- package/dist/src/store/index-file.d.ts +69 -0
- package/dist/src/store/index-file.js +151 -0
- package/dist/src/store/index.d.ts +27 -0
- package/dist/src/store/index.js +22 -0
- package/dist/src/store/ingestor.d.ts +43 -0
- package/dist/src/store/ingestor.js +211 -0
- package/dist/src/store/install.d.ts +228 -0
- package/dist/src/store/install.js +555 -0
- package/dist/src/store/instruction-source.d.ts +49 -0
- package/dist/src/store/instruction-source.js +298 -0
- package/dist/src/store/origin-evidence.d.ts +21 -0
- package/dist/src/store/origin-evidence.js +66 -0
- package/dist/src/store/pre-commit-verifier.d.ts +68 -0
- package/dist/src/store/pre-commit-verifier.js +418 -0
- package/dist/src/store/resolve.d.ts +138 -0
- package/dist/src/store/resolve.js +363 -0
- package/dist/src/store/types.d.ts +288 -0
- package/dist/src/store/types.js +356 -0
- package/dist/{types.d.ts → src/types.d.ts} +58 -24
- package/dist/{untar.d.ts → src/untar.d.ts} +8 -23
- package/dist/src/untar.js +38 -0
- package/dist/{util.d.ts → src/util.d.ts} +3 -2
- package/dist/{util.js → src/util.js} +3 -2
- package/dist/{owenwork.d.ts → src/work-settings.d.ts} +22 -22
- package/dist/{owenwork.js → src/work-settings.js} +27 -27
- package/docs/agent-runner.md +86 -0
- package/docs/authoring.md +150 -59
- package/docs/bundles.md +250 -0
- package/docs/cli.md +1758 -163
- package/docs/crypto.md +816 -0
- package/docs/design.md +374 -52
- package/docs/embedding.md +135 -27
- package/docs/wire-contracts.md +380 -0
- package/examples/workflows/{command-worker.yaml → command-executor.yaml} +15 -15
- package/examples/workflows/compile-dev-playbook.yaml +338 -0
- package/examples/workflows/judges/gate-sharpness.md +39 -0
- package/examples/workflows/judges/security.md +34 -0
- package/package.json +22 -8
- package/plugins/claude-code/.claude-plugin/marketplace.json +14 -0
- package/plugins/claude-code/plugin/.claude-plugin/plugin.json +8 -0
- package/plugins/claude-code/plugin/.mcp.json +14 -0
- package/plugins/claude-code/plugin/hooks/hooks.json +26 -0
- package/plugins/claude-code/plugin/hooks/session-end.sh +40 -0
- package/plugins/claude-code/plugin/hooks/session-start.sh +52 -0
- package/plugins/claude-code/plugin/skills/author/SKILL.md +181 -0
- package/plugins/claude-code/plugin/skills/conduct/SKILL.md +106 -0
- package/plugins/claude-code/plugin/skills/shift/SKILL.md +105 -0
- package/plugins/codex/.agents/plugins/marketplace.json +21 -0
- package/plugins/codex/plugins/owenloop/.codex-plugin/plugin.json +7 -0
- package/plugins/codex/plugins/owenloop/.mcp.json +20 -0
- package/plugins/codex/plugins/owenloop/hooks/hooks.json +26 -0
- package/plugins/codex/plugins/owenloop/hooks/session-end.sh +40 -0
- package/plugins/codex/plugins/owenloop/hooks/session-start.sh +52 -0
- package/plugins/codex/plugins/owenloop/skills/author/SKILL.md +181 -0
- package/plugins/codex/plugins/owenloop/skills/conduct/SKILL.md +106 -0
- package/plugins/codex/plugins/owenloop/skills/shift/SKILL.md +105 -0
- package/dist/add.d.ts +0 -384
- package/dist/add.js +0 -834
- package/dist/cli.js +0 -3270
- package/dist/index.d.ts +0 -32
- package/dist/index.js +0 -23
- package/dist/lock.d.ts +0 -80
- package/dist/lock.js +0 -217
- package/dist/mcp/serve.d.ts +0 -84
- package/dist/untar.js +0 -164
- /package/dist/{schema.d.ts → src/schema.d.ts} +0 -0
- /package/dist/{schema.js → src/schema.js} +0 -0
- /package/dist/{store.d.ts → src/store.d.ts} +0 -0
- /package/dist/{store.js → src/store.js} +0 -0
- /package/dist/{types.js → src/types.js} +0 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DSSE (Dead Simple Signing Envelope) — cryptographic framing for owenloop's
|
|
3
|
+
* signed records.
|
|
4
|
+
*
|
|
5
|
+
* Implements the DSSEv1 protocol (https://github.com/secure-systems-lab/dsse):
|
|
6
|
+
* a `{ payloadType, payload, signatures }` envelope where each signature covers
|
|
7
|
+
* the Pre-Authentication Encoding (PAE) of payload type + payload bytes. PAE
|
|
8
|
+
* binds the payload type INTO the signed data, so a payload signed under one
|
|
9
|
+
* record class can never verify as another — the record-class wrappers below
|
|
10
|
+
* enforce that on top of the generic verify.
|
|
11
|
+
*
|
|
12
|
+
* Scope is deliberately cryptographic framing ONLY: payloads are opaque bytes
|
|
13
|
+
* here — this module never parses or re-serializes them, and owns none of the
|
|
14
|
+
* grant/revocation/submission/policy-floor/origin JSON schemas (that is the
|
|
15
|
+
* WP-A1/WP-A3/WP-B1 surface). Signing and verification run through the
|
|
16
|
+
* `Signer` interface, so the envelope code is format-neutral: today the SSH
|
|
17
|
+
* signer implements it; a future Sigstore signer can implement the same
|
|
18
|
+
* contract without touching this file.
|
|
19
|
+
*
|
|
20
|
+
* Base64 discipline: `payload`/`sig` fields are STANDARD RFC 4648 on the wire
|
|
21
|
+
* (what `dsseSignEnvelope` emits), but verification accepts standard OR
|
|
22
|
+
* URL-safe input (the protocol requires accepting both). Decoding is STRICT —
|
|
23
|
+
* Node's `Buffer.from(.., 'base64')` is permissive (it drops unknown
|
|
24
|
+
* characters and ignores bad padding), so `decodeBase64` validates the
|
|
25
|
+
* alphabet and padding explicitly and rejects malformed encodings rather than
|
|
26
|
+
* silently truncating them into a different payload.
|
|
27
|
+
*
|
|
28
|
+
* `keyid` discipline: `keyid` is optional and UNAUTHENTICATED in DSSE. This
|
|
29
|
+
* module treats it as a candidate-selection hint only — never as identity or
|
|
30
|
+
* authorization. Absent and empty-string `keyid` are treated identically.
|
|
31
|
+
*/
|
|
32
|
+
import type { DetachedSignature, Signer, VerifiedSignature } from './ssh.ts';
|
|
33
|
+
/**
|
|
34
|
+
* The DSSE protocol version string and PAE prefix. PAE is defined as
|
|
35
|
+
* `"DSSEv1" SP len(payloadType) SP payloadType SP len(payload) SP payload`
|
|
36
|
+
* with ASCII-decimal lengths (no leading zeroes) over the UTF-8 byte length of
|
|
37
|
+
* the type and the raw byte length of the payload.
|
|
38
|
+
*/
|
|
39
|
+
export declare const DSSE_VERSION = "DSSEv1";
|
|
40
|
+
/** One signature entry inside a DSSE envelope. `keyid` is optional and unauthenticated. */
|
|
41
|
+
export interface DsseSignature {
|
|
42
|
+
/** Optional candidate-selection hint. NEVER trusted as identity. */
|
|
43
|
+
keyid?: string;
|
|
44
|
+
/** Base64 (standard or URL-safe) of the signature bytes. */
|
|
45
|
+
sig: string;
|
|
46
|
+
/** Unknown fields are tolerated by the decoder. */
|
|
47
|
+
[field: string]: unknown;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A DSSE envelope as it travels on the wire. `payload` and `sig` fields are
|
|
51
|
+
* Base64 text; everything else the decoder needs is typed here, and unknown
|
|
52
|
+
* fields pass through untouched.
|
|
53
|
+
*/
|
|
54
|
+
export interface DsseEnvelope {
|
|
55
|
+
/** Base64 (standard or URL-safe) of the raw payload bytes. */
|
|
56
|
+
payload: string;
|
|
57
|
+
/** The payload's media type, e.g. `application/vnd.owenloop.origin.v1+json`. */
|
|
58
|
+
payloadType: string;
|
|
59
|
+
/** One or more signatures (verification threshold configurable). */
|
|
60
|
+
signatures: DsseSignature[];
|
|
61
|
+
/** Unknown fields are tolerated by the decoder. */
|
|
62
|
+
[field: string]: unknown;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A malformed envelope — wrong shape, bad Base64, missing required fields.
|
|
66
|
+
* A cryptographic miss (wrong key / tampered bytes) is also a hard verification
|
|
67
|
+
* failure: `dsseVerifyEnvelope` throws this error instead of returning a result
|
|
68
|
+
* whose empty payload could be mistaken for a verified empty payload.
|
|
69
|
+
*/
|
|
70
|
+
export declare class DsseEnvelopeError extends Error {
|
|
71
|
+
constructor(message: string);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The six launch signed-record payload types. These strings are signed wire
|
|
75
|
+
* identifiers — versioned, stable, and consumed by later trust work, so a
|
|
76
|
+
* change here is a new `v2` constant, never an edit.
|
|
77
|
+
*/
|
|
78
|
+
export declare const PAYLOAD_TYPE_ENROLLMENT_GRANT = "application/vnd.owenloop.enrollment-grant.v1+json";
|
|
79
|
+
export declare const PAYLOAD_TYPE_REVOCATION = "application/vnd.owenloop.revocation.v1+json";
|
|
80
|
+
export declare const PAYLOAD_TYPE_SUBMISSION = "application/vnd.owenloop.submission.v1+json";
|
|
81
|
+
export declare const PAYLOAD_TYPE_POLICY_FLOOR = "application/vnd.owenloop.policy-floor.v1+json";
|
|
82
|
+
export declare const PAYLOAD_TYPE_ORIGIN = "application/vnd.owenloop.origin.v1+json";
|
|
83
|
+
export declare const PAYLOAD_TYPE_PUBLICATION = "application/vnd.owenloop.publication.v1+json";
|
|
84
|
+
/** The DSSE SSHSIG namespace used for all owenloop DSSE envelopes. */
|
|
85
|
+
export declare const DSSE_SSH_NAMESPACE = "owenloop-dsse-v1";
|
|
86
|
+
/**
|
|
87
|
+
* The Pre-Authentication Encoding of one (payloadType, payload) pair:
|
|
88
|
+
* `DSSEv1 SP len(typeBytes) SP typeBytes SP len(payloadBytes) SP payloadBytes`.
|
|
89
|
+
* Lengths are ASCII decimal (no leading zeroes) byte counts; the payload type
|
|
90
|
+
* is measured in UTF-8 bytes. The result is the exact byte string every DSSE
|
|
91
|
+
* signature covers.
|
|
92
|
+
*/
|
|
93
|
+
export declare function preAuthEncode(payloadType: string, payload: Buffer): Buffer;
|
|
94
|
+
/**
|
|
95
|
+
* Decode a STRICT Base64 string (standard `+/` or URL-safe `-_` alphabet,
|
|
96
|
+
* optional `=` padding). Throws `DsseEnvelopeError` on any malformed input:
|
|
97
|
+
* out-of-alphabet characters, wrong length modulo 4, or a trailing single
|
|
98
|
+
* padding character (three encoded characters never encode a whole byte
|
|
99
|
+
* count). Node's permissive decoder is never used on untrusted wire input —
|
|
100
|
+
* it would silently drop illegal characters and accept missing padding,
|
|
101
|
+
* decoding two different strings to the same bytes.
|
|
102
|
+
*/
|
|
103
|
+
export declare function decodeBase64Strict(s: string, opts?: {
|
|
104
|
+
allowEmpty?: boolean;
|
|
105
|
+
}): Buffer;
|
|
106
|
+
/** Encode bytes as STANDARD (RFC 4648 §4) Base64 with padding. */
|
|
107
|
+
export declare function encodeBase64(b: Buffer): string;
|
|
108
|
+
/** Result of a DSSE verification. */
|
|
109
|
+
export interface DsseVerifyResult {
|
|
110
|
+
/** The EXACT verified payload bytes — never re-parsed or re-serialized. */
|
|
111
|
+
payloadBytes: Buffer;
|
|
112
|
+
/** Descriptors of every signature that verified (deduplicated by the signer). */
|
|
113
|
+
signers: VerifiedSignature[];
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Verify a DSSE envelope with a format-neutral `Signer`.
|
|
117
|
+
*
|
|
118
|
+
* Verification order (fixed):
|
|
119
|
+
* 1. Decode — the envelope object shape, payload Base64, and each `sig`.
|
|
120
|
+
* 2. Reconstruct the PAE from the envelope's EXACT payload type and payload
|
|
121
|
+
* bytes.
|
|
122
|
+
* 3. Verify signatures through the signer; require at least `threshold`
|
|
123
|
+
* DISTINCT verified signers (the signer deduplicates: a trusted key
|
|
124
|
+
* counts once even when duplicate signature entries validate).
|
|
125
|
+
* 4. Require `payloadType === expectedPayloadType` — a valid envelope for
|
|
126
|
+
* another record class is rejected here.
|
|
127
|
+
*
|
|
128
|
+
* Returns the exact verified payload bytes plus the verified signer
|
|
129
|
+
* descriptors. Throws `DsseEnvelopeError` on malformed input; a payload-type
|
|
130
|
+
* mismatch after cryptographic success is also a `DsseEnvelopeError` (the
|
|
131
|
+
* envelope cannot be consumed as this record class). `keyid` plays no role in
|
|
132
|
+
* authorization.
|
|
133
|
+
*/
|
|
134
|
+
export declare function dsseVerifyEnvelope(envelope: unknown, expectedPayloadType: string, signer: Pick<Signer, 'verify'>, opts?: {
|
|
135
|
+
threshold?: number;
|
|
136
|
+
}): Promise<DsseVerifyResult>;
|
|
137
|
+
/**
|
|
138
|
+
* Sign exact payload bytes into a DSSE envelope using `signer`. The payload is
|
|
139
|
+
* authenticated as EXACT bytes — callers own serialization. Returns the
|
|
140
|
+
* envelope (standard Base64 payload/sig) alongside the signer's detached
|
|
141
|
+
* signature. Never parses `payloadBytes`.
|
|
142
|
+
*/
|
|
143
|
+
export declare function dsseSignEnvelope(payloadType: string, payloadBytes: Buffer, signer: Pick<Signer, 'sign'>): Promise<{
|
|
144
|
+
envelope: DsseEnvelope;
|
|
145
|
+
signature: DetachedSignature;
|
|
146
|
+
}>;
|
|
147
|
+
/** The closed set of launch record payload types. */
|
|
148
|
+
export type DsseRecordPayloadType = typeof PAYLOAD_TYPE_ENROLLMENT_GRANT | typeof PAYLOAD_TYPE_REVOCATION | typeof PAYLOAD_TYPE_SUBMISSION | typeof PAYLOAD_TYPE_POLICY_FLOOR | typeof PAYLOAD_TYPE_ORIGIN | typeof PAYLOAD_TYPE_PUBLICATION;
|
|
149
|
+
/** Runtime copy of the closed record-type set used at dynamic boundaries. */
|
|
150
|
+
export declare const DSSE_RECORD_PAYLOAD_TYPES: readonly ["application/vnd.owenloop.enrollment-grant.v1+json", "application/vnd.owenloop.revocation.v1+json", "application/vnd.owenloop.submission.v1+json", "application/vnd.owenloop.policy-floor.v1+json", "application/vnd.owenloop.origin.v1+json", "application/vnd.owenloop.publication.v1+json"];
|
|
151
|
+
/** Check a dynamic value against the six supported record payload types. */
|
|
152
|
+
export declare function isDsseRecordPayloadType(value: unknown): value is DsseRecordPayloadType;
|
|
153
|
+
/** Generic wrapper retained for callers that already carry a closed-union type. */
|
|
154
|
+
export declare function dsseSignRecord(payloadType: DsseRecordPayloadType, payloadBytes: Buffer, signer: Pick<Signer, 'sign'>): Promise<{
|
|
155
|
+
envelope: DsseEnvelope;
|
|
156
|
+
signature: DetachedSignature;
|
|
157
|
+
}>;
|
|
158
|
+
/** Generic closed-union verification wrapper. */
|
|
159
|
+
export declare function dsseVerifyRecord(envelope: unknown, expectedPayloadType: DsseRecordPayloadType, signer: Pick<Signer, 'verify'>, opts?: {
|
|
160
|
+
threshold?: number;
|
|
161
|
+
}): Promise<DsseVerifyResult>;
|
|
162
|
+
/** Fixed enrollment-grant record wrapper. */
|
|
163
|
+
export declare const dsseSignEnrollmentGrant: (payloadBytes: Buffer, signer: Pick<Signer, "sign">) => Promise<{
|
|
164
|
+
envelope: DsseEnvelope;
|
|
165
|
+
signature: DetachedSignature;
|
|
166
|
+
}>;
|
|
167
|
+
export declare const dsseVerifyEnrollmentGrant: (envelope: unknown, signer: Pick<Signer, "verify">, opts?: {
|
|
168
|
+
threshold?: number;
|
|
169
|
+
}) => Promise<DsseVerifyResult>;
|
|
170
|
+
/** Fixed revocation record wrapper. */
|
|
171
|
+
export declare const dsseSignRevocation: (payloadBytes: Buffer, signer: Pick<Signer, "sign">) => Promise<{
|
|
172
|
+
envelope: DsseEnvelope;
|
|
173
|
+
signature: DetachedSignature;
|
|
174
|
+
}>;
|
|
175
|
+
export declare const dsseVerifyRevocation: (envelope: unknown, signer: Pick<Signer, "verify">, opts?: {
|
|
176
|
+
threshold?: number;
|
|
177
|
+
}) => Promise<DsseVerifyResult>;
|
|
178
|
+
/** Fixed submission record wrapper. */
|
|
179
|
+
export declare const dsseSignSubmission: (payloadBytes: Buffer, signer: Pick<Signer, "sign">) => Promise<{
|
|
180
|
+
envelope: DsseEnvelope;
|
|
181
|
+
signature: DetachedSignature;
|
|
182
|
+
}>;
|
|
183
|
+
export declare const dsseVerifySubmission: (envelope: unknown, signer: Pick<Signer, "verify">, opts?: {
|
|
184
|
+
threshold?: number;
|
|
185
|
+
}) => Promise<DsseVerifyResult>;
|
|
186
|
+
/** Fixed policy-floor record wrapper. */
|
|
187
|
+
export declare const dsseSignPolicyFloor: (payloadBytes: Buffer, signer: Pick<Signer, "sign">) => Promise<{
|
|
188
|
+
envelope: DsseEnvelope;
|
|
189
|
+
signature: DetachedSignature;
|
|
190
|
+
}>;
|
|
191
|
+
export declare const dsseVerifyPolicyFloor: (envelope: unknown, signer: Pick<Signer, "verify">, opts?: {
|
|
192
|
+
threshold?: number;
|
|
193
|
+
}) => Promise<DsseVerifyResult>;
|
|
194
|
+
/** Fixed origin record wrapper. */
|
|
195
|
+
export declare const dsseSignOrigin: (payloadBytes: Buffer, signer: Pick<Signer, "sign">) => Promise<{
|
|
196
|
+
envelope: DsseEnvelope;
|
|
197
|
+
signature: DetachedSignature;
|
|
198
|
+
}>;
|
|
199
|
+
export declare const dsseVerifyOrigin: (envelope: unknown, signer: Pick<Signer, "verify">, opts?: {
|
|
200
|
+
threshold?: number;
|
|
201
|
+
}) => Promise<DsseVerifyResult>;
|
|
202
|
+
/** Fixed publication record wrapper. */
|
|
203
|
+
export declare const dsseSignPublication: (payloadBytes: Buffer, signer: Pick<Signer, "sign">) => Promise<{
|
|
204
|
+
envelope: DsseEnvelope;
|
|
205
|
+
signature: DetachedSignature;
|
|
206
|
+
}>;
|
|
207
|
+
export declare const dsseVerifyPublication: (envelope: unknown, signer: Pick<Signer, "verify">, opts?: {
|
|
208
|
+
threshold?: number;
|
|
209
|
+
}) => Promise<DsseVerifyResult>;
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DSSE (Dead Simple Signing Envelope) — cryptographic framing for owenloop's
|
|
3
|
+
* signed records.
|
|
4
|
+
*
|
|
5
|
+
* Implements the DSSEv1 protocol (https://github.com/secure-systems-lab/dsse):
|
|
6
|
+
* a `{ payloadType, payload, signatures }` envelope where each signature covers
|
|
7
|
+
* the Pre-Authentication Encoding (PAE) of payload type + payload bytes. PAE
|
|
8
|
+
* binds the payload type INTO the signed data, so a payload signed under one
|
|
9
|
+
* record class can never verify as another — the record-class wrappers below
|
|
10
|
+
* enforce that on top of the generic verify.
|
|
11
|
+
*
|
|
12
|
+
* Scope is deliberately cryptographic framing ONLY: payloads are opaque bytes
|
|
13
|
+
* here — this module never parses or re-serializes them, and owns none of the
|
|
14
|
+
* grant/revocation/submission/policy-floor/origin JSON schemas (that is the
|
|
15
|
+
* WP-A1/WP-A3/WP-B1 surface). Signing and verification run through the
|
|
16
|
+
* `Signer` interface, so the envelope code is format-neutral: today the SSH
|
|
17
|
+
* signer implements it; a future Sigstore signer can implement the same
|
|
18
|
+
* contract without touching this file.
|
|
19
|
+
*
|
|
20
|
+
* Base64 discipline: `payload`/`sig` fields are STANDARD RFC 4648 on the wire
|
|
21
|
+
* (what `dsseSignEnvelope` emits), but verification accepts standard OR
|
|
22
|
+
* URL-safe input (the protocol requires accepting both). Decoding is STRICT —
|
|
23
|
+
* Node's `Buffer.from(.., 'base64')` is permissive (it drops unknown
|
|
24
|
+
* characters and ignores bad padding), so `decodeBase64` validates the
|
|
25
|
+
* alphabet and padding explicitly and rejects malformed encodings rather than
|
|
26
|
+
* silently truncating them into a different payload.
|
|
27
|
+
*
|
|
28
|
+
* `keyid` discipline: `keyid` is optional and UNAUTHENTICATED in DSSE. This
|
|
29
|
+
* module treats it as a candidate-selection hint only — never as identity or
|
|
30
|
+
* authorization. Absent and empty-string `keyid` are treated identically.
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* The DSSE protocol version string and PAE prefix. PAE is defined as
|
|
34
|
+
* `"DSSEv1" SP len(payloadType) SP payloadType SP len(payload) SP payload`
|
|
35
|
+
* with ASCII-decimal lengths (no leading zeroes) over the UTF-8 byte length of
|
|
36
|
+
* the type and the raw byte length of the payload.
|
|
37
|
+
*/
|
|
38
|
+
export const DSSE_VERSION = 'DSSEv1';
|
|
39
|
+
/**
|
|
40
|
+
* A malformed envelope — wrong shape, bad Base64, missing required fields.
|
|
41
|
+
* A cryptographic miss (wrong key / tampered bytes) is also a hard verification
|
|
42
|
+
* failure: `dsseVerifyEnvelope` throws this error instead of returning a result
|
|
43
|
+
* whose empty payload could be mistaken for a verified empty payload.
|
|
44
|
+
*/
|
|
45
|
+
export class DsseEnvelopeError extends Error {
|
|
46
|
+
constructor(message) {
|
|
47
|
+
super(message);
|
|
48
|
+
this.name = 'DsseEnvelopeError';
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The six launch signed-record payload types. These strings are signed wire
|
|
53
|
+
* identifiers — versioned, stable, and consumed by later trust work, so a
|
|
54
|
+
* change here is a new `v2` constant, never an edit.
|
|
55
|
+
*/
|
|
56
|
+
export const PAYLOAD_TYPE_ENROLLMENT_GRANT = 'application/vnd.owenloop.enrollment-grant.v1+json';
|
|
57
|
+
export const PAYLOAD_TYPE_REVOCATION = 'application/vnd.owenloop.revocation.v1+json';
|
|
58
|
+
export const PAYLOAD_TYPE_SUBMISSION = 'application/vnd.owenloop.submission.v1+json';
|
|
59
|
+
export const PAYLOAD_TYPE_POLICY_FLOOR = 'application/vnd.owenloop.policy-floor.v1+json';
|
|
60
|
+
export const PAYLOAD_TYPE_ORIGIN = 'application/vnd.owenloop.origin.v1+json';
|
|
61
|
+
export const PAYLOAD_TYPE_PUBLICATION = 'application/vnd.owenloop.publication.v1+json';
|
|
62
|
+
/** The DSSE SSHSIG namespace used for all owenloop DSSE envelopes. */
|
|
63
|
+
export const DSSE_SSH_NAMESPACE = 'owenloop-dsse-v1';
|
|
64
|
+
/**
|
|
65
|
+
* The Pre-Authentication Encoding of one (payloadType, payload) pair:
|
|
66
|
+
* `DSSEv1 SP len(typeBytes) SP typeBytes SP len(payloadBytes) SP payloadBytes`.
|
|
67
|
+
* Lengths are ASCII decimal (no leading zeroes) byte counts; the payload type
|
|
68
|
+
* is measured in UTF-8 bytes. The result is the exact byte string every DSSE
|
|
69
|
+
* signature covers.
|
|
70
|
+
*/
|
|
71
|
+
export function preAuthEncode(payloadType, payload) {
|
|
72
|
+
const typeBytes = Buffer.from(payloadType, 'utf8');
|
|
73
|
+
const head = `${DSSE_VERSION} ${typeBytes.length} `;
|
|
74
|
+
const mid = Buffer.concat([Buffer.from(head, 'utf8'), typeBytes]);
|
|
75
|
+
return Buffer.concat([mid, Buffer.from(` ${payload.length} `, 'utf8'), payload]);
|
|
76
|
+
}
|
|
77
|
+
/** The strict Base64 alphabet check shared by both alphabets. */
|
|
78
|
+
function base64CharsOk(s, alphabet, allowEmpty) {
|
|
79
|
+
return (allowEmpty || s.length > 0) && alphabet.test(s);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Decode a STRICT Base64 string (standard `+/` or URL-safe `-_` alphabet,
|
|
83
|
+
* optional `=` padding). Throws `DsseEnvelopeError` on any malformed input:
|
|
84
|
+
* out-of-alphabet characters, wrong length modulo 4, or a trailing single
|
|
85
|
+
* padding character (three encoded characters never encode a whole byte
|
|
86
|
+
* count). Node's permissive decoder is never used on untrusted wire input —
|
|
87
|
+
* it would silently drop illegal characters and accept missing padding,
|
|
88
|
+
* decoding two different strings to the same bytes.
|
|
89
|
+
*/
|
|
90
|
+
export function decodeBase64Strict(s, opts) {
|
|
91
|
+
if (typeof s !== 'string')
|
|
92
|
+
throw new DsseEnvelopeError('base64 field is not a string');
|
|
93
|
+
const allowEmpty = opts?.allowEmpty ?? false;
|
|
94
|
+
const std = /^[A-Za-z0-9+/]*$/;
|
|
95
|
+
const url = /^[A-Za-z0-9_-]*$/;
|
|
96
|
+
const body = s.replace(/=+$/, '');
|
|
97
|
+
const hadPadding = s.length > body.length;
|
|
98
|
+
if (s.length === 0 && !allowEmpty)
|
|
99
|
+
throw new DsseEnvelopeError('base64 field is empty');
|
|
100
|
+
if (/[\r\n\t ]/.test(s))
|
|
101
|
+
throw new DsseEnvelopeError('malformed base64: whitespace is not allowed');
|
|
102
|
+
if (hadPadding) {
|
|
103
|
+
// With explicit padding the total must be a multiple of 4 and the padding
|
|
104
|
+
// at most two characters.
|
|
105
|
+
if (s.length % 4 !== 0 || s.length - body.length > 2) {
|
|
106
|
+
throw new DsseEnvelopeError('malformed base64: bad padding');
|
|
107
|
+
}
|
|
108
|
+
if (!base64CharsOk(body, std, allowEmpty) && !base64CharsOk(body, url, allowEmpty)) {
|
|
109
|
+
throw new DsseEnvelopeError('malformed base64: character outside both alphabets');
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
if (!base64CharsOk(s, std, allowEmpty) && !base64CharsOk(s, url, allowEmpty)) {
|
|
114
|
+
throw new DsseEnvelopeError('malformed base64: character outside both alphabets');
|
|
115
|
+
}
|
|
116
|
+
const rem = s.length % 4;
|
|
117
|
+
if (rem === 1)
|
|
118
|
+
throw new DsseEnvelopeError('malformed base64: length % 4 == 1');
|
|
119
|
+
}
|
|
120
|
+
// Re-encode through the standard alphabet for the decoder (URL-safe chars
|
|
121
|
+
// mapped to standard; padding restored).
|
|
122
|
+
const standard = body.replace(/-/g, '+').replace(/_/g, '/');
|
|
123
|
+
const pad = standard.length % 4 === 0 ? '' : '='.repeat(4 - (standard.length % 4));
|
|
124
|
+
return Buffer.from(standard + pad, 'base64');
|
|
125
|
+
}
|
|
126
|
+
/** Encode bytes as STANDARD (RFC 4648 §4) Base64 with padding. */
|
|
127
|
+
export function encodeBase64(b) {
|
|
128
|
+
return b.toString('base64');
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Verify one signature entry's bytes against the signer. Returns the verified
|
|
132
|
+
* descriptor or `null`. Malformed Base64 in `sig` is a hard envelope error
|
|
133
|
+
* (the envelope itself is broken), not a miss.
|
|
134
|
+
*/
|
|
135
|
+
function decodeSigEntry(entry, index) {
|
|
136
|
+
if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) {
|
|
137
|
+
throw new DsseEnvelopeError(`signatures[${index}]: entry is not an object`);
|
|
138
|
+
}
|
|
139
|
+
const sigEntry = entry;
|
|
140
|
+
if (typeof sigEntry.sig !== 'string' || sigEntry.sig === '') {
|
|
141
|
+
throw new DsseEnvelopeError(`signatures[${index}]: missing 'sig' field`);
|
|
142
|
+
}
|
|
143
|
+
try {
|
|
144
|
+
return decodeBase64Strict(sigEntry.sig);
|
|
145
|
+
}
|
|
146
|
+
catch (e) {
|
|
147
|
+
throw new DsseEnvelopeError(`signatures[${index}]: ${e.message}`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Verify a DSSE envelope with a format-neutral `Signer`.
|
|
152
|
+
*
|
|
153
|
+
* Verification order (fixed):
|
|
154
|
+
* 1. Decode — the envelope object shape, payload Base64, and each `sig`.
|
|
155
|
+
* 2. Reconstruct the PAE from the envelope's EXACT payload type and payload
|
|
156
|
+
* bytes.
|
|
157
|
+
* 3. Verify signatures through the signer; require at least `threshold`
|
|
158
|
+
* DISTINCT verified signers (the signer deduplicates: a trusted key
|
|
159
|
+
* counts once even when duplicate signature entries validate).
|
|
160
|
+
* 4. Require `payloadType === expectedPayloadType` — a valid envelope for
|
|
161
|
+
* another record class is rejected here.
|
|
162
|
+
*
|
|
163
|
+
* Returns the exact verified payload bytes plus the verified signer
|
|
164
|
+
* descriptors. Throws `DsseEnvelopeError` on malformed input; a payload-type
|
|
165
|
+
* mismatch after cryptographic success is also a `DsseEnvelopeError` (the
|
|
166
|
+
* envelope cannot be consumed as this record class). `keyid` plays no role in
|
|
167
|
+
* authorization.
|
|
168
|
+
*/
|
|
169
|
+
export async function dsseVerifyEnvelope(envelope, expectedPayloadType, signer, opts) {
|
|
170
|
+
const threshold = opts?.threshold ?? 1;
|
|
171
|
+
if (!Number.isInteger(threshold) || threshold < 1) {
|
|
172
|
+
throw new DsseEnvelopeError('threshold must be an integer >= 1');
|
|
173
|
+
}
|
|
174
|
+
if (typeof envelope !== 'object' || envelope === null || Array.isArray(envelope)) {
|
|
175
|
+
throw new DsseEnvelopeError('envelope is not an object');
|
|
176
|
+
}
|
|
177
|
+
const env = envelope;
|
|
178
|
+
if (typeof env.payload !== 'string')
|
|
179
|
+
throw new DsseEnvelopeError("missing 'payload' field");
|
|
180
|
+
if (typeof env.payloadType !== 'string' || env.payloadType === '') {
|
|
181
|
+
throw new DsseEnvelopeError("missing 'payloadType' field");
|
|
182
|
+
}
|
|
183
|
+
if (!Array.isArray(env.signatures) || env.signatures.length === 0) {
|
|
184
|
+
throw new DsseEnvelopeError('envelope must carry at least one signature');
|
|
185
|
+
}
|
|
186
|
+
const payloadBytes = (() => {
|
|
187
|
+
try {
|
|
188
|
+
return decodeBase64Strict(env.payload, { allowEmpty: true });
|
|
189
|
+
}
|
|
190
|
+
catch (e) {
|
|
191
|
+
throw new DsseEnvelopeError(`payload: ${e.message}`);
|
|
192
|
+
}
|
|
193
|
+
})();
|
|
194
|
+
const pae = preAuthEncode(env.payloadType, payloadBytes);
|
|
195
|
+
const sigBytes = env.signatures.map((entry, i) => decodeSigEntry(entry, i));
|
|
196
|
+
const verified = [];
|
|
197
|
+
const seen = new Set();
|
|
198
|
+
for (const sig of sigBytes) {
|
|
199
|
+
const res = await signer.verify(pae, sig);
|
|
200
|
+
if (res === null)
|
|
201
|
+
continue;
|
|
202
|
+
// A trusted key counts at most once, even when duplicate entries validate.
|
|
203
|
+
if (seen.has(res.keyid))
|
|
204
|
+
continue;
|
|
205
|
+
seen.add(res.keyid);
|
|
206
|
+
verified.push(res);
|
|
207
|
+
}
|
|
208
|
+
if (verified.length < threshold) {
|
|
209
|
+
throw new DsseEnvelopeError(`DSSE verification failed: ${verified.length} distinct trusted signer(s), threshold is ${threshold}`);
|
|
210
|
+
}
|
|
211
|
+
if (env.payloadType !== expectedPayloadType) {
|
|
212
|
+
throw new DsseEnvelopeError(`payload type mismatch: envelope carries '${env.payloadType}', caller expects '${expectedPayloadType}'`);
|
|
213
|
+
}
|
|
214
|
+
return { payloadBytes, signers: verified };
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Sign exact payload bytes into a DSSE envelope using `signer`. The payload is
|
|
218
|
+
* authenticated as EXACT bytes — callers own serialization. Returns the
|
|
219
|
+
* envelope (standard Base64 payload/sig) alongside the signer's detached
|
|
220
|
+
* signature. Never parses `payloadBytes`.
|
|
221
|
+
*/
|
|
222
|
+
export async function dsseSignEnvelope(payloadType, payloadBytes, signer) {
|
|
223
|
+
const pae = preAuthEncode(payloadType, payloadBytes);
|
|
224
|
+
const signature = await signer.sign(pae);
|
|
225
|
+
const envelope = {
|
|
226
|
+
payload: encodeBase64(payloadBytes),
|
|
227
|
+
payloadType,
|
|
228
|
+
signatures: [
|
|
229
|
+
{
|
|
230
|
+
...(signature.keyid !== '' ? { keyid: signature.keyid } : {}),
|
|
231
|
+
sig: encodeBase64(signature.sig),
|
|
232
|
+
},
|
|
233
|
+
],
|
|
234
|
+
};
|
|
235
|
+
return { envelope, signature };
|
|
236
|
+
}
|
|
237
|
+
/** Runtime copy of the closed record-type set used at dynamic boundaries. */
|
|
238
|
+
export const DSSE_RECORD_PAYLOAD_TYPES = Object.freeze([
|
|
239
|
+
PAYLOAD_TYPE_ENROLLMENT_GRANT,
|
|
240
|
+
PAYLOAD_TYPE_REVOCATION,
|
|
241
|
+
PAYLOAD_TYPE_SUBMISSION,
|
|
242
|
+
PAYLOAD_TYPE_POLICY_FLOOR,
|
|
243
|
+
PAYLOAD_TYPE_ORIGIN,
|
|
244
|
+
PAYLOAD_TYPE_PUBLICATION,
|
|
245
|
+
]);
|
|
246
|
+
/** Check a dynamic value against the six supported record payload types. */
|
|
247
|
+
export function isDsseRecordPayloadType(value) {
|
|
248
|
+
return typeof value === 'string' && DSSE_RECORD_PAYLOAD_TYPES.includes(value);
|
|
249
|
+
}
|
|
250
|
+
function assertDsseRecordPayloadType(value) {
|
|
251
|
+
if (!isDsseRecordPayloadType(value)) {
|
|
252
|
+
throw new DsseEnvelopeError('unsupported DSSE record payload type');
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/** Generic wrapper retained for callers that already carry a closed-union type. */
|
|
256
|
+
export async function dsseSignRecord(payloadType, payloadBytes, signer) {
|
|
257
|
+
assertDsseRecordPayloadType(payloadType);
|
|
258
|
+
return dsseSignEnvelope(payloadType, payloadBytes, signer);
|
|
259
|
+
}
|
|
260
|
+
/** Generic closed-union verification wrapper. */
|
|
261
|
+
export async function dsseVerifyRecord(envelope, expectedPayloadType, signer, opts) {
|
|
262
|
+
assertDsseRecordPayloadType(expectedPayloadType);
|
|
263
|
+
return dsseVerifyEnvelope(envelope, expectedPayloadType, signer, opts);
|
|
264
|
+
}
|
|
265
|
+
/** Fixed enrollment-grant record wrapper. */
|
|
266
|
+
export const dsseSignEnrollmentGrant = (payloadBytes, signer) => dsseSignEnvelope(PAYLOAD_TYPE_ENROLLMENT_GRANT, payloadBytes, signer);
|
|
267
|
+
export const dsseVerifyEnrollmentGrant = (envelope, signer, opts) => dsseVerifyEnvelope(envelope, PAYLOAD_TYPE_ENROLLMENT_GRANT, signer, opts);
|
|
268
|
+
/** Fixed revocation record wrapper. */
|
|
269
|
+
export const dsseSignRevocation = (payloadBytes, signer) => dsseSignEnvelope(PAYLOAD_TYPE_REVOCATION, payloadBytes, signer);
|
|
270
|
+
export const dsseVerifyRevocation = (envelope, signer, opts) => dsseVerifyEnvelope(envelope, PAYLOAD_TYPE_REVOCATION, signer, opts);
|
|
271
|
+
/** Fixed submission record wrapper. */
|
|
272
|
+
export const dsseSignSubmission = (payloadBytes, signer) => dsseSignEnvelope(PAYLOAD_TYPE_SUBMISSION, payloadBytes, signer);
|
|
273
|
+
export const dsseVerifySubmission = (envelope, signer, opts) => dsseVerifyEnvelope(envelope, PAYLOAD_TYPE_SUBMISSION, signer, opts);
|
|
274
|
+
/** Fixed policy-floor record wrapper. */
|
|
275
|
+
export const dsseSignPolicyFloor = (payloadBytes, signer) => dsseSignEnvelope(PAYLOAD_TYPE_POLICY_FLOOR, payloadBytes, signer);
|
|
276
|
+
export const dsseVerifyPolicyFloor = (envelope, signer, opts) => dsseVerifyEnvelope(envelope, PAYLOAD_TYPE_POLICY_FLOOR, signer, opts);
|
|
277
|
+
/** Fixed origin record wrapper. */
|
|
278
|
+
export const dsseSignOrigin = (payloadBytes, signer) => dsseSignEnvelope(PAYLOAD_TYPE_ORIGIN, payloadBytes, signer);
|
|
279
|
+
export const dsseVerifyOrigin = (envelope, signer, opts) => dsseVerifyEnvelope(envelope, PAYLOAD_TYPE_ORIGIN, signer, opts);
|
|
280
|
+
/** Fixed publication record wrapper. */
|
|
281
|
+
export const dsseSignPublication = (payloadBytes, signer) => dsseSignEnvelope(PAYLOAD_TYPE_PUBLICATION, payloadBytes, signer);
|
|
282
|
+
export const dsseVerifyPublication = (envelope, signer, opts) => dsseVerifyEnvelope(envelope, PAYLOAD_TYPE_PUBLICATION, signer, opts);
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enrollment-grant construction and client-side roster verification.
|
|
3
|
+
*
|
|
4
|
+
* D1 deliberately stops at a narrow chain-validation seam. A signed grant is
|
|
5
|
+
* unforgeable by a hub that only relays records, but a signature alone does not
|
|
6
|
+
* prove that the grantor is enrolled in the organization. Until a
|
|
7
|
+
* `EnrollmentChainValidator` is installed, verification therefore refuses with
|
|
8
|
+
* `unverifiable` rather than accepting the record. The explicit early return in
|
|
9
|
+
* `verifyRosterEntry` is the §8.1 fail-closed gate.
|
|
10
|
+
*/
|
|
11
|
+
import type { Signer } from './ssh.ts';
|
|
12
|
+
import type { EnrollmentGrantRecord, GrantScope, PrincipalReference } from './records.ts';
|
|
13
|
+
import type { PublicKeyDescriptor } from './keys.ts';
|
|
14
|
+
/** The narrow D1/D4 boundary for proving that one grant reaches the org root. */
|
|
15
|
+
export interface EnrollmentChainValidator {
|
|
16
|
+
/** Resolve whether `grant` chains to the org root. */
|
|
17
|
+
validate(grant: EnrollmentGrantRecord, verifiedSignerKeyId: string): Promise<{
|
|
18
|
+
ok: true;
|
|
19
|
+
} | {
|
|
20
|
+
ok: false;
|
|
21
|
+
reason: string;
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
24
|
+
/** The least privilege scope carried by a self-vouched machine grant. */
|
|
25
|
+
export declare const DEFAULT_MACHINE_SCOPE: GrantScope;
|
|
26
|
+
/** Inputs for the pure enrollment-grant builder. */
|
|
27
|
+
export interface BuildEnrollmentGrantArgs {
|
|
28
|
+
newKey: PublicKeyDescriptor;
|
|
29
|
+
principal: PrincipalReference;
|
|
30
|
+
grantedBy: string;
|
|
31
|
+
validFrom: number;
|
|
32
|
+
scope: GrantScope;
|
|
33
|
+
}
|
|
34
|
+
/** Build one complete, immutable enrollment grant without performing I/O. */
|
|
35
|
+
export declare function buildEnrollmentGrant(args: BuildEnrollmentGrantArgs): EnrollmentGrantRecord;
|
|
36
|
+
/** The four states a client can distinguish when reading a relayed roster. */
|
|
37
|
+
export type RosterVerdict = {
|
|
38
|
+
kind: 'enrolled';
|
|
39
|
+
keyid: string;
|
|
40
|
+
principal: string;
|
|
41
|
+
} | {
|
|
42
|
+
kind: 'unenrolled';
|
|
43
|
+
} | {
|
|
44
|
+
kind: 'unverifiable';
|
|
45
|
+
reason: string;
|
|
46
|
+
} | {
|
|
47
|
+
kind: 'invalid';
|
|
48
|
+
reason: string;
|
|
49
|
+
};
|
|
50
|
+
/** One relayed DSSE envelope plus the local allowed_signers text. */
|
|
51
|
+
export interface VerifyRosterEntryInput {
|
|
52
|
+
/** A decoded DSSE envelope, or JSON/UTF-8 bytes carrying one. */
|
|
53
|
+
envelope?: unknown;
|
|
54
|
+
/** Alias for callers that already have a sidecar-like byte buffer. */
|
|
55
|
+
dsseBytes?: Uint8Array;
|
|
56
|
+
/** Resolved local `allowed_signers` text. */
|
|
57
|
+
allowedSignersText?: string;
|
|
58
|
+
}
|
|
59
|
+
/** Test and signer-tool seams for roster verification. */
|
|
60
|
+
export interface VerifyRosterEntryOptions {
|
|
61
|
+
/** D4's chain-validation seam. Omission is deliberately fail-closed. */
|
|
62
|
+
chainValidator?: EnrollmentChainValidator;
|
|
63
|
+
/** Inject a signer for hermetic verification tests. */
|
|
64
|
+
signerForPrincipal?: (args: {
|
|
65
|
+
principal: string;
|
|
66
|
+
allowedSignersText: string;
|
|
67
|
+
}) => Pick<Signer, 'verify'> & {
|
|
68
|
+
dispose?: () => void;
|
|
69
|
+
};
|
|
70
|
+
/** SSHSIG namespace override for a caller with a different record domain. */
|
|
71
|
+
namespace?: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Verify one relayed enrollment record. The operation is ordered so malformed
|
|
75
|
+
* input, missing trust roots, signer authorization, and missing chain support
|
|
76
|
+
* remain distinct verdicts instead of collapsing into a boolean.
|
|
77
|
+
*/
|
|
78
|
+
export declare function verifyRosterEntry(input: VerifyRosterEntryInput, options?: VerifyRosterEntryOptions): Promise<RosterVerdict>;
|