@kungfu-tech/buildchain 3.0.9-alpha.10 → 3.0.9-alpha.11

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.
@@ -0,0 +1,395 @@
1
+ import { initAdopterManifest } from "@kungfu-tech/kfd/adopter-conformance/toolchain";
2
+
3
+ import { adopterDeliveryGateDigest } from "./adopter-delivery-gate.js";
4
+ import { withPublishedBuildchainDeliveryAuthority } from "./published-delivery-authority.js";
5
+
6
+ export const BUILDCHAIN_DELIVERY_SELF_DOGFOOD_CONTRACT =
7
+ "kungfu-buildchain-delivery-infrastructure-self-dogfood/v1";
8
+
9
+ const ROOT_PATTERN = /^sha256:[0-9a-f]{64}$/;
10
+ const SHA_PATTERN = /^[0-9a-f]{40}$/;
11
+ const BUILDCHAIN_PACKAGE = "@kungfu-tech/buildchain";
12
+ const KFD_PACKAGE = "@kungfu-tech/kfd";
13
+ const PROFILE_REQUIREMENTS = Object.freeze([
14
+ ["adopter-identity", ["declaration"]],
15
+ ["artifact-readback", ["verification"]],
16
+ ["claim-boundary", ["declaration"]],
17
+ ["delivery-policy-cut", ["declaration", "verification"]],
18
+ ["kfd-cut", ["verification"]],
19
+ ["protected-delivery", ["implementation", "review", "verification"]],
20
+ ["source-artifact", ["implementation"]],
21
+ ]);
22
+
23
+ function exactPackage(value, { name, version = "", root = "", label }) {
24
+ if (
25
+ value?.name !== name ||
26
+ typeof value.version !== "string" ||
27
+ value.version.length === 0 ||
28
+ !ROOT_PATTERN.test(value.artifactRoot ?? "")
29
+ ) {
30
+ throw new TypeError(`${label} package identity is incomplete`);
31
+ }
32
+ if (version && value.version !== version) {
33
+ throw new TypeError(`${label} package version does not match its binding`);
34
+ }
35
+ if (root && value.artifactRoot !== root) {
36
+ throw new TypeError(`${label} package root does not match its binding`);
37
+ }
38
+ return structuredClone(value);
39
+ }
40
+
41
+ function authorityFunctions(authorityRuntime) {
42
+ const names = [
43
+ "createBuildchainDeliveryInfrastructureInstanceManifest",
44
+ "verifyBuildchainDeliveryInfrastructureInstance",
45
+ "createAdopterDeliveryGate",
46
+ "createPackageArtifactProfile",
47
+ "createKfdAdopterCategoryProtocolDriver",
48
+ "qualifyBuildchainDeliveryInfrastructureBootstrap",
49
+ ];
50
+ for (const name of names) {
51
+ if (typeof authorityRuntime?.[name] !== "function") {
52
+ throw new TypeError(`authority runtime is missing ${name}`);
53
+ }
54
+ }
55
+ return authorityRuntime;
56
+ }
57
+
58
+ function passed(value, label) {
59
+ if (value?.status !== "passed") {
60
+ throw new Error(
61
+ `${label} failed closed: ${JSON.stringify(value?.issues ?? [])}`,
62
+ );
63
+ }
64
+ return value;
65
+ }
66
+
67
+ function candidateWarrant(candidate) {
68
+ const terminal = candidate?.terminal;
69
+ if (
70
+ candidate?.status !== "merged" ||
71
+ !SHA_PATTERN.test(candidate?.sourceHead ?? "") ||
72
+ !ROOT_PATTERN.test(candidate?.sourceProofRoot ?? "") ||
73
+ terminal?.outcome !== "merged" ||
74
+ !ROOT_PATTERN.test(terminal?.nativeProofRoot ?? "") ||
75
+ !ROOT_PATTERN.test(terminal?.evidenceRoot ?? "")
76
+ ) {
77
+ throw new TypeError("candidate Warrant settlement is incomplete");
78
+ }
79
+ return {
80
+ outcome: "merged",
81
+ sourceHead: candidate.sourceHead,
82
+ sourceProofRoot: candidate.sourceProofRoot,
83
+ nativeProofRoot: terminal.nativeProofRoot,
84
+ integrationProofRoot: terminal.evidenceRoot,
85
+ };
86
+ }
87
+
88
+ function deliveryCut() {
89
+ const protocol = {
90
+ id: "kfd.adopter-category/instance-manifest",
91
+ version: "1.0.0",
92
+ };
93
+ protocol.root = adopterDeliveryGateDigest(protocol);
94
+ const profile = {
95
+ id: "kfd.adopter-category/delivery-infrastructure",
96
+ version: "1.0.0",
97
+ };
98
+ profile.root = adopterDeliveryGateDigest({
99
+ ...profile,
100
+ requirements: PROFILE_REQUIREMENTS,
101
+ });
102
+ return {
103
+ gateRoot: adopterDeliveryGateDigest({
104
+ protocol,
105
+ profile,
106
+ artifactProfile: {
107
+ id: "buildchain.artifact/package",
108
+ version: "1.0.0",
109
+ },
110
+ }),
111
+ protocol,
112
+ profile,
113
+ };
114
+ }
115
+
116
+ function candidateEvidence({
117
+ source,
118
+ artifact,
119
+ authority,
120
+ warrant,
121
+ kfdRoot,
122
+ observedAt,
123
+ }) {
124
+ const roots = {
125
+ "adopter-identity:declaration": source.root,
126
+ "artifact-readback:verification": artifact.root,
127
+ "claim-boundary:declaration": adopterDeliveryGateDigest({
128
+ qualifying: false,
129
+ selfCertified: false,
130
+ releaseAuthorized: false,
131
+ }),
132
+ "delivery-policy-cut:declaration": authority.gateRoot,
133
+ "delivery-policy-cut:verification": warrant.integrationProofRoot,
134
+ "kfd-cut:verification": kfdRoot,
135
+ "protected-delivery:implementation": artifact.root,
136
+ "protected-delivery:review": warrant.sourceProofRoot,
137
+ "protected-delivery:verification": warrant.nativeProofRoot,
138
+ "source-artifact:implementation": source.root,
139
+ };
140
+ return PROFILE_REQUIREMENTS.flatMap(([requirementId, kinds]) =>
141
+ kinds.map((kind) => ({
142
+ requirementId,
143
+ kind,
144
+ coordinate: `evidence://kungfu-systems/buildchain/${requirementId}/${kind}`,
145
+ root: roots[`${requirementId}:${kind}`],
146
+ observedAt,
147
+ })),
148
+ );
149
+ }
150
+
151
+ export function createBuildchainDeliveryInfrastructureSelfDogfood(
152
+ {
153
+ authorityPackage,
154
+ kfdPackage,
155
+ authority,
156
+ candidate,
157
+ instanceId,
158
+ adopterManifest,
159
+ source,
160
+ artifact,
161
+ release,
162
+ evidence = [],
163
+ warrant,
164
+ transitionEvidence,
165
+ verifiedAt,
166
+ maxAgeSeconds,
167
+ } = {},
168
+ authorityRuntime,
169
+ ) {
170
+ const runtime = authorityFunctions(authorityRuntime);
171
+ const boundAuthorityPackage = exactPackage(authorityPackage, {
172
+ name: BUILDCHAIN_PACKAGE,
173
+ version: authority?.version,
174
+ root: authority?.packageRoot,
175
+ label: "Buildchain authority",
176
+ });
177
+ const boundKfdPackage = exactPackage(kfdPackage, {
178
+ name: KFD_PACKAGE,
179
+ version: adopterManifest?.kfdCut?.package?.version,
180
+ root: adopterManifest?.kfdCut?.package?.artifactRoot,
181
+ label: "KFD authority",
182
+ });
183
+ if (candidate?.authorityVersion !== boundAuthorityPackage.version) {
184
+ throw new TypeError(
185
+ "candidate does not name the exact Buildchain N-1 authority",
186
+ );
187
+ }
188
+
189
+ const instanceManifest =
190
+ runtime.createBuildchainDeliveryInfrastructureInstanceManifest({
191
+ instanceId,
192
+ adopterManifest,
193
+ source,
194
+ artifact,
195
+ release,
196
+ evidence,
197
+ });
198
+ const instanceReport = runtime.verifyBuildchainDeliveryInfrastructureInstance(
199
+ instanceManifest,
200
+ {
201
+ adopterManifest,
202
+ verifiedAt,
203
+ maxAgeSeconds,
204
+ },
205
+ );
206
+ if (instanceReport?.valid !== true) {
207
+ throw new Error(
208
+ `delivery-infrastructure instance failed closed: ${JSON.stringify(instanceReport?.issues ?? [])}`,
209
+ );
210
+ }
211
+
212
+ const gateResult = passed(
213
+ runtime
214
+ .createAdopterDeliveryGate({
215
+ drivers: [runtime.createKfdAdopterCategoryProtocolDriver()],
216
+ artifactProfiles: [runtime.createPackageArtifactProfile()],
217
+ })
218
+ .evaluate(
219
+ {
220
+ schemaVersion: 1,
221
+ contract: "kungfu-buildchain-adopter-delivery-request",
222
+ protocol: {
223
+ id: "kfd.adopter-category/instance-manifest",
224
+ version: "1.0.0",
225
+ },
226
+ artifactProfile: {
227
+ id: "buildchain.artifact/package",
228
+ version: "1.0.0",
229
+ },
230
+ project: {
231
+ instanceId,
232
+ adopterId: "kungfu-systems/buildchain",
233
+ },
234
+ artifact: structuredClone(artifact),
235
+ declaration: instanceManifest,
236
+ },
237
+ { adopterManifest, verifiedAt, maxAgeSeconds },
238
+ ),
239
+ "adopter delivery gate",
240
+ );
241
+ const bootstrap = passed(
242
+ runtime.qualifyBuildchainDeliveryInfrastructureBootstrap({
243
+ authority,
244
+ candidate,
245
+ gateResult,
246
+ warrant,
247
+ transitionEvidence,
248
+ }),
249
+ "delivery-infrastructure bootstrap",
250
+ );
251
+
252
+ const result = {
253
+ schemaVersion: 1,
254
+ contract: BUILDCHAIN_DELIVERY_SELF_DOGFOOD_CONTRACT,
255
+ status: "passed",
256
+ authorityRuntime: {
257
+ buildchainPackage: boundAuthorityPackage,
258
+ kfdPackage: boundKfdPackage,
259
+ },
260
+ candidate: structuredClone(candidate),
261
+ roots: {
262
+ adopterManifest: adopterDeliveryGateDigest(adopterManifest),
263
+ instanceManifest: adopterDeliveryGateDigest(instanceManifest),
264
+ instanceReport: adopterDeliveryGateDigest(instanceReport),
265
+ gateResult: gateResult.gateRoot,
266
+ bootstrap: bootstrap.bootstrapRoot,
267
+ warrant: adopterDeliveryGateDigest(warrant),
268
+ },
269
+ instanceManifest,
270
+ instanceReport,
271
+ gateResult,
272
+ bootstrap,
273
+ qualifying: false,
274
+ selfCertified: false,
275
+ releaseAuthorized: false,
276
+ finalAuthority:
277
+ "protected-n-minus-one-runtime-plus-exact-delivery-evidence",
278
+ };
279
+ result.selfDogfoodRoot = adopterDeliveryGateDigest(result);
280
+ return result;
281
+ }
282
+
283
+ export async function createPublishedBuildchainDeliveryInfrastructureSelfDogfood({
284
+ authorityPackages,
285
+ selfDogfood,
286
+ } = {}) {
287
+ return withPublishedBuildchainDeliveryAuthority(
288
+ authorityPackages,
289
+ async ({ packages, authorityRuntime, authorityRoot }) => {
290
+ const result = createBuildchainDeliveryInfrastructureSelfDogfood(
291
+ {
292
+ ...structuredClone(selfDogfood ?? {}),
293
+ authorityPackage: packages.buildchain,
294
+ kfdPackage: packages.kfd,
295
+ },
296
+ authorityRuntime,
297
+ );
298
+ return {
299
+ ...result,
300
+ publishedAuthorityRoot: authorityRoot,
301
+ };
302
+ },
303
+ );
304
+ }
305
+
306
+ export async function createPublishedBuildchainDeliveryInfrastructureCandidateSelfDogfood({
307
+ authorityPackages,
308
+ authoritySourceCommit,
309
+ candidatePackage,
310
+ warrantCandidate,
311
+ source,
312
+ release,
313
+ verifiedAt,
314
+ maxAgeSeconds = 86400,
315
+ } = {}) {
316
+ if (!SHA_PATTERN.test(authoritySourceCommit ?? "")) {
317
+ throw new TypeError("authority source commit is invalid");
318
+ }
319
+ const artifact = exactPackage(candidatePackage, {
320
+ name: BUILDCHAIN_PACKAGE,
321
+ label: "Buildchain candidate",
322
+ });
323
+ if (
324
+ source?.coordinate !==
325
+ `kungfu-systems/buildchain@${warrantCandidate?.sourceHead ?? ""}` ||
326
+ !ROOT_PATTERN.test(source?.root ?? "") ||
327
+ !ROOT_PATTERN.test(release?.root ?? "")
328
+ ) {
329
+ throw new TypeError("candidate source or release binding is incomplete");
330
+ }
331
+ const warrant = candidateWarrant(warrantCandidate);
332
+ const cut = deliveryCut();
333
+ const authority = {
334
+ version: authorityPackages?.buildchain?.version,
335
+ sourceCommit: authoritySourceCommit,
336
+ packageRoot: authorityPackages?.buildchain?.artifactRoot,
337
+ ...cut,
338
+ protected: true,
339
+ published: true,
340
+ };
341
+ const candidate = {
342
+ version: artifact.version,
343
+ sourceCommit: warrant.sourceHead,
344
+ packageRoot: artifact.artifactRoot,
345
+ ...cut,
346
+ authorityVersion: authority.version,
347
+ };
348
+ const adopterManifest = initAdopterManifest({
349
+ manifestId: `buildchain-delivery-infrastructure-${artifact.version}`,
350
+ adopterId: "kungfu-systems/buildchain",
351
+ artifactKind: "package",
352
+ artifactCoordinate: `${artifact.name}@${artifact.version}`,
353
+ artifactRoot: artifact.artifactRoot,
354
+ scope: "Buildchain delivery infrastructure release candidate self-dogfood",
355
+ packageArtifactRoot: authorityPackages?.kfd?.artifactRoot,
356
+ verifiedAt,
357
+ maxAgeSeconds,
358
+ });
359
+ adopterManifest.releaseBindings.push({
360
+ id: `buildchain-${artifact.version}`,
361
+ artifact: {
362
+ kind: "package",
363
+ coordinate: `${artifact.name}@${artifact.version}`,
364
+ root: artifact.artifactRoot,
365
+ },
366
+ releasePassport: structuredClone(release),
367
+ kfdPackageRoot: authorityPackages.kfd.artifactRoot,
368
+ });
369
+ const evidence = candidateEvidence({
370
+ source,
371
+ artifact: adopterManifest.releaseBindings[0].artifact,
372
+ authority,
373
+ warrant,
374
+ kfdRoot: authorityPackages.kfd.artifactRoot,
375
+ observedAt: verifiedAt,
376
+ });
377
+ const result =
378
+ await createPublishedBuildchainDeliveryInfrastructureSelfDogfood({
379
+ authorityPackages,
380
+ selfDogfood: {
381
+ authority,
382
+ candidate,
383
+ instanceId: `kungfu-systems/buildchain@${artifact.version}`,
384
+ adopterManifest,
385
+ source,
386
+ artifact: adopterManifest.releaseBindings[0].artifact,
387
+ release,
388
+ evidence,
389
+ warrant,
390
+ verifiedAt,
391
+ maxAgeSeconds,
392
+ },
393
+ });
394
+ return { ...result, adopterManifest, deliveryEvidence: evidence };
395
+ }
@@ -610,6 +610,7 @@ export function closeDevDeliveryWarrant(queueInput, warrant, { outcome, evidence
610
610
  closedAt: currentTime,
611
611
  fencingToken: active.fencingToken,
612
612
  leaseGeneration: active.generation,
613
+ ...(active.nativeProofRoot ? { nativeProofRoot: exactRoot(active.nativeProofRoot, "nativeProofRoot") } : {}),
613
614
  };
614
615
  queue.activeWarrant = null;
615
616
  return { candidate, active };
@@ -0,0 +1,247 @@
1
+ import { createHash } from "node:crypto";
2
+ import { createReadStream } from "node:fs";
3
+ import { mkdir, mkdtemp, readFile, realpath, rm } from "node:fs/promises";
4
+ import { tmpdir } from "node:os";
5
+ import path from "node:path";
6
+ import { promisify } from "node:util";
7
+ import { pathToFileURL } from "node:url";
8
+ import { execFile } from "node:child_process";
9
+
10
+ import { adopterDeliveryGateDigest } from "./adopter-delivery-gate.js";
11
+
12
+ export const PUBLISHED_DELIVERY_AUTHORITY_CONTRACT =
13
+ "kungfu-buildchain-published-delivery-authority/v1";
14
+
15
+ const execFileAsync = promisify(execFile);
16
+ const ROOT_PATTERN = /^sha256:[0-9a-f]{64}$/;
17
+ const PACKAGES = [
18
+ {
19
+ key: "buildchain",
20
+ name: "@kungfu-tech/buildchain",
21
+ packageRoot: "archive",
22
+ modules: {
23
+ adopterDeliveryGate: "packages/core/adopter-delivery-gate.js",
24
+ bootstrap: "packages/core/buildchain-delivery-bootstrap.js",
25
+ infrastructure: "packages/core/buildchain-delivery-infrastructure.js",
26
+ kfdCategoryDriver: "packages/core/kfd-adopter-category-driver.js",
27
+ },
28
+ },
29
+ {
30
+ key: "kfd",
31
+ name: "@kungfu-tech/kfd",
32
+ packageRoot: "profiles/adopter-conformance/adopters/kfd/manifest.json",
33
+ modules: {},
34
+ },
35
+ ];
36
+
37
+ async function sha256File(file) {
38
+ const hash = createHash("sha256");
39
+ for await (const chunk of createReadStream(file)) hash.update(chunk);
40
+ return `sha256:${hash.digest("hex")}`;
41
+ }
42
+
43
+ function exactDeclaration(value, expectedName, label) {
44
+ if (
45
+ value?.name !== expectedName ||
46
+ typeof value.version !== "string" ||
47
+ value.version.length === 0 ||
48
+ typeof value.archivePath !== "string" ||
49
+ value.archivePath.length === 0 ||
50
+ !ROOT_PATTERN.test(value.archiveRoot ?? "") ||
51
+ !ROOT_PATTERN.test(value.artifactRoot ?? "")
52
+ ) {
53
+ throw new TypeError(`${label} package declaration is incomplete`);
54
+ }
55
+ return structuredClone(value);
56
+ }
57
+
58
+ function safeArchiveEntries(listing, verboseListing, label) {
59
+ const entries = listing.split("\n").filter(Boolean);
60
+ const types = verboseListing.split("\n").filter(Boolean);
61
+ if (entries.length === 0 || entries.length !== types.length) {
62
+ throw new Error(`${label} archive listing is incomplete`);
63
+ }
64
+ for (let index = 0; index < entries.length; index += 1) {
65
+ const entry = entries[index];
66
+ const parts = entry.split("/");
67
+ if (
68
+ parts[0] !== "package" ||
69
+ parts.some((part, partIndex) =>
70
+ partIndex === parts.length - 1 && part === ""
71
+ ? false
72
+ : part === "" || part === "." || part === "..",
73
+ )
74
+ ) {
75
+ throw new Error(`${label} archive contains an unsafe path`);
76
+ }
77
+ if (!["-", "d"].includes(types[index][0])) {
78
+ throw new Error(`${label} archive contains a non-file entry`);
79
+ }
80
+ }
81
+ }
82
+
83
+ async function extractPackage(declaration, destination, definition, label) {
84
+ const observedRoot = await sha256File(declaration.archivePath);
85
+ if (observedRoot !== declaration.archiveRoot) {
86
+ throw new Error(`${label} archive bytes do not match archiveRoot`);
87
+ }
88
+ const [{ stdout: listing }, { stdout: verboseListing }] = await Promise.all([
89
+ execFileAsync("tar", ["-tzf", declaration.archivePath], {
90
+ maxBuffer: 16 * 1024 * 1024,
91
+ }),
92
+ execFileAsync("tar", ["-tvzf", declaration.archivePath], {
93
+ maxBuffer: 16 * 1024 * 1024,
94
+ }),
95
+ ]);
96
+ safeArchiveEntries(listing, verboseListing, label);
97
+ await mkdir(destination, { recursive: true });
98
+ await execFileAsync(
99
+ "tar",
100
+ [
101
+ "-xzf",
102
+ declaration.archivePath,
103
+ "--strip-components",
104
+ "1",
105
+ "-C",
106
+ destination,
107
+ ],
108
+ { maxBuffer: 16 * 1024 * 1024 },
109
+ );
110
+ const packageJsonPath = path.join(destination, "package.json");
111
+ const packageJson = JSON.parse(await readFile(packageJsonPath, "utf8"));
112
+ if (
113
+ packageJson.name !== declaration.name ||
114
+ packageJson.version !== declaration.version
115
+ ) {
116
+ throw new Error(`${label} extracted package identity does not match`);
117
+ }
118
+ if (definition.packageRoot === "archive") {
119
+ if (declaration.artifactRoot !== declaration.archiveRoot) {
120
+ throw new Error(`${label} package artifactRoot must match archiveRoot`);
121
+ }
122
+ } else {
123
+ const packageManifest = JSON.parse(
124
+ await readFile(path.join(destination, definition.packageRoot), "utf8"),
125
+ );
126
+ const packageCut = packageManifest?.kfdCut?.package;
127
+ if (
128
+ packageCut?.name !== declaration.name ||
129
+ packageCut?.version !== declaration.version ||
130
+ packageCut?.artifactRoot !== declaration.artifactRoot
131
+ ) {
132
+ throw new Error(`${label} semantic package identity does not match`);
133
+ }
134
+ }
135
+ const destinationRoot = await realpath(destination);
136
+ if (!destinationRoot.endsWith(path.join(...declaration.name.split("/")))) {
137
+ throw new Error(`${label} extraction escaped its package coordinate`);
138
+ }
139
+ return {
140
+ name: declaration.name,
141
+ version: declaration.version,
142
+ archiveRoot: declaration.archiveRoot,
143
+ artifactRoot: declaration.artifactRoot,
144
+ };
145
+ }
146
+
147
+ async function importAuthorityRuntime(buildchainRoot) {
148
+ const definition = PACKAGES[0];
149
+ const imported = {};
150
+ for (const [key, relativePath] of Object.entries(definition.modules)) {
151
+ imported[key] = await import(
152
+ pathToFileURL(path.join(buildchainRoot, relativePath)).href
153
+ );
154
+ }
155
+ const runtime = {
156
+ createAdopterDeliveryGate:
157
+ imported.adopterDeliveryGate.createAdopterDeliveryGate,
158
+ createPackageArtifactProfile:
159
+ imported.adopterDeliveryGate.createPackageArtifactProfile,
160
+ qualifyBuildchainDeliveryInfrastructureBootstrap:
161
+ imported.bootstrap.qualifyBuildchainDeliveryInfrastructureBootstrap,
162
+ createBuildchainDeliveryInfrastructureInstanceManifest:
163
+ imported.infrastructure
164
+ .createBuildchainDeliveryInfrastructureInstanceManifest,
165
+ verifyBuildchainDeliveryInfrastructureInstance:
166
+ imported.infrastructure.verifyBuildchainDeliveryInfrastructureInstance,
167
+ createKfdAdopterCategoryProtocolDriver:
168
+ imported.kfdCategoryDriver.createKfdAdopterCategoryProtocolDriver,
169
+ };
170
+ for (const [name, implementation] of Object.entries(runtime)) {
171
+ if (typeof implementation !== "function") {
172
+ throw new Error(`published Buildchain authority is missing ${name}`);
173
+ }
174
+ }
175
+ return runtime;
176
+ }
177
+
178
+ export async function loadPublishedBuildchainDeliveryAuthority({
179
+ buildchain,
180
+ kfd,
181
+ } = {}) {
182
+ const declarations = {
183
+ buildchain: exactDeclaration(
184
+ buildchain,
185
+ "@kungfu-tech/buildchain",
186
+ "Buildchain authority",
187
+ ),
188
+ kfd: exactDeclaration(kfd, "@kungfu-tech/kfd", "KFD authority"),
189
+ };
190
+ const temporaryRoot = await mkdtemp(
191
+ path.join(tmpdir(), "buildchain-published-delivery-authority-"),
192
+ );
193
+ let retained = false;
194
+ try {
195
+ const identities = {};
196
+ for (const definition of PACKAGES) {
197
+ identities[definition.key] = await extractPackage(
198
+ declarations[definition.key],
199
+ path.join(temporaryRoot, "node_modules", ...definition.name.split("/")),
200
+ definition,
201
+ `${definition.key} authority`,
202
+ );
203
+ }
204
+ const authorityRuntime = await importAuthorityRuntime(
205
+ path.join(temporaryRoot, "node_modules", ...PACKAGES[0].name.split("/")),
206
+ );
207
+ const authority = {
208
+ schemaVersion: 1,
209
+ contract: PUBLISHED_DELIVERY_AUTHORITY_CONTRACT,
210
+ packages: identities,
211
+ moduleCoordinates: structuredClone(PACKAGES[0].modules),
212
+ qualifying: false,
213
+ selfCertified: false,
214
+ releaseAuthorized: false,
215
+ finalAuthority:
216
+ "caller-bound-public-npm-archive-bytes-and-package-identity",
217
+ };
218
+ authority.authorityRoot = adopterDeliveryGateDigest(authority);
219
+ retained = true;
220
+ return {
221
+ ...authority,
222
+ authorityRuntime,
223
+ temporaryRoot,
224
+ async dispose() {
225
+ await rm(temporaryRoot, { recursive: true, force: true });
226
+ },
227
+ };
228
+ } finally {
229
+ if (!retained) await rm(temporaryRoot, { recursive: true, force: true });
230
+ }
231
+ }
232
+
233
+ export async function withPublishedBuildchainDeliveryAuthority(
234
+ declarations,
235
+ operation,
236
+ ) {
237
+ if (typeof operation !== "function") {
238
+ throw new TypeError("published authority operation must be a function");
239
+ }
240
+ const authority =
241
+ await loadPublishedBuildchainDeliveryAuthority(declarations);
242
+ try {
243
+ return await operation(authority);
244
+ } finally {
245
+ await authority.dispose();
246
+ }
247
+ }
@@ -1533,7 +1533,7 @@ export function collectGitHubReleasePassport({
1533
1533
  kfd2ClaimJsons = [],
1534
1534
  kfd3PrebuildWitnessJsons = [],
1535
1535
  kfd3ArtifactWitnessJsons = [],
1536
- kfd3ArtifactVerifyCommand = "",
1536
+ kfd3ArtifactVerifyCommand = "", adopterDeliveryJson = "",
1537
1537
  kfdAdopterManifestJson = "",
1538
1538
  kfdSupportMatrixJson = "",
1539
1539
  kfdProductGateJsons = [],
@@ -1594,6 +1594,11 @@ export function collectGitHubReleasePassport({
1594
1594
  cwd,
1595
1595
  label: "KFD-3 artifact verify command",
1596
1596
  });
1597
+ const adopterDelivery = parseJsonInput(
1598
+ adopterDeliveryJson,
1599
+ undefined,
1600
+ { cwd, label: "adopterDeliveryJson" },
1601
+ );
1597
1602
  const basePassportMeta = parseJsonInputWithMeta(basePassportJson, undefined, { cwd, label: "basePassportJson" });
1598
1603
  const invariantPassportMetas = (invariantPassportJsons || [])
1599
1604
  .filter(Boolean)
@@ -1684,6 +1689,7 @@ export function collectGitHubReleasePassport({
1684
1689
  tag: resolvedTag,
1685
1690
  sourceSha,
1686
1691
  workflow,
1692
+ adopterDelivery,
1687
1693
  kfdAdopter,
1688
1694
  });
1689
1695
  const bundledPublishEvidencePath = publishEvidenceMeta.value ? "evidence.json" : "";
@@ -1750,6 +1756,7 @@ export function collectGitHubReleasePassport({
1750
1756
  kfd1,
1751
1757
  kfd2Claims: kfd2ClaimMetas.map((meta) => meta.value),
1752
1758
  kfd3,
1759
+ adopterDelivery,
1753
1760
  kfdAdopter,
1754
1761
  kfdAdopterManifestEvidencePath: kfdAdopter ? "kfd-adopter-manifest.json" : "",
1755
1762
  kfdAdopterGateEvidencePath: kfdAdopter ? "kfd-adopter-manifest-gate.json" : "",
@@ -67,6 +67,7 @@ export const BUILDCHAIN_USAGE = `Usage:
67
67
  [--kfd-3-prebuild-witness-json <json-or-path>]...
68
68
  [--kfd-3-artifact-witness-json <json-or-path>]...
69
69
  [--kfd-3-artifact-verify-cmd <command>]
70
+ [--adopter-delivery-json <json-or-path>]
70
71
  [--kfd-adopter-manifest-json <json-or-path>]
71
72
  [--kfd-support-matrix-json <json-or-path>]
72
73
  [--kfd-product-gate-json <json-or-path>]...
@@ -1003,7 +1003,7 @@ for (const forbiddenSnippet of [
1003
1003
  for (const requiredSnippet of [
1004
1004
  "id-token: write",
1005
1005
  "actions: write",
1006
- "uses: kungfu-systems/buildchain/.github/workflows/release-candidate-promote.yml@cc6c32845ab5779009aeb48cc34efe65e229fe30\n",
1006
+ "uses: kungfu-systems/buildchain/.github/workflows/release-candidate-promote.yml@15db8a9d7c39f7a649a0e3971af68490356dd9ac\n",
1007
1007
  "github.event.workflow_run.event == 'push'",
1008
1008
  "!startsWith(github.event.workflow_run.display_title, 'chore(release): prepare v')",
1009
1009
  "!startsWith(github.event.workflow_run.display_title, 'chore(release): release v')",