space-data-module-sdk 0.10.4 → 0.11.0

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.
@@ -463,6 +463,66 @@ export async function createSingleFileBundle(options = {}) {
463
463
  };
464
464
  }
465
465
 
466
+ /**
467
+ * The trailer of an ENCRYPTED artifact (`ciphertext || REC` with an ENC
468
+ * record) written again with the given bundle entries and signature. The
469
+ * payload is never read as wasm: it is ciphertext, and it is copied as it is.
470
+ * The ENC and PNM records and the record collection's version are kept. With
471
+ * no bundle in the old trailer, the new one records `contentHash` as its
472
+ * canonical module hash and no manifest hash, as the engine's envelope signer
473
+ * does.
474
+ *
475
+ * @param {Object} options
476
+ * @param {Object} options.publicationRecords - extractPublicationRecordCollection() of the artifact
477
+ * @param {Array} options.entries - bundle entries to keep (no signature entry)
478
+ * @param {Object} options.signature - the signature entry's JSON payload
479
+ * @param {Uint8Array} options.contentHash - sha256 of the payload
480
+ * @returns {Promise<Uint8Array>}
481
+ */
482
+ export async function rewriteProtectedEnvelopeTrailer(options = {}) {
483
+ const records = options.publicationRecords;
484
+ if (!records?.enc) {
485
+ throw new Error(
486
+ "rewriteProtectedEnvelopeTrailer takes only an artifact whose trailer carries an ENC record.",
487
+ );
488
+ }
489
+ const kept = normalizeAdditionalEntries(options.entries ?? []);
490
+ const manifestEntries = kept.filter((entry) => entry.entryId === "manifest");
491
+ const otherEntries = kept.filter((entry) => entry.entryId !== "manifest");
492
+ const rawEntries = [
493
+ ...manifestEntries,
494
+ ...normalizeStandardEntries({ signature: options.signature }),
495
+ ...otherEntries,
496
+ ];
497
+ const entries = [];
498
+ for (const entry of rawEntries) {
499
+ entries.push(await withSha256(entry));
500
+ }
501
+ const base = records.mbl ?? {
502
+ bundleVersion: 1,
503
+ moduleFormat: "space-data-module",
504
+ canonicalization: {
505
+ version: 1,
506
+ strippedCustomSectionPrefix: SDS_CUSTOM_SECTION_PREFIX,
507
+ bundleSectionName: SDS_MBL_CONTAINER_NAME,
508
+ hashAlgorithm: "sha256",
509
+ },
510
+ canonicalModuleHash: normalizeBytes(options.contentHash, "contentHash"),
511
+ manifestHash: [],
512
+ manifestExportSymbol: DEFAULT_MANIFEST_EXPORT_SYMBOL,
513
+ manifestSizeSymbol: DEFAULT_MANIFEST_SIZE_SYMBOL,
514
+ };
515
+ return appendPublicationRecordCollection(
516
+ records.payloadBytes,
517
+ encodePublicationRecordCollection({
518
+ version: records.version,
519
+ mbl: { ...base, entries },
520
+ enc: records.enc,
521
+ pnm: records.pnm,
522
+ }),
523
+ );
524
+ }
525
+
466
526
  export async function parseSingleFileBundle(bytes, options = {}) {
467
527
  const protectedArtifact = extractPublicationRecordCollection(bytes);
468
528
  if (!protectedArtifact?.mbl) {
@@ -5,6 +5,7 @@ import {
5
5
  hasLegacyPmanManifest,
6
6
  loadManifestFromFile,
7
7
  loadComplianceConfig,
8
+ locateBoundPlgManifest,
8
9
  locateEmbeddedPlgManifest,
9
10
  resolveManifestFiles,
10
11
  validatePluginArtifact,
@@ -62,6 +63,7 @@ export {
62
63
  hasLegacyPmanManifest,
63
64
  loadManifestFromFile,
64
65
  loadComplianceConfig,
66
+ locateBoundPlgManifest,
65
67
  locateEmbeddedPlgManifest,
66
68
  RecommendedCapabilityIds,
67
69
  StandaloneWasiCapabilityIds,
@@ -32,6 +32,7 @@ import {
32
32
  } from "../manifest/normalize.js";
33
33
  import { isLegacyWildcardPort } from "./legacyWildcardPorts.js";
34
34
  import { SDS_MANIFEST_SECTION_NAME } from "../bundle/constants.js";
35
+ import { readBoundManifestBytes } from "../bundle/codeManifest.js";
35
36
  import {
36
37
  decodeUnsignedLeb128,
37
38
  getWasmCustomSections,
@@ -2304,19 +2305,77 @@ function decodeManifestCandidate(candidate, options = {}) {
2304
2305
  return { start: 0, identifierOffset: 4, bytes, decoded };
2305
2306
  }
2306
2307
 
2308
+ function containsBytes(haystack, needle) {
2309
+ if (!haystack || needle.length === 0 || haystack.length < needle.length) {
2310
+ return false;
2311
+ }
2312
+ return Buffer.from(haystack.buffer, haystack.byteOffset, haystack.byteLength)
2313
+ .indexOf(Buffer.from(needle.buffer, needle.byteOffset, needle.byteLength)) !== -1;
2314
+ }
2315
+
2316
+ // The manifest found in the code itself (the bytes before any trailer): an
2317
+ // `sds.manifest` custom section, the data segments, the memory image they
2318
+ // build, or a raw scan. These bytes are the ones a publication signature
2319
+ // covers.
2320
+ function locateCodePlgManifest(bytes, options) {
2321
+ for (const sectionBytes of getWasmCustomSections(bytes, SDS_MANIFEST_SECTION_NAME)) {
2322
+ const located = decodeManifestCandidate(sectionBytes, options);
2323
+ if (located) {
2324
+ return { ...located, source: "custom-section" };
2325
+ }
2326
+ }
2327
+ const dataPayloads = concatenateWasmDataSegmentPayloads(bytes);
2328
+ if (dataPayloads) {
2329
+ const located = scanForEmbeddedPlgManifest(dataPayloads, options);
2330
+ if (located) {
2331
+ return { ...located, source: "data-payloads" };
2332
+ }
2333
+ }
2334
+ const memoryImage = reconstructWasmDataMemoryImage(bytes);
2335
+ if (memoryImage) {
2336
+ const located = scanForEmbeddedPlgManifest(memoryImage, options);
2337
+ if (located) {
2338
+ return { ...located, source: "data-memory" };
2339
+ }
2340
+ }
2341
+ const located = scanForEmbeddedPlgManifest(bytes, options);
2342
+ return located ? { ...located, source: "raw-wasm" } : null;
2343
+ }
2344
+
2307
2345
  /**
2308
- * Scan wasm bytes for the canonical `$PLG` FlatBuffer identifier and, when
2309
- * found, return both the raw offset and the smallest aligned candidate buffer
2310
- * that a downstream decoder can try to parse. The wasm `data` sections embed
2311
- * the manifest bytes verbatim; FlatBuffer headers are `<root_offset:u32><$PLG>`
2312
- * so we walk backwards one 4-byte word and hand the caller a slice starting
2313
- * there.
2346
+ * The artifact's embedded `$PLG` manifest, the copy inside the CODE first.
2347
+ *
2348
+ * The code (every byte before the publication trailer) is what a publication
2349
+ * signature covers; the trailer's MBL `manifest` entry is not covered. So:
2350
+ *
2351
+ * - The code's copy is looked for first: an `sds.manifest` custom section,
2352
+ * then the data segments (FlatBuffer headers are `<root_offset:u32><$PLG>`,
2353
+ * so a scan walks back one word from the identifier and hands back a
2354
+ * slice starting there), then their memory image, then a raw scan.
2355
+ * - When the trailer also carries a manifest and its exact bytes appear in
2356
+ * the code (an `sds.manifest` section, the data segments or their memory
2357
+ * image), it is returned with `fromCode: true`.
2358
+ * - When they do not and the code keeps an `sds.manifest` section of its
2359
+ * own, the trailer copy was changed after signing: refused with an Error
2360
+ * whose `code` is `trailer_manifest_mismatch`. A byte scan of the data is
2361
+ * a heuristic (it can land on bytes that only look like a manifest), so a
2362
+ * scan never refuses.
2363
+ * - Otherwise the trailer's copy is returned with `fromCode: false`: this
2364
+ * function could not find it in the code by reading bytes. Most compiled
2365
+ * modules keep their manifest where only running their
2366
+ * `plugin_get_manifest_flatbuffer` export finds it. A caller that must
2367
+ * trust the manifest calls `locateBoundPlgManifest`, which asks the code
2368
+ * and refuses a trailer copy that differs.
2369
+ *
2370
+ * Every result says `fromCode`: true when the bytes were found in the code.
2314
2371
  */
2315
2372
  export function locateEmbeddedPlgManifest(wasmBytes, options = {}) {
2316
2373
  const inputBytes = wasmBytes instanceof Uint8Array
2317
2374
  ? wasmBytes
2318
2375
  : new Uint8Array(wasmBytes);
2319
2376
  const protectedArtifact = extractPublicationRecordCollection(inputBytes);
2377
+ const bytes = protectedArtifact?.payloadBytes ?? inputBytes;
2378
+ let trailer = null;
2320
2379
  for (const entry of protectedArtifact?.mbl?.entries ?? []) {
2321
2380
  if (
2322
2381
  entry?.entryId !== "manifest" &&
@@ -2329,32 +2388,70 @@ export function locateEmbeddedPlgManifest(wasmBytes, options = {}) {
2329
2388
  options,
2330
2389
  );
2331
2390
  if (located) {
2332
- return { ...located, source: "bundle-manifest" };
2391
+ trailer = { ...located, source: "bundle-manifest" };
2392
+ break;
2333
2393
  }
2334
2394
  }
2335
- const bytes = protectedArtifact?.payloadBytes ?? inputBytes;
2336
- for (const sectionBytes of getWasmCustomSections(bytes, SDS_MANIFEST_SECTION_NAME)) {
2337
- const located = decodeManifestCandidate(sectionBytes, options);
2338
- if (located) {
2339
- return { ...located, source: "custom-section" };
2395
+
2396
+ if (trailer) {
2397
+ const sections = getWasmCustomSections(bytes, SDS_MANIFEST_SECTION_NAME);
2398
+ const inCode =
2399
+ sections.some((section) =>
2400
+ section.length === trailer.bytes.length && containsBytes(section, trailer.bytes)) ||
2401
+ containsBytes(concatenateWasmDataSegmentPayloads(bytes), trailer.bytes) ||
2402
+ containsBytes(reconstructWasmDataMemoryImage(bytes), trailer.bytes);
2403
+ if (inCode) {
2404
+ return { ...trailer, fromCode: true };
2340
2405
  }
2341
- }
2342
- const dataPayloads = concatenateWasmDataSegmentPayloads(bytes);
2343
- if (dataPayloads) {
2344
- const located = scanForEmbeddedPlgManifest(dataPayloads, options);
2345
- if (located) {
2346
- return { ...located, source: "data-payloads" };
2406
+ // Refused only against a copy the code certainly carries: its own
2407
+ // `sds.manifest` section. A byte scan of the data is a heuristic (it can
2408
+ // land on bytes that only look like a manifest), so it never refuses.
2409
+ const section = sections
2410
+ .map((sectionBytes) => decodeManifestCandidate(sectionBytes, {}))
2411
+ .find(Boolean);
2412
+ if (section) {
2413
+ throw trailerManifestMismatch(trailer, section.decoded, "its sds.manifest section");
2347
2414
  }
2415
+ return { ...trailer, fromCode: false };
2348
2416
  }
2349
- const memoryImage = reconstructWasmDataMemoryImage(bytes);
2350
- if (memoryImage) {
2351
- const located = scanForEmbeddedPlgManifest(memoryImage, options);
2352
- if (located) {
2353
- return { ...located, source: "data-memory" };
2354
- }
2417
+
2418
+ const code = locateCodePlgManifest(bytes, options);
2419
+ return code ? { ...code, fromCode: true } : null;
2420
+ }
2421
+
2422
+ function trailerManifestMismatch(trailer, codeDecoded, where) {
2423
+ const error = new Error(
2424
+ `the artifact's trailer manifest (${trailer.bytes.length} bytes, pluginId "${trailer.decoded?.pluginId}") is not the manifest its signed code carries in ${where} (pluginId "${codeDecoded?.pluginId}"); the trailer is not covered by the signature and was changed after signing`,
2425
+ );
2426
+ error.code = "trailer_manifest_mismatch";
2427
+ return error;
2428
+ }
2429
+
2430
+ /**
2431
+ * The manifest the SIGNED code carries, asked of the code itself
2432
+ * (`readBoundManifestBytes`: an `sds.manifest` section left in the bytes
2433
+ * before the trailer, else what the code's `plugin_get_manifest_flatbuffer`
2434
+ * export returns, answered from the bytes alone by `readStaticManifestBytes`).
2435
+ * The code is never run here: no signature was verified, so a manifest export
2436
+ * whose body is not a constant, with a trailer copy, is reported
2437
+ * `trailer_manifest_unbound` with `codeNotRun` true. A trailer copy that is
2438
+ * not byte for byte the code's is refused by name
2439
+ * (`trailer_manifest_mismatch`), and a trailer copy with no manifest in the
2440
+ * code to bind it to is refused (`trailer_manifest_unbound`), each as a
2441
+ * ModuleSignatureError. Returns
2442
+ * `{ bytes, decoded, source: "signed-code", fromCode: true }`, or null when
2443
+ * neither the code nor the trailer carries a manifest that decodes, or when
2444
+ * the decoded manifest is not the expected plugin id or version.
2445
+ */
2446
+ export async function locateBoundPlgManifest(wasmBytes, options = {}) {
2447
+ const bound = await readBoundManifestBytes(
2448
+ wasmBytes instanceof Uint8Array ? wasmBytes : new Uint8Array(wasmBytes),
2449
+ );
2450
+ if (!bound) {
2451
+ return null;
2355
2452
  }
2356
- const located = scanForEmbeddedPlgManifest(bytes, options);
2357
- return located ? { ...located, source: "raw-wasm" } : null;
2453
+ const located = decodeManifestCandidate(bound, options);
2454
+ return located ? { ...located, source: "signed-code", fromCode: true } : null;
2358
2455
  }
2359
2456
 
2360
2457
  export function hasLegacyPmanManifest(wasmBytes) {
@@ -2364,7 +2461,7 @@ export function hasLegacyPmanManifest(wasmBytes) {
2364
2461
  return indexOfBytes(bytes, LEGACY_PMAN_IDENTIFIER_BYTES) !== -1;
2365
2462
  }
2366
2463
 
2367
- function validateEmbeddedManifestBytes({
2464
+ async function validateEmbeddedManifestBytes({
2368
2465
  wasmBytes,
2369
2466
  manifest,
2370
2467
  issues,
@@ -2382,10 +2479,25 @@ function validateEmbeddedManifestBytes({
2382
2479
 
2383
2480
  const sourcePluginId = manifest?.pluginId ?? manifest?.plugin_id ?? null;
2384
2481
  const sourceVersion = manifest?.version ?? null;
2385
- const located = locateEmbeddedPlgManifest(wasmBytes, {
2386
- expectedPluginId: sourcePluginId,
2387
- expectedVersion: sourceVersion,
2388
- });
2482
+ // The manifest the signed code carries, asked of the code; the trailer's
2483
+ // copy, which no signature covers, is checked against it.
2484
+ let located = null;
2485
+ try {
2486
+ located = await locateBoundPlgManifest(wasmBytes);
2487
+ located ??= locateEmbeddedPlgManifest(wasmBytes, {
2488
+ expectedPluginId: sourcePluginId,
2489
+ expectedVersion: sourceVersion,
2490
+ });
2491
+ } catch (error) {
2492
+ if (
2493
+ error?.code !== "trailer_manifest_mismatch" &&
2494
+ error?.code !== "trailer_manifest_unbound"
2495
+ ) {
2496
+ throw error;
2497
+ }
2498
+ pushIssue(issues, "error", error.code.replaceAll("_", "-"), error.message, sourceLabel);
2499
+ return;
2500
+ }
2389
2501
  if (!located) {
2390
2502
  pushIssue(
2391
2503
  issues,
@@ -2521,7 +2633,7 @@ export async function validatePluginArtifact(options) {
2521
2633
  );
2522
2634
  }
2523
2635
  if (loadedWasmBytes) {
2524
- validateEmbeddedManifestBytes({
2636
+ await validateEmbeddedManifestBytes({
2525
2637
  wasmBytes: loadedWasmBytes,
2526
2638
  manifest,
2527
2639
  issues,
@@ -81,7 +81,11 @@ import {
81
81
  import { appendWasmCustomSection } from "../bundle/wasm.js";
82
82
  import { runtimeTargetSatisfies } from "../host/runtimeTargetGate.js";
83
83
  import { SDS_MANIFEST_SECTION_NAME } from "../bundle/constants.js";
84
- import { verifyModuleArtifact } from "../bundle/signing.js";
84
+ import {
85
+ SDK_TEST_SIGNER_PUBLIC_KEY_HEX,
86
+ isSdkTestSigner,
87
+ verifyModuleArtifact,
88
+ } from "../bundle/signing.js";
85
89
  import { DOMAIN_MODULE_PUBLICATION_V1 } from "../bundle/sigdomain.js";
86
90
  import { sha256Bytes } from "../utils/crypto.js";
87
91
  import { bytesToHex } from "../utils/encoding.js";
@@ -249,6 +253,7 @@ async function verifyIsomorphicNodeArtifacts({
249
253
  check,
250
254
  dependencies,
251
255
  flowSourcePath,
256
+ allowTestSigner = false,
252
257
  }) {
253
258
  const nodesById = new Map(
254
259
  (flow?.nodes ?? []).map((node) => [node.nodeId, node]),
@@ -295,63 +300,54 @@ async function verifyIsomorphicNodeArtifacts({
295
300
  const publisher = dependency.publisherRecord
296
301
  ? dependency.publisherRecord
297
302
  : JSON.parse(await readFile(publisherPath, "utf8"));
303
+ // A publisher whose own record says developmentOnly is refused, always,
304
+ // as through 0.10.4: allowTestSigner does not admit it.
298
305
  if (publisher?.developmentOnly === true) {
299
306
  throw new Error(
300
307
  `Isomorphic node "${checkedNode.nodeId}" is signed only by a development publisher.`,
301
308
  );
302
309
  }
310
+ // A publisher file says what it likes about itself; the SDK's public test
311
+ // key is a development signer whatever its record claims, and is admitted
312
+ // only when the caller says so (allowTestSigner). Only the test KEY is
313
+ // gated by that option.
314
+ if (isSdkTestSigner(publisher?.publicKeyHex) && allowTestSigner !== true) {
315
+ throw new Error(
316
+ `Isomorphic node "${checkedNode.nodeId}" is signed by the SDK's public test key (${SDK_TEST_SIGNER_PUBLIC_KEY_HEX}), a development signer; pass allowTestSigner: true to compile it.`,
317
+ );
318
+ }
303
319
  if (!/^[0-9a-f]{64}$/.test(publisher?.publicKeyHex ?? "")) {
304
320
  throw new Error(
305
321
  `Isomorphic node "${checkedNode.nodeId}" publisher has no valid Ed25519 public key.`,
306
322
  );
307
323
  }
308
- const verification = await verifyModuleArtifact(artifactBytes, {
309
- trustedPublicKeys: [publisher.publicKeyHex],
310
- requireSignature: true,
311
- });
312
- // WHAT THE FLOW LANE REQUIRES OF A SIGNATURE, and why it is two forms.
313
- //
314
- // Composition inlines somebody else's object code into a binary this
315
- // process then ships. The signature has to bind, at minimum, everything
316
- // that ends up compiled in. Two signatures do that, and they are NOT the
317
- // same statement:
318
- //
319
- // - BUNDLE scope — binds the whole MBL: the canonical module hash, the
320
- // manifest hash, and every non-signature member around it. The widest
321
- // commitment available, and the only one that covers the surrounding
322
- // bundle metadata.
323
- //
324
- // - MODULE scope UNDER THE MODULE-PUBLICATION DOMAIN — the node's own
325
- // signing endpoint (sdn-server/internal/modulesign) issues
326
- // `SDN-MODULE-PUBLICATION-V1 || 0x00 || sha256(portable)`. That covers
327
- // the ENTIRE trailer-stripped payload — the code, the embedded
328
- // manifest section, every sds.* section — which is strictly more of the
329
- // compiled artifact than the canonical hash inside a bundle signature
330
- // binds (the canonical hash strips sds.* before hashing). It does not
331
- // bind the trailer metadata around it; the flow document's own
332
- // artifact.sha256 check above already pinned the exact file bytes, so
333
- // nothing the compiler consumes is left unbound.
334
- //
335
- // A BARE-DIGEST module signature (statementDomain absent, the pre-domain
336
- // SDK form) is still refused here: no domain separation means a signature
337
- // minted over some other protocol's digest can be replayed into this lane,
338
- // and this lane compiles what it admits.
339
- //
340
- // Refusing module scope outright — which this did until 2026-07-30 — meant
341
- // the flow compiler rejected EVERY artifact the node is able to sign, one
342
- // line after verifying it, with a message that blamed the signature rather
343
- // than the policy. See graph/tasks/sdk-flow-compiler-refuses-node-signed.md.
344
- const domainSeparatedModuleScope =
345
- verification.signatureScope === "module" &&
346
- verification.statementDomain === DOMAIN_MODULE_PUBLICATION_V1;
324
+ let verification;
325
+ try {
326
+ verification = await verifyModuleArtifact(artifactBytes, {
327
+ trustedPublicKeys: [publisher.publicKeyHex],
328
+ requireSignature: true,
329
+ });
330
+ } catch (error) {
331
+ if (error?.code === "legacy_module_signature" || error?.code === "legacy_bundle_signature") {
332
+ error.message = `Isomorphic node "${checkedNode.nodeId}": ${error.message}`;
333
+ }
334
+ throw error;
335
+ }
336
+ // WHAT THE FLOW LANE REQUIRES OF A SIGNATURE: the one form, the
337
+ // `SDN-MODULE-PUBLICATION-V1 || 0x00 || sha256(portable)` statement, which
338
+ // covers the ENTIRE trailer-stripped payload (the code, every data segment,
339
+ // every section left in it). It does not bind the trailer around it; the
340
+ // flow document's own artifact.sha256 check above pins the exact file
341
+ // bytes, so nothing the compiler consumes is left unbound. The two forms
342
+ // without a statement domain were removed in 0.11.0 and verifyModuleArtifact
343
+ // refuses them by name before this line.
347
344
  if (
348
345
  !verification.verified ||
349
- (verification.signatureScope !== "bundle" && !domainSeparatedModuleScope)
346
+ verification.statementDomain !== DOMAIN_MODULE_PUBLICATION_V1
350
347
  ) {
351
348
  throw new Error(
352
349
  `Isomorphic node "${checkedNode.nodeId}" artifact signature is not a verified ` +
353
- `whole-bundle signature, nor a module signature under the ` +
354
- `${DOMAIN_MODULE_PUBLICATION_V1} statement domain.`,
350
+ `signature under the ${DOMAIN_MODULE_PUBLICATION_V1} statement domain.`,
355
351
  );
356
352
  }
357
353
  verifiedByPluginId.set(checkedNode.pluginId, {
@@ -3113,6 +3109,7 @@ export async function compileFlowProgram({
3113
3109
  flowSourcePath = null,
3114
3110
  catalog,
3115
3111
  standardsRoot,
3112
+ allowTestSigner = false,
3116
3113
  }) {
3117
3114
  const check = checkFlowProgram({ flow, dependencies });
3118
3115
  if (!check.ok) {
@@ -3128,6 +3125,7 @@ export async function compileFlowProgram({
3128
3125
  check,
3129
3126
  dependencies,
3130
3127
  flowSourcePath,
3128
+ allowTestSigner,
3131
3129
  });
3132
3130
 
3133
3131
  const standardsOptions = { catalog, standardsRoot };
@@ -3,10 +3,9 @@ import {
3
3
  resolveModuleSignaturePolicy,
4
4
  verifyModuleArtifact,
5
5
  } from "../bundle/signing.js";
6
- import { getWasmCustomSections } from "../bundle/wasm.js";
6
+ import { readBoundManifestBytes } from "../bundle/codeManifest.js";
7
7
  import { decodePlgManifest } from "../manifest/plgCodec.js";
8
8
  import { createBrowserModuleHarness } from "../host/browserModuleHarness.js";
9
- import { extractPublicationRecordCollection } from "../transport/records.js";
10
9
  import { sha256Bytes } from "../utils/crypto.js";
11
10
  import { bytesToHex } from "../utils/encoding.js";
12
11
  import { createFlowRuntimeHost } from "./flowRuntimeHost.js";
@@ -45,31 +44,22 @@ function decodeCanonicalPlg(bytes, description) {
45
44
  }
46
45
  }
47
46
 
48
- function embeddedFlowManifest(artifactBytes) {
49
- const publication = extractPublicationRecordCollection(artifactBytes);
50
- for (const entry of publication?.mbl?.entries ?? []) {
51
- if (
52
- entry?.entryId === "manifest" ||
53
- entry?.sectionName === SDS_MANIFEST_SECTION_NAME
54
- ) {
55
- return decodeCanonicalPlg(
56
- exactArtifactBytes(entry.payload),
57
- "Signed flow bundle manifest",
58
- );
59
- }
60
- }
61
-
62
- const portableBytes = publication?.payloadBytes ?? artifactBytes;
63
- const sections = getWasmCustomSections(
64
- portableBytes,
65
- SDS_MANIFEST_SECTION_NAME,
66
- );
67
- if (sections.length === 0) {
47
+ // The flow's node list comes from its SIGNED code: the manifest the parent's
48
+ // running instance returns (or an sds.manifest section left in the bytes
49
+ // before the trailer). The trailer's manifest entry is not covered by the
50
+ // signature; it is only compared with the code's copy, and a difference is
51
+ // refused by name (readBoundManifestBytes).
52
+ async function signedFlowManifest(artifactBytes, parent) {
53
+ const manifestBytes = await readBoundManifestBytes(artifactBytes, {
54
+ instance: parent.instance,
55
+ memory: parent.memory,
56
+ });
57
+ if (!manifestBytes) {
68
58
  throw new Error(
69
- `Isomorphic flow artifact embeds no ${SDS_MANIFEST_SECTION_NAME} PLG manifest.`,
59
+ `Isomorphic flow artifact carries no PLG manifest in its signed code (no ${SDS_MANIFEST_SECTION_NAME} section, no manifest export).`,
70
60
  );
71
61
  }
72
- return decodeCanonicalPlg(sections[0], "Embedded flow manifest");
62
+ return decodeCanonicalPlg(manifestBytes, "Signed flow manifest");
73
63
  }
74
64
 
75
65
  function flowManifestNodes(manifest) {
@@ -215,9 +205,6 @@ export async function createIsomorphicFlowRuntimeHost(options = {}) {
215
205
  if (parentSignaturePolicy) {
216
206
  await verifyModuleArtifact(parentArtifactBytes, parentSignaturePolicy);
217
207
  }
218
- const manifestNodes = flowManifestNodes(
219
- embeddedFlowManifest(parentArtifactBytes),
220
- );
221
208
  const parent = await createFlowRuntimeHost({
222
209
  wasmSource: parentArtifactBytes,
223
210
  // UNCONDITIONAL, with no opt-out. This host mounts every isomorphic child
@@ -235,6 +222,9 @@ export async function createIsomorphicFlowRuntimeHost(options = {}) {
235
222
  legacyHostImportCompat: options.legacyHostImportCompat,
236
223
  engineLink: options.engineLink,
237
224
  });
225
+ const manifestNodes = flowManifestNodes(
226
+ await signedFlowManifest(parentArtifactBytes, parent),
227
+ );
238
228
  const declared = new Map();
239
229
  for (let index = 0; index < parent.dependencyCount; index += 1) {
240
230
  const descriptor = parent.getDependencyDescriptor(index);