@warpgogol/forge 8.0.2 → 8.0.4

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.
Files changed (71) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/bin/cli.ts +3 -2
  3. package/dist/bin/cli.js +3 -2
  4. package/dist/bin/cli.js.map +1 -1
  5. package/dist/os/authority/authority.module.d.ts +3 -0
  6. package/dist/os/authority/authority.module.d.ts.map +1 -0
  7. package/dist/os/authority/authority.module.js +169 -0
  8. package/dist/os/authority/authority.module.js.map +1 -0
  9. package/dist/os/authority/handlers/delegate-revoke.d.ts +15 -0
  10. package/dist/os/authority/handlers/delegate-revoke.d.ts.map +1 -0
  11. package/dist/os/authority/handlers/delegate-revoke.js +91 -0
  12. package/dist/os/authority/handlers/delegate-revoke.js.map +1 -0
  13. package/dist/os/authority/handlers/delegate.d.ts +14 -0
  14. package/dist/os/authority/handlers/delegate.d.ts.map +1 -0
  15. package/dist/os/authority/handlers/delegate.js +134 -0
  16. package/dist/os/authority/handlers/delegate.js.map +1 -0
  17. package/dist/os/authority/handlers/delegation-list.d.ts +12 -0
  18. package/dist/os/authority/handlers/delegation-list.d.ts.map +1 -0
  19. package/dist/os/authority/handlers/delegation-list.js +54 -0
  20. package/dist/os/authority/handlers/delegation-list.js.map +1 -0
  21. package/dist/os/authority/handlers/delegation-validate.d.ts +11 -0
  22. package/dist/os/authority/handlers/delegation-validate.d.ts.map +1 -0
  23. package/dist/os/authority/handlers/delegation-validate.js +132 -0
  24. package/dist/os/authority/handlers/delegation-validate.js.map +1 -0
  25. package/dist/os/authority/helpers.d.ts +36 -0
  26. package/dist/os/authority/helpers.d.ts.map +1 -0
  27. package/dist/os/authority/helpers.js +83 -0
  28. package/dist/os/authority/helpers.js.map +1 -0
  29. package/dist/os/authority/index.d.ts +2 -0
  30. package/dist/os/authority/index.d.ts.map +1 -0
  31. package/dist/os/authority/index.js +14 -0
  32. package/dist/os/authority/index.js.map +1 -0
  33. package/dist/os/rfc/handlers/validate-rules.d.ts.map +1 -1
  34. package/dist/os/rfc/handlers/validate-rules.js +30 -1
  35. package/dist/os/rfc/handlers/validate-rules.js.map +1 -1
  36. package/dist/os/rfc/types.d.ts +8 -0
  37. package/dist/os/rfc/types.d.ts.map +1 -1
  38. package/dist/os/rfc/types.js +2 -0
  39. package/dist/os/rfc/types.js.map +1 -1
  40. package/dist/os/session/handlers/save.d.ts.map +1 -1
  41. package/dist/os/session/handlers/save.js +41 -10
  42. package/dist/os/session/handlers/save.js.map +1 -1
  43. package/dist/src/authority/delegations.d.ts +108 -0
  44. package/dist/src/authority/delegations.d.ts.map +1 -0
  45. package/dist/src/authority/delegations.js +217 -0
  46. package/dist/src/authority/delegations.js.map +1 -0
  47. package/dist/src/authority/index.d.ts +3 -0
  48. package/dist/src/authority/index.d.ts.map +1 -0
  49. package/dist/src/authority/index.js +17 -0
  50. package/dist/src/authority/index.js.map +1 -0
  51. package/dist/src/authority/signing.d.ts +8 -0
  52. package/dist/src/authority/signing.d.ts.map +1 -0
  53. package/dist/src/authority/signing.js +72 -0
  54. package/dist/src/authority/signing.js.map +1 -0
  55. package/os/authority/authority.module.ts +183 -0
  56. package/os/authority/authority.test.ts +328 -0
  57. package/os/authority/handlers/delegate-revoke.ts +123 -0
  58. package/os/authority/handlers/delegate.ts +190 -0
  59. package/os/authority/handlers/delegation-list.ts +80 -0
  60. package/os/authority/handlers/delegation-validate.ts +231 -0
  61. package/os/authority/helpers.ts +111 -0
  62. package/os/authority/index.ts +14 -0
  63. package/os/rfc/handlers/validate-rules.ts +42 -6
  64. package/os/rfc/types.ts +10 -0
  65. package/os/session/handlers/save.ts +43 -9
  66. package/package.json +13 -1
  67. package/src/authority/delegations.ts +267 -0
  68. package/src/authority/index.ts +38 -0
  69. package/src/authority/signing.ts +73 -0
  70. package/src/tests/rfc-validate-delegation.test.ts +178 -0
  71. package/src/tests/session-handlers.test.ts +65 -0
@@ -0,0 +1,217 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>RFC-1336: forge/authority-delegations@1 — the workspace-root
4
+ delegation registry schema plus the portable loader/resolver every
5
+ human-gated consumer shares. A delegation grants one declared agent
6
+ (grantedTo) the right to run one scope on behalf of a named human
7
+ (grantedBy), site-bounded, expirable, and revocable. The registry is
8
+ policy plus audit evidence — not a cryptographic security boundary.</purpose>
9
+ <non-goals>
10
+ <item>Do not import kernel/site/engine packages — forge stays runtime-autonomous (FORGE-AUTONOMY-01).</item>
11
+ <item>Do not police which process may invoke the mutating commands — the human-only rule on authority.delegate is workspace policy (AGENTS.md), not a check inside this module.</item>
12
+ </non-goals>
13
+ </MODULE_CONTRACT>
14
+ <KEY_DECISIONS>
15
+ <item>Registry absence is tolerance-neutral — ENOENT yields an empty registry; consumers treat "no file" and "no grant" identically (RFC-1336 unchanged-behavior rule).</item>
16
+ <item>DelegationQuery carries an optional grantedBy — consumers that already know the deciding human (e.g. bordbuch.append --delegated-by) bind the query to the grantor so delegatedBy provenance cannot be fabricated against a different human's grant.</item>
17
+ <item>sites: "workspace" covers every site; an explicit id list bounds site scope. Site-scoped queries with no site never match a site-listed grant.</item>
18
+ </KEY_DECISIONS>
19
+ <CHANGE_SUMMARY>
20
+ <item>RFC-1336: initial module — schema, scope catalog, loader, resolver, serializer.</item>
21
+ <item>RFC-1336: step 1: forge authority module — delegation registry schema + resolver, four authority.* commands, optional Ed25519 signing</item>
22
+ <item>RFC-1336: delegated editorial sign-off (RFC-1336 step 3)
23
+
24
+ editorial.review.signoff admits agent:<id> reviewers under an active
25
+ editorial.signoff delegation — the record and the editorial-signoff
26
+ bordbuch event carry delegatedBy + delegationId provenance; the sign-off
27
+ schema fails closed on agent reviewers without it. leitstand.ship gains
28
+ an editorial-delegated-signoff step between sync-after-alt and
29
+ certify-main that prepares the packet (if absent) and signs as the
30
+ delegate — a journaled no-op with no delegation, so the operator path is
31
+ unchanged. certify/promote precondition remediation now names an active
32
+ delegation when one covers the site.</item>
33
+ <item>RFC-1336: delegated rfc.decision/version.major/onboarding.decision + docs (RFC-1336 steps 4-5)</item>
34
+ </CHANGE_SUMMARY>
35
+ */
36
+ import path from "node:path";
37
+ import YAML from "yaml";
38
+ import { z } from "zod";
39
+ import { resolveIo } from "../utils/io.js";
40
+ import { canonicalJson } from "./signing.js";
41
+ export const AUTHORITY_DELEGATIONS_SCHEMA_ID = "forge/authority-delegations@1";
42
+ export const DELEGATIONS_FILENAME = "authority.delegations.yaml";
43
+ export const AGENT_ID_PATTERN = /^agent:[a-z0-9][a-z0-9-]*$/;
44
+ export const AGENT_OR_WILDCARD_PATTERN = /^agent:([a-z0-9][a-z0-9-]*|\*)$/;
45
+ export const HUMAN_ID_PATTERN = /^human:[a-z0-9][a-z0-9-]*$/;
46
+ /**
47
+ * The delegable scope catalogue (RFC-1336). `bordbuch.<kind>` is a
48
+ * parameterized family — any concrete Bordbuch entry kind appends its own
49
+ * scope (`bordbuch.editorial-signoff`, `bordbuch.operator-note`, …).
50
+ */
51
+ export const DELEGABLE_SCOPES = [
52
+ "editorial.signoff",
53
+ "rfc.decision",
54
+ "version.major",
55
+ "onboarding.decision",
56
+ "fleet.notify",
57
+ ];
58
+ export const BORDBUCH_SCOPE_PREFIX = "bordbuch.";
59
+ /**
60
+ * Scopes that MUST NOT be delegated (RFC-1336 non-goals): security-sensitive
61
+ * or irreversible flows stay human-only. Checked at grant write time and by
62
+ * authority.delegation.validate (DELEG-04).
63
+ */
64
+ export const NON_DELEGABLE_SCOPES = [
65
+ "sternsystem.handover",
66
+ "nachweis.sign",
67
+ "nachweis.timestamp",
68
+ "cloudflare.token",
69
+ "fleet.claims.merge",
70
+ ];
71
+ const isoDatetime = z.string().refine((v) => !Number.isNaN(Date.parse(v)), {
72
+ message: "must be an ISO-8601 datetime",
73
+ });
74
+ export const delegationEntrySchema = z
75
+ .object({
76
+ id: z.string().regex(/^del-[0-9]{4,}$/),
77
+ scope: z.string().min(1),
78
+ grantedTo: z.string().regex(AGENT_OR_WILDCARD_PATTERN),
79
+ grantedBy: z.string().regex(HUMAN_ID_PATTERN),
80
+ sites: z.union([z.literal("workspace"), z.array(z.string().min(1)).min(1)]),
81
+ grantedAt: isoDatetime,
82
+ expiresAt: isoDatetime.nullish(),
83
+ revokedAt: isoDatetime.nullish(),
84
+ revokedBy: z.string().regex(HUMAN_ID_PATTERN).optional(),
85
+ note: z.string().optional(),
86
+ /** Optional `--sign` provenance: "ed25519:<publicKeyHex>:<signatureHex>". */
87
+ signature: z.string().optional(),
88
+ })
89
+ .strict();
90
+ export const authorityDelegationsSchema = z
91
+ .object({
92
+ schema: z.literal(AUTHORITY_DELEGATIONS_SCHEMA_ID),
93
+ delegations: z.array(delegationEntrySchema).default([]),
94
+ })
95
+ .strict();
96
+ export class DelegationRegistryError extends Error {
97
+ constructor(message) {
98
+ super(message);
99
+ this.name = "DelegationRegistryError";
100
+ }
101
+ }
102
+ export function delegationsPath(workspaceRoot) {
103
+ return path.join(workspaceRoot, DELEGATIONS_FILENAME);
104
+ }
105
+ /** True when the scope string names a delegable scope (catalogue or bordbuch.*). */
106
+ export function isDelegableScope(scope) {
107
+ return (DELEGABLE_SCOPES.includes(scope) ||
108
+ scope.startsWith(BORDBUCH_SCOPE_PREFIX));
109
+ }
110
+ /**
111
+ * Load the delegation registry. An absent file means zero delegations (RFC-1336:
112
+ * the file is optional); parse/schema failures are load-bearing and throw
113
+ * DelegationRegistryError — a corrupted registry must never silently resolve
114
+ * to "no delegations" or every gate disarms.
115
+ */
116
+ export async function loadDelegations(workspaceRoot, io) {
117
+ const effectiveIo = resolveIo(io);
118
+ const filePath = delegationsPath(workspaceRoot);
119
+ let source;
120
+ try {
121
+ source = await effectiveIo.readFile(filePath);
122
+ }
123
+ catch (e) {
124
+ if (e.code === "ENOENT") {
125
+ return { schema: AUTHORITY_DELEGATIONS_SCHEMA_ID, delegations: [] };
126
+ }
127
+ throw new DelegationRegistryError(`cannot read ${DELEGATIONS_FILENAME}: ${e instanceof Error ? e.message : String(e)}`);
128
+ }
129
+ let raw;
130
+ try {
131
+ raw = YAML.parse(source);
132
+ }
133
+ catch (e) {
134
+ throw new DelegationRegistryError(`${DELEGATIONS_FILENAME} is not parseable YAML: ${e instanceof Error ? e.message : String(e)}`);
135
+ }
136
+ const parsed = authorityDelegationsSchema.safeParse(raw);
137
+ if (!parsed.success) {
138
+ const issues = parsed.error.issues
139
+ .map((i) => `${i.path.join(".") || "<root>"}: ${i.message}`)
140
+ .join("; ");
141
+ throw new DelegationRegistryError(`${DELEGATIONS_FILENAME} schema violation — ${issues}`);
142
+ }
143
+ return parsed.data;
144
+ }
145
+ const REGISTRY_HEADER = `# Operator authority delegations (RFC-1336) — ${AUTHORITY_DELEGATIONS_SCHEMA_ID}
146
+ # Human-granted, scoped, revocable powers for agent delegates.
147
+ # Agents MUST NOT edit this file — grants and revocations go through
148
+ # authority.delegate / authority.delegate.revoke (operator-only).
149
+ `;
150
+ /** Serialize a registry for write-back — canonical header, stable key order. */
151
+ export function serializeDelegations(registry) {
152
+ return REGISTRY_HEADER + YAML.stringify(registry);
153
+ }
154
+ /**
155
+ * The bytes a `--sign` signature covers: canonical JSON of the entry without
156
+ * its signature field (imported here so signers and verifiers share one
157
+ * canonicalization — signing.ts owns the crypto).
158
+ */
159
+ export function canonicalDelegationPayload(entry) {
160
+ const { signature: _signature, ...rest } = entry;
161
+ return canonicalJson(rest);
162
+ }
163
+ export function resolveDelegation(registry, query, now = new Date()) {
164
+ const matches = registry.delegations.filter((d) => {
165
+ if (d.scope !== query.scope)
166
+ return false;
167
+ if (d.revokedAt)
168
+ return false;
169
+ if (d.expiresAt && new Date(d.expiresAt).getTime() <= now.getTime())
170
+ return false;
171
+ if (query.agent !== undefined && d.grantedTo !== query.agent && d.grantedTo !== "agent:*") {
172
+ return false;
173
+ }
174
+ if (query.grantedBy !== undefined && d.grantedBy !== query.grantedBy)
175
+ return false;
176
+ if (d.sites === "workspace")
177
+ return true;
178
+ return query.site !== undefined && d.sites.includes(query.site);
179
+ });
180
+ if (matches.length === 0)
181
+ return null;
182
+ // Most specific grantee first (an explicit agent:<id> beats the wildcard),
183
+ // then most recently granted.
184
+ const specificity = (d) => (d.grantedTo === "agent:*" ? 0 : 1);
185
+ return matches.reduce((a, b) => specificity(a) !== specificity(b)
186
+ ? specificity(a) > specificity(b)
187
+ ? a
188
+ : b
189
+ : a.grantedAt >= b.grantedAt
190
+ ? a
191
+ : b);
192
+ }
193
+ /**
194
+ * The actor identity a delegated operation records. A grant to an explicit
195
+ * `agent:<id>` names its actor; a wildcard `agent:*` grant requires the caller
196
+ * to supply the session's agent id so provenance stays specific.
197
+ */
198
+ export function delegationActor(grant, sessionAgentId) {
199
+ if (grant.grantedTo !== "agent:*")
200
+ return grant.grantedTo;
201
+ if (sessionAgentId && AGENT_ID_PATTERN.test(sessionAgentId))
202
+ return sessionAgentId;
203
+ return null;
204
+ }
205
+ /**
206
+ * Normalize a session-declared agent id — callers read WERKSTATT_AGENT_ID,
207
+ * which accepts both "devin" and "agent:devin". Anything else is not a
208
+ * usable actor id and returns undefined (callers fail closed).
209
+ */
210
+ export function normalizeAgentId(raw) {
211
+ const trimmed = raw?.trim();
212
+ if (!trimmed)
213
+ return undefined;
214
+ const id = trimmed.startsWith("agent:") ? trimmed : `agent:${trimmed}`;
215
+ return AGENT_ID_PATTERN.test(id) ? id : undefined;
216
+ }
217
+ //# sourceMappingURL=delegations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delegations.js","sourceRoot":"","sources":["../../../src/authority/delegations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkCE;AAEF,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7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;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAuB;IACtD,MAAM,OAAO,GAAG,GAAG,EAAE,IAAI,EAAE,CAAC;IAC5B,IAAI,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IAC/B,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC;IACvE,OAAO,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AACpD,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { AGENT_ID_PATTERN, AGENT_OR_WILDCARD_PATTERN, AUTHORITY_DELEGATIONS_SCHEMA_ID, BORDBUCH_SCOPE_PREFIX, DELEGABLE_SCOPES, DELEGATIONS_FILENAME, DelegationRegistryError, HUMAN_ID_PATTERN, NON_DELEGABLE_SCOPES, authorityDelegationsSchema, canonicalDelegationPayload, delegationActor, delegationEntrySchema, delegationsPath, isDelegableScope, loadDelegations, normalizeAgentId, resolveDelegation, serializeDelegations, } from "./delegations.ts";
2
+ export type { AuthorityDelegations, DelegationEntry, DelegationQuery } from "./delegations.ts";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/authority/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,gBAAgB,EAChB,yBAAyB,EACzB,+BAA+B,EAC/B,qBAAqB,EACrB,gBAAgB,EAChB,oBAAoB,EACpB,uBAAuB,EACvB,gBAAgB,EAChB,oBAAoB,EACpB,0BAA0B,EAC1B,0BAA0B,EAC1B,eAAe,EACf,qBAAqB,EACrB,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,oBAAoB,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,17 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>RFC-1336: authority barrel — the consumer-facing surface of the
4
+ delegation model (schema, loader, resolver, scope catalogue). Werkstatt
5
+ engine/site consumers import from @warpgogol/forge/authority.</purpose>
6
+ <non-goals>
7
+ <item>Do not re-export signing internals — signature verification is a validator concern (verifyDelegationSignature is importable from ./signing.ts for tests).</item>
8
+ </non-goals>
9
+ </MODULE_CONTRACT>
10
+ <CHANGE_SUMMARY>
11
+ <item>RFC-1336: initial barrel.</item>
12
+ <item>RFC-1336: step 1: forge authority module — delegation registry schema + resolver, four authority.* commands, optional Ed25519 signing</item>
13
+ <item>RFC-1336: delegated rfc.decision/version.major/onboarding.decision + docs (RFC-1336 steps 4-5)</item>
14
+ </CHANGE_SUMMARY>
15
+ */
16
+ export { AGENT_ID_PATTERN, AGENT_OR_WILDCARD_PATTERN, AUTHORITY_DELEGATIONS_SCHEMA_ID, BORDBUCH_SCOPE_PREFIX, DELEGABLE_SCOPES, DELEGATIONS_FILENAME, DelegationRegistryError, HUMAN_ID_PATTERN, NON_DELEGABLE_SCOPES, authorityDelegationsSchema, canonicalDelegationPayload, delegationActor, delegationEntrySchema, delegationsPath, isDelegableScope, loadDelegations, normalizeAgentId, resolveDelegation, serializeDelegations, } from "./delegations.js";
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/authority/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;EAcE;AAEF,OAAO,EACL,gBAAgB,EAChB,yBAAyB,EACzB,+BAA+B,EAC/B,qBAAqB,EACrB,gBAAgB,EAChB,oBAAoB,EACpB,uBAAuB,EACvB,gBAAgB,EAChB,oBAAoB,EACpB,0BAA0B,EAC1B,0BAA0B,EAC1B,eAAe,EACf,qBAAqB,EACrB,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,8 @@
1
+ /** Deterministic sorted-key serialization — the signature's signed payload. */
2
+ export declare function canonicalJson(value: unknown): string;
3
+ export declare function publicKeyHexFromSeed(privateKeyHex: string): string;
4
+ /** Sign a payload with a hex-encoded Ed25519 seed; returns "<pubHex>:<sigHex>". */
5
+ export declare function signDelegationPayload(privateKeyHex: string, payload: string): string;
6
+ /** Verify a "ed25519:<pubHex>:<sigHex>"-shaped signature against a payload. */
7
+ export declare function verifyDelegationSignature(signature: string, payload: string): boolean;
8
+ //# sourceMappingURL=signing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../../../src/authority/signing.ts"],"names":[],"mappings":"AAyBA,+EAA+E;AAC/E,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAQpD;AAED,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAQlE;AAED,mFAAmF;AACnF,wBAAgB,qBAAqB,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAQpF;AAED,+EAA+E;AAC/E,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAcrF"}
@@ -0,0 +1,72 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>RFC-1336: optional Ed25519 provenance signatures on delegation
4
+ entries (`authority.delegate --sign`). Signs the canonical JSON of the
5
+ entry under SIGNING_PRIVATE_KEY (hex-encoded 32-byte seed — the same
6
+ convention as werkstatt-shared/signing) and stores
7
+ "ed25519:<publicKeyHex>:<signatureHex>". Implemented on node:crypto —
8
+ forge carries no @noble dependency (FORGE-AUTONOMY-01).</purpose>
9
+ <non-goals>
10
+ <item>Does not turn the registry into a security boundary — the signature is provenance evidence; the entry's authority still flows from declared policy.</item>
11
+ </non-goals>
12
+ </MODULE_CONTRACT>
13
+ <CHANGE_SUMMARY>
14
+ <item>RFC-1336: initial module — seed→PKCS8 reconstruction, canonical JSON, sign/verify.</item>
15
+ <item>RFC-1336: step 1: forge authority module — delegation registry schema + resolver, four authority.* commands, optional Ed25519 signing</item>
16
+ </CHANGE_SUMMARY>
17
+ */
18
+ import { createPrivateKey, createPublicKey, sign, verify } from "node:crypto";
19
+ /** PKCS8 DER prefix wrapping a raw 32-byte Ed25519 seed. */
20
+ const ED25519_PKCS8_PREFIX = Buffer.from("302e020100300506032b657004220420", "hex");
21
+ /** SPKI DER prefix wrapping a raw 32-byte Ed25519 public key. */
22
+ const ED25519_SPKI_PREFIX = Buffer.from("302a300506032b6570032100", "hex");
23
+ /** Deterministic sorted-key serialization — the signature's signed payload. */
24
+ export function canonicalJson(value) {
25
+ if (value === null || typeof value !== "object")
26
+ return JSON.stringify(value);
27
+ if (Array.isArray(value))
28
+ return `[${value.map(canonicalJson).join(",")}]`;
29
+ const entries = Object.entries(value)
30
+ .filter(([, v]) => v !== undefined)
31
+ .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
32
+ .map(([k, v]) => `${JSON.stringify(k)}:${canonicalJson(v)}`);
33
+ return `{${entries.join(",")}}`;
34
+ }
35
+ export function publicKeyHexFromSeed(privateKeyHex) {
36
+ const key = createPrivateKey({
37
+ key: Buffer.concat([ED25519_PKCS8_PREFIX, Buffer.from(privateKeyHex, "hex")]),
38
+ format: "der",
39
+ type: "pkcs8",
40
+ });
41
+ const jwk = createPublicKey(key).export({ format: "jwk" });
42
+ return Buffer.from(jwk.x, "base64url").toString("hex");
43
+ }
44
+ /** Sign a payload with a hex-encoded Ed25519 seed; returns "<pubHex>:<sigHex>". */
45
+ export function signDelegationPayload(privateKeyHex, payload) {
46
+ const key = createPrivateKey({
47
+ key: Buffer.concat([ED25519_PKCS8_PREFIX, Buffer.from(privateKeyHex, "hex")]),
48
+ format: "der",
49
+ type: "pkcs8",
50
+ });
51
+ const signature = sign(null, Buffer.from(payload, "utf8"), key);
52
+ return `${publicKeyHexFromSeed(privateKeyHex)}:${signature.toString("hex")}`;
53
+ }
54
+ /** Verify a "ed25519:<pubHex>:<sigHex>"-shaped signature against a payload. */
55
+ export function verifyDelegationSignature(signature, payload) {
56
+ const bare = signature.startsWith("ed25519:") ? signature.slice("ed25519:".length) : signature;
57
+ const [pubHex, sigHex] = bare.split(":");
58
+ if (!pubHex || !sigHex || pubHex.length !== 64 || sigHex.length !== 128)
59
+ return false;
60
+ try {
61
+ const key = createPublicKey({
62
+ key: Buffer.concat([ED25519_SPKI_PREFIX, Buffer.from(pubHex, "hex")]),
63
+ format: "der",
64
+ type: "spki",
65
+ });
66
+ return verify(null, Buffer.from(payload, "utf8"), key, Buffer.from(sigHex, "hex"));
67
+ }
68
+ catch {
69
+ return false;
70
+ }
71
+ }
72
+ //# sourceMappingURL=signing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signing.js","sourceRoot":"","sources":["../../../src/authority/signing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;EAgBE;AAEF,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE9E,4DAA4D;AAC5D,MAAM,oBAAoB,GAAG,MAAM,CAAC,IAAI,CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAC;AACpF,iEAAiE;AACjE,MAAM,mBAAmB,GAAG,MAAM,CAAC,IAAI,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAC;AAE3E,+EAA+E;AAC/E,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC9E,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,KAA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AAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;IACrF,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
@@ -0,0 +1,183 @@
1
+ /*
2
+ <MODULE_CONTRACT>
3
+ <purpose>RFC-1336: forge-authority — the operator-authority delegation module.
4
+ Registers the four authority.* commands: delegate + delegate.revoke
5
+ (operator-only writes to the workspace-root registry), delegation.list and
6
+ delegation.validate (read-only inspection). Runtime: autonomous — the only
7
+ engine touchpoint is the optional sibling-invocation port used for Bordbuch
8
+ audit events.</purpose>
9
+ <non-goals>
10
+ <item>Do not implement consumer gates here — signoff, bordbuch.append, ecosystem.commit, onboarding, and rfc.validate consume src/authority/delegations.ts directly.</item>
11
+ </non-goals>
12
+ </MODULE_CONTRACT>
13
+ <CHANGE_SUMMARY>
14
+ <item>RFC-1336: initial module — four authority.* commands.</item>
15
+ <item>RFC-1336: step 1: forge authority module — delegation registry schema + resolver, four authority.* commands, optional Ed25519 signing</item>
16
+ <item>RFC-1336: step 5: coverage "operator" declarations — the commands are CLI-invoked by the operator (or read-only by agents), not pipeline-wired; satisfies the reachable acceptance probe.</item>
17
+ </CHANGE_SUMMARY>
18
+ */
19
+
20
+ import type { ForgeModule } from "../../src/forge-module.ts";
21
+
22
+ export async function createForgeAuthorityModule(): Promise<ForgeModule> {
23
+ const { runAuthorityDelegate } = await import("./handlers/delegate.ts");
24
+ const { runAuthorityDelegateRevoke } = await import("./handlers/delegate-revoke.ts");
25
+ const { runAuthorityDelegationList } = await import("./handlers/delegation-list.ts");
26
+ const { runAuthorityDelegationValidate } = await import("./handlers/delegation-validate.ts");
27
+ return {
28
+ name: "forge-authority",
29
+ version: "0.1.0",
30
+ runtime: "autonomous",
31
+ declarations: [],
32
+ commands: [
33
+ {
34
+ name: "authority.delegate",
35
+ description:
36
+ "RFC-1336: grant a scoped, site-bounded, expirable authority delegation to an " +
37
+ "agent — writes one entry to authority.delegations.yaml and fans out an " +
38
+ "authority-delegation Bordbuch event per covered site. OPERATOR-ONLY — " +
39
+ "agents MUST NOT run this command; delegated records keep honest provenance " +
40
+ "(reviewer: agent:<id>, delegatedBy, delegationId). " +
41
+ "Required flags: --scope, --to, --by. Mutates the registry.",
42
+ scope: "workspace",
43
+ coverage: "operator" as const,
44
+ coverageNote:
45
+ "operator-invoked via forge/werkstatt CLI; agents MUST NOT run it (RFC-1336 grants are operator-authored)",
46
+ mutatesState: true,
47
+ mutatingFlags: ["scope", "to", "by"],
48
+ reads: ["authority.delegations.yaml"],
49
+ writes: ["authority.delegations.yaml"],
50
+ generates: [],
51
+ cacheable: false,
52
+ modulePath: "packages/forge/os/authority/handlers/delegate.ts",
53
+ flags: {
54
+ scope: {
55
+ kind: "string",
56
+ required: true,
57
+ description:
58
+ "Delegation scope: editorial.signoff | rfc.decision | version.major | onboarding.decision | fleet.notify | bordbuch.<kind>.",
59
+ },
60
+ to: {
61
+ kind: "string",
62
+ required: true,
63
+ description:
64
+ "Delegate identity: agent:<id> (preferred) or the agent:* wildcard (warns).",
65
+ },
66
+ by: {
67
+ kind: "string",
68
+ required: true,
69
+ description: "Granting human: human:<handle>.",
70
+ },
71
+ site: {
72
+ kind: "string[]",
73
+ description:
74
+ "Site id(s) the grant covers — must resolve to systems-cache siblings. Absent means a workspace-scoped grant.",
75
+ },
76
+ expires: {
77
+ kind: "string",
78
+ description: "Optional ISO-8601 expiry; the grant becomes inactive after it.",
79
+ },
80
+ note: {
81
+ kind: "string",
82
+ description: "Free-text reason recorded on the grant.",
83
+ },
84
+ sign: {
85
+ kind: "boolean",
86
+ description:
87
+ "Sign the entry with SIGNING_PRIVATE_KEY (Ed25519) for provenance hardening.",
88
+ },
89
+ },
90
+ execute: runAuthorityDelegate,
91
+ },
92
+ {
93
+ name: "authority.delegate.revoke",
94
+ description:
95
+ "RFC-1336: revoke a delegation by id — stamps revokedAt and fans out an " +
96
+ "authority-delegation-revoked Bordbuch event per covered site. Idempotent. " +
97
+ "OPERATOR-ONLY — agents MUST NOT run this command. Required flags: --id.",
98
+ scope: "workspace",
99
+ coverage: "operator" as const,
100
+ coverageNote:
101
+ "operator-invoked via forge/werkstatt CLI; agents MUST NOT run it (RFC-1336 revocations are operator-authored)",
102
+ mutatesState: true,
103
+ mutatingFlags: ["id"],
104
+ reads: ["authority.delegations.yaml"],
105
+ writes: ["authority.delegations.yaml"],
106
+ generates: [],
107
+ cacheable: false,
108
+ modulePath: "packages/forge/os/authority/handlers/delegate-revoke.ts",
109
+ flags: {
110
+ id: {
111
+ kind: "string",
112
+ required: true,
113
+ description: "Delegation id to revoke (del-NNNN).",
114
+ },
115
+ by: {
116
+ kind: "string",
117
+ description: "Revoking human (human:<handle>) — recorded when given.",
118
+ },
119
+ },
120
+ execute: runAuthorityDelegateRevoke,
121
+ },
122
+ {
123
+ name: "authority.delegation.list",
124
+ description:
125
+ "RFC-1336: list delegations — active grants by default; --history includes " +
126
+ "revoked/expired history, --site filters to grants covering one site. Read-only.",
127
+ scope: "workspace",
128
+ coverage: "operator" as const,
129
+ coverageNote:
130
+ "operator/agent CLI read — not wired into a pipeline; agents may inspect grants",
131
+ mutatesState: false,
132
+ reads: ["authority.delegations.yaml"],
133
+ cacheable: false,
134
+ modulePath: "packages/forge/os/authority/handlers/delegation-list.ts",
135
+ flags: {
136
+ site: {
137
+ kind: "string",
138
+ description: "Only show grants covering this site (or workspace-scoped).",
139
+ },
140
+ history: {
141
+ kind: "boolean",
142
+ description: "Include revoked and expired delegations.",
143
+ },
144
+ },
145
+ execute: runAuthorityDelegationList,
146
+ },
147
+ {
148
+ name: "authority.delegation.validate",
149
+ description:
150
+ "RFC-1336: validate the authority.delegations.yaml registry — schema, " +
151
+ "duplicate ids, non-delegable scopes, agent:* wildcards, site references, " +
152
+ "signature integrity (DELEG-01..08). Read-only.",
153
+ scope: "workspace",
154
+ coverage: "operator" as const,
155
+ coverageNote:
156
+ "operator/agent CLI read — not wired into a pipeline; agents may audit the registry",
157
+ mutatesState: false,
158
+ contract: "authority",
159
+ rules: [
160
+ "DELEG-01",
161
+ "DELEG-02",
162
+ "DELEG-03",
163
+ "DELEG-04",
164
+ "DELEG-05",
165
+ "DELEG-06",
166
+ "DELEG-07",
167
+ "DELEG-08",
168
+ ],
169
+ reads: ["authority.delegations.yaml"],
170
+ cacheable: false,
171
+ modulePath: "packages/forge/os/authority/handlers/delegation-validate.ts",
172
+ flags: {
173
+ site: {
174
+ kind: "string",
175
+ description: "Restrict DELEG-07 site probes to this site id.",
176
+ },
177
+ },
178
+ execute: runAuthorityDelegationValidate,
179
+ },
180
+ ],
181
+ pipelines: [],
182
+ };
183
+ }