@plasius/gpu-shader 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -34,6 +34,7 @@ __export(src_exports, {
34
34
  SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES: () => SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES,
35
35
  activateStyleProfile: () => activateStyleProfile,
36
36
  asSha256Hex: () => asSha256Hex,
37
+ assertImmutableAssetVersion: () => assertImmutableAssetVersion,
37
38
  canonicalizeGpuContract: () => canonicalizeGpuContract,
38
39
  computeGpuAbiHash: () => computeGpuAbiHash,
39
40
  computeSha256: () => computeSha256,
@@ -74,69 +75,299 @@ var SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES = [
74
75
  Object.freeze(SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES);
75
76
  var SUPPORTED_ADDITIVE_WEBGPU_MATRIX_POLICIES = Object.freeze([]);
76
77
 
78
+ // src/asset-version.ts
79
+ var ASSET_VERSION_PATTERN = /^[0-9A-Za-z][0-9A-Za-z._-]{0,127}$/u;
80
+ var MUTABLE_VERSION_ALIASES = /* @__PURE__ */ new Set([
81
+ "latest",
82
+ "current",
83
+ "stable",
84
+ "preview",
85
+ "default",
86
+ "production",
87
+ "canary",
88
+ "next",
89
+ "head",
90
+ "main"
91
+ ]);
92
+ var X_WILDCARD_SEGMENT_PATTERN = /^(?:[vV])?[xX](?:\.|-|$)|\.[xX](?:\.|-|$)/u;
93
+ var IMMUTABLE_VERSION_ERROR_MESSAGE = "Immutable asset version must be an exact token up to 128 characters; mutable aliases, ranges, wildcards, and URLs are not allowed.";
94
+ function assertImmutableAssetVersion(value) {
95
+ if (typeof value !== "string" || !ASSET_VERSION_PATTERN.test(value) || MUTABLE_VERSION_ALIASES.has(value.toLowerCase()) || X_WILDCARD_SEGMENT_PATTERN.test(value)) {
96
+ throw new TypeError(IMMUTABLE_VERSION_ERROR_MESSAGE);
97
+ }
98
+ return value;
99
+ }
100
+
77
101
  // src/canonical-json.ts
78
- function isPlainObject(value) {
79
- const prototype = Object.getPrototypeOf(value);
80
- return prototype === Object.prototype || prototype === null;
102
+ var GPU_CONTRACT_SNAPSHOT_LIMITS = Object.freeze({
103
+ maximumDepth: 64,
104
+ maximumNodes: 262144,
105
+ maximumProperties: 131072,
106
+ maximumElements: 131072,
107
+ maximumArrayLength: 1e5,
108
+ maximumStringBytes: 1024 * 1024,
109
+ maximumAggregateStringBytes: 8 * 1024 * 1024,
110
+ maximumAggregateBytes: 16 * 1024 * 1024,
111
+ maximumInputBytes: 16 * 1024 * 1024
112
+ });
113
+ var QUALIFICATION_GPU_CONTRACT_SNAPSHOT_LIMITS = Object.freeze({
114
+ maximumDepth: 96,
115
+ maximumNodes: 4e6,
116
+ maximumProperties: 2e6,
117
+ maximumElements: 2e6,
118
+ maximumArrayLength: 25e4,
119
+ maximumStringBytes: 4 * 1024 * 1024,
120
+ maximumAggregateStringBytes: 128 * 1024 * 1024,
121
+ maximumAggregateBytes: 256 * 1024 * 1024,
122
+ maximumInputBytes: 256 * 1024 * 1024
123
+ });
124
+ var FAILURE_MESSAGES = Object.freeze({
125
+ "aggregate-bytes": "GPU contract snapshot exceeds the aggregate byte limit.",
126
+ "aggregate-string-bytes": "GPU contract snapshot exceeds the aggregate string byte limit.",
127
+ "array-length": "GPU contract snapshot exceeds the single-array element limit.",
128
+ cycle: "GPU contract snapshot contains a circular reference.",
129
+ depth: "GPU contract snapshot exceeds the nesting-depth limit.",
130
+ elements: "GPU contract snapshot exceeds the total element limit.",
131
+ inspection: "GPU contract snapshot rejected unsafe object inspection.",
132
+ nodes: "GPU contract snapshot exceeds the total node limit.",
133
+ "non-finite": "GPU contract snapshot contains a non-finite number.",
134
+ properties: "GPU contract snapshot exceeds the total property limit.",
135
+ shape: "GPU contract snapshot requires plain JSON objects with own enumerable data properties and dense arrays.",
136
+ "string-bytes": "GPU contract snapshot exceeds the individual string byte limit.",
137
+ unicode: "GPU contract snapshot contains an invalid Unicode scalar string or unpaired UTF-16 surrogate.",
138
+ value: "GPU contract snapshot contains undefined or another value that JSON cannot represent."
139
+ });
140
+ var GpuContractSnapshotError = class extends TypeError {
141
+ code;
142
+ constructor(code) {
143
+ super(FAILURE_MESSAGES[code]);
144
+ this.name = "GpuContractSnapshotError";
145
+ this.code = code;
146
+ }
147
+ };
148
+ var TYPED_ARRAY_PROTOTYPE = Reflect.getPrototypeOf(Uint8Array.prototype);
149
+ var TYPED_ARRAY_BYTE_LENGTH = Reflect.getOwnPropertyDescriptor(
150
+ TYPED_ARRAY_PROTOTYPE,
151
+ "byteLength"
152
+ )?.get;
153
+ var TYPED_ARRAY_TAG = Reflect.getOwnPropertyDescriptor(
154
+ TYPED_ARRAY_PROTOTYPE,
155
+ Symbol.toStringTag
156
+ )?.get;
157
+ var UINT8_ARRAY_SET = Uint8Array.prototype.set;
158
+ function snapshotUint8Array(value, maximumBytes) {
159
+ if (!Number.isSafeInteger(maximumBytes) || maximumBytes < 0) {
160
+ throw new TypeError("GPU contract byte limit must be a non-negative safe integer.");
161
+ }
162
+ let byteLength;
163
+ let tag;
164
+ try {
165
+ if (!TYPED_ARRAY_BYTE_LENGTH || !TYPED_ARRAY_TAG) throw new TypeError();
166
+ byteLength = Reflect.apply(TYPED_ARRAY_BYTE_LENGTH, value, []);
167
+ tag = Reflect.apply(TYPED_ARRAY_TAG, value, []);
168
+ } catch {
169
+ throw new TypeError("GPU contract bytes must be a bounded detached Uint8Array.");
170
+ }
171
+ if (tag !== "Uint8Array" || !Number.isSafeInteger(byteLength) || byteLength > maximumBytes) {
172
+ throw new TypeError("GPU contract bytes must be a bounded detached Uint8Array.");
173
+ }
174
+ const output = new Uint8Array(byteLength);
175
+ try {
176
+ Reflect.apply(UINT8_ARRAY_SET, output, [value]);
177
+ } catch {
178
+ throw new TypeError("GPU contract bytes must be a bounded detached Uint8Array.");
179
+ }
180
+ return output;
181
+ }
182
+ function fail(reason) {
183
+ throw new GpuContractSnapshotError(reason);
184
+ }
185
+ function inspected(operation) {
186
+ try {
187
+ return operation();
188
+ } catch {
189
+ return fail("inspection");
190
+ }
191
+ }
192
+ function assertLimit(value, maximum, reason) {
193
+ if (!Number.isSafeInteger(value) || value > maximum) fail(reason);
81
194
  }
82
- function assertUnicodeScalarString(value, path) {
195
+ function utf8ByteLength(value, maximum) {
196
+ let bytes = 0;
83
197
  for (let index = 0; index < value.length; index += 1) {
84
198
  const code = value.charCodeAt(index);
85
- if (code >= 55296 && code <= 56319) {
199
+ if (code <= 127) bytes += 1;
200
+ else if (code <= 2047) bytes += 2;
201
+ else if (code >= 55296 && code <= 56319) {
86
202
  const next = value.charCodeAt(index + 1);
87
- if (!(next >= 56320 && next <= 57343)) throw new TypeError(`${path} contains an unpaired UTF-16 surrogate.`);
203
+ if (!(next >= 56320 && next <= 57343)) fail("unicode");
204
+ bytes += 4;
88
205
  index += 1;
89
- } else if (code >= 56320 && code <= 57343) throw new TypeError(`${path} contains an unpaired UTF-16 surrogate.`);
206
+ } else if (code >= 56320 && code <= 57343) fail("unicode");
207
+ else bytes += 3;
208
+ if (bytes > maximum) fail("string-bytes");
90
209
  }
210
+ return bytes;
91
211
  }
92
- function canonicalizeGpuContract(value) {
212
+ function quotedJsonByteLength(value, maximum) {
213
+ let raw = 0;
214
+ let quoted = 2;
215
+ for (let index = 0; index < value.length; index += 1) {
216
+ const code = value.charCodeAt(index);
217
+ if (code <= 127) {
218
+ raw += 1;
219
+ if (code <= 31) quoted += code === 8 || code === 9 || code === 10 || code === 12 || code === 13 ? 2 : 6;
220
+ else quoted += code === 34 || code === 92 ? 2 : 1;
221
+ } else if (code <= 2047) {
222
+ raw += 2;
223
+ quoted += 2;
224
+ } else if (code >= 55296 && code <= 56319) {
225
+ const next = value.charCodeAt(index + 1);
226
+ if (!(next >= 56320 && next <= 57343)) fail("unicode");
227
+ raw += 4;
228
+ quoted += 4;
229
+ index += 1;
230
+ } else if (code >= 56320 && code <= 57343) fail("unicode");
231
+ else {
232
+ raw += 3;
233
+ quoted += 3;
234
+ }
235
+ if (raw > maximum) fail("string-bytes");
236
+ }
237
+ return { raw, quoted };
238
+ }
239
+ function assertLimits(limits) {
240
+ for (const value of Object.values(limits)) {
241
+ if (!Number.isSafeInteger(value) || value < 1) throw new TypeError("GPU contract snapshot limits must be positive safe integers.");
242
+ }
243
+ }
244
+ function snapshotGpuContract(value, limits = GPU_CONTRACT_SNAPSHOT_LIMITS) {
245
+ assertLimits(limits);
93
246
  const ancestors = /* @__PURE__ */ new Set();
94
- const visit = (current, path) => {
95
- if (current === null) return "null";
96
- if (typeof current === "string" || typeof current === "boolean") {
97
- if (typeof current === "string") assertUnicodeScalarString(current, path);
98
- return JSON.stringify(current);
247
+ let nodes = 0;
248
+ let properties = 0;
249
+ let elements = 0;
250
+ let aggregateStringBytes = 0;
251
+ let aggregateBytes = 0;
252
+ const addAggregate = (bytes) => {
253
+ aggregateBytes += bytes;
254
+ assertLimit(aggregateBytes, limits.maximumAggregateBytes, "aggregate-bytes");
255
+ };
256
+ const addString = (text2) => {
257
+ const measured = quotedJsonByteLength(text2, limits.maximumStringBytes);
258
+ aggregateStringBytes += measured.raw;
259
+ assertLimit(aggregateStringBytes, limits.maximumAggregateStringBytes, "aggregate-string-bytes");
260
+ return measured.quoted;
261
+ };
262
+ const visit = (current, depth) => {
263
+ if (depth > limits.maximumDepth) fail("depth");
264
+ nodes += 1;
265
+ assertLimit(nodes, limits.maximumNodes, "nodes");
266
+ if (current === null) {
267
+ addAggregate(4);
268
+ return null;
99
269
  }
100
- if (typeof current === "number") {
101
- if (!Number.isFinite(current)) {
102
- throw new TypeError(`${path} contains a non-finite number.`);
103
- }
104
- return Object.is(current, -0) ? "0" : JSON.stringify(current);
270
+ if (typeof current === "string") {
271
+ addAggregate(addString(current));
272
+ return current;
105
273
  }
106
- if (typeof current !== "object") {
107
- throw new TypeError(`${path} contains a value that JSON cannot represent.`);
274
+ if (typeof current === "boolean") {
275
+ addAggregate(current ? 4 : 5);
276
+ return current;
108
277
  }
109
- if (ancestors.has(current)) {
110
- throw new TypeError(`${path} contains a circular reference.`);
278
+ if (typeof current === "number") {
279
+ if (!Number.isFinite(current)) fail("non-finite");
280
+ const normalized = Object.is(current, -0) ? 0 : current;
281
+ addAggregate(JSON.stringify(normalized).length);
282
+ return normalized;
111
283
  }
284
+ if (typeof current !== "object") fail("value");
285
+ if (ancestors.has(current)) fail("cycle");
286
+ const isArray = inspected(() => Array.isArray(current));
287
+ const prototype = inspected(() => Reflect.getPrototypeOf(current));
288
+ if (isArray ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null) fail("shape");
112
289
  ancestors.add(current);
113
290
  try {
114
- if (Array.isArray(current)) {
115
- return `[${current.map((item, index) => visit(item, `${path}[${index}]`)).join(",")}]`;
291
+ if (isArray) {
292
+ const lengthDescriptor = inspected(() => Reflect.getOwnPropertyDescriptor(current, "length"));
293
+ if (!lengthDescriptor || !Object.hasOwn(lengthDescriptor, "value") || lengthDescriptor.enumerable || typeof lengthDescriptor.value !== "number" || !Number.isSafeInteger(lengthDescriptor.value) || lengthDescriptor.value < 0) fail("shape");
294
+ const length = lengthDescriptor.value;
295
+ assertLimit(length, limits.maximumArrayLength, "array-length");
296
+ elements += length;
297
+ assertLimit(elements, limits.maximumElements, "elements");
298
+ const ownKeys2 = inspected(() => Reflect.ownKeys(current));
299
+ if (ownKeys2.some((key) => typeof key !== "string")) fail("shape");
300
+ if (ownKeys2.length !== length + 1) fail("shape");
301
+ const keySet = new Set(ownKeys2);
302
+ if (!keySet.delete("length")) fail("shape");
303
+ const output2 = new Array(length);
304
+ addAggregate(2 + Math.max(0, length - 1));
305
+ for (let index = 0; index < length; index += 1) {
306
+ const key = String(index);
307
+ if (!keySet.delete(key)) fail("shape");
308
+ const descriptor = inspected(() => Reflect.getOwnPropertyDescriptor(current, key));
309
+ if (!descriptor || !descriptor.enumerable || !Object.hasOwn(descriptor, "value")) fail("shape");
310
+ Object.defineProperty(output2, key, {
311
+ configurable: true,
312
+ enumerable: true,
313
+ value: visit(descriptor.value, depth + 1),
314
+ writable: true
315
+ });
316
+ }
317
+ if (keySet.size !== 0) fail("shape");
318
+ return output2;
116
319
  }
117
- if (!isPlainObject(current)) {
118
- throw new TypeError(`${path} must contain only plain JSON objects.`);
320
+ const ownKeys = inspected(() => Reflect.ownKeys(current));
321
+ if (ownKeys.some((key) => typeof key !== "string")) fail("shape");
322
+ properties += ownKeys.length;
323
+ assertLimit(properties, limits.maximumProperties, "properties");
324
+ addAggregate(2 + Math.max(0, ownKeys.length - 1) + ownKeys.length);
325
+ const output = {};
326
+ for (const key of ownKeys) {
327
+ addAggregate(addString(key));
328
+ const descriptor = inspected(() => Reflect.getOwnPropertyDescriptor(current, key));
329
+ if (!descriptor || !descriptor.enumerable || !Object.hasOwn(descriptor, "value")) fail("shape");
330
+ Object.defineProperty(output, key, {
331
+ configurable: true,
332
+ enumerable: true,
333
+ value: visit(descriptor.value, depth + 1),
334
+ writable: true
335
+ });
119
336
  }
120
- const keys = Object.keys(current).sort();
121
- const properties = keys.map((key) => {
122
- assertUnicodeScalarString(key, `${path} key`);
123
- const member = current[key];
124
- if (member === void 0) {
125
- throw new TypeError(`${path}.${key} is undefined.`);
126
- }
127
- return `${JSON.stringify(key)}:${visit(member, `${path}.${key}`)}`;
128
- });
129
- return `{${properties.join(",")}}`;
337
+ return output;
130
338
  } finally {
131
339
  ancestors.delete(current);
132
340
  }
133
341
  };
134
- return visit(value, "$root");
342
+ return visit(value, 0);
343
+ }
344
+ function serializeSnapshot(value) {
345
+ if (value === null) return "null";
346
+ if (typeof value === "string" || typeof value === "boolean") return JSON.stringify(value);
347
+ if (typeof value === "number") return JSON.stringify(value);
348
+ if (Array.isArray(value)) return `[${value.map(serializeSnapshot).join(",")}]`;
349
+ const input = value;
350
+ return `{${Object.keys(input).sort().map((key) => `${JSON.stringify(key)}:${serializeSnapshot(input[key])}`).join(",")}}`;
351
+ }
352
+ function canonicalizeGpuContract(value) {
353
+ return serializeSnapshot(snapshotGpuContract(value));
135
354
  }
136
355
  function parseCanonicalJson(value) {
137
- const parsed = JSON.parse(value);
138
- if (canonicalizeGpuContract(parsed) !== value) throw new TypeError("JSON input is valid but not in canonical form.");
139
- return parsed;
356
+ if (typeof value !== "string") throw new TypeError("Canonical GPU contract JSON must be a string.");
357
+ try {
358
+ utf8ByteLength(value, GPU_CONTRACT_SNAPSHOT_LIMITS.maximumInputBytes);
359
+ } catch {
360
+ throw new TypeError("Canonical GPU contract JSON is invalid or exceeds its input bound.");
361
+ }
362
+ let parsed;
363
+ try {
364
+ parsed = JSON.parse(value);
365
+ } catch {
366
+ throw new TypeError("Canonical GPU contract JSON is invalid or exceeds its input bound.");
367
+ }
368
+ const snapshot = snapshotGpuContract(parsed);
369
+ if (serializeSnapshot(snapshot) !== value) throw new TypeError("JSON input is valid but not in canonical form.");
370
+ return snapshot;
140
371
  }
141
372
 
142
373
  // src/hash.ts
@@ -218,39 +449,41 @@ function modelProjection(manifest) {
218
449
  };
219
450
  }
220
451
  async function computeGpuAbiHash(input) {
221
- if (input.kind === "model") {
452
+ const snapshot = snapshotGpuContract(input);
453
+ if (snapshot.kind === "model") {
222
454
  return computeSha256(
223
455
  `plasius.gpu.model-abi/v1
224
- ${canonicalizeGpuContract(modelProjection(input.interface))}`
456
+ ${canonicalizeGpuContract(modelProjection(snapshot.interface))}`
225
457
  );
226
458
  }
227
- if (input.kind === "interface") {
459
+ if (snapshot.kind === "interface") {
228
460
  return computeSha256(
229
461
  `plasius.gpu.interface-abi/v1
230
- ${canonicalizeGpuContract(interfaceProjection(input.interface))}`
462
+ ${canonicalizeGpuContract(interfaceProjection(snapshot.interface))}`
231
463
  );
232
464
  }
233
465
  const pipelines = sorted(
234
- input.pipelines,
466
+ snapshot.pipelines,
235
467
  (left, right) => compareString(left.pipelineId, right.pipelineId)
236
468
  );
237
469
  const requirements = {
238
- semantics: [...input.requirements.semantics].sort(),
239
- features: [...input.requirements.features].sort(),
240
- limits: sorted(input.requirements.limits, (left, right) => compareString(left.name, right.name)),
241
- formats: [...input.requirements.formats].sort()
470
+ semantics: [...snapshot.requirements.semantics].sort(),
471
+ features: [...snapshot.requirements.features].sort(),
472
+ limits: sorted(snapshot.requirements.limits, (left, right) => compareString(left.name, right.name)),
473
+ formats: [...snapshot.requirements.formats].sort()
242
474
  };
243
475
  return computeSha256(
244
476
  `plasius.gpu.shader-abi/v1
245
477
  ${canonicalizeGpuContract({
246
- interface: interfaceProjection(input.interface),
478
+ interface: interfaceProjection(snapshot.interface),
247
479
  pipelines,
248
480
  requirements
249
481
  })}`
250
482
  );
251
483
  }
252
484
  async function computeShaderManifestCoreSha256(manifest) {
253
- const core = Object.fromEntries(Object.entries(manifest).filter(
485
+ const snapshot = snapshotGpuContract(manifest);
486
+ const core = Object.fromEntries(Object.entries(snapshot).filter(
254
487
  ([key]) => key !== "validationEvidence" && key !== "additionalValidationEvidence"
255
488
  ));
256
489
  return computeSha256(
@@ -882,96 +1115,17 @@ function validateShaderDerivedRequirements(input) {
882
1115
  for (const feature of inferWgslRequiredFeatures([...input.moduleSources.values()])) if (!features.has(feature)) throw new TypeError(`Shader requirements omit WGSL-derived feature ${feature}.`);
883
1116
  }
884
1117
 
885
- // src/compatibility.ts
886
- function error(code, message, path) {
887
- return { code, severity: "error", message, ...path ? { path } : {} };
888
- }
889
- function interfaceMatches(item, model) {
890
- return item.interfaceId === model.gpuInterface.interfaceId && item.interfaceVersion === model.gpuInterface.interfaceVersion && item.manifestSha256 === model.gpuInterface.manifestSha256 && item.interfaceAbiHash === model.gpuInterface.interfaceAbiHash && item.modelAbiHash === model.modelAbiHash;
891
- }
892
- function validateRequirements(shader, gpuInterface, model, capabilities, diagnostics) {
893
- const semantics = new Set(model.providedSemantics);
894
- const requiredSemantics = /* @__PURE__ */ new Set([
895
- ...shader.requirements.semantics,
896
- ...gpuInterface.modelAbi.semantics.map((projection) => projection.semantic)
897
- ]);
898
- for (const semantic2 of requiredSemantics) {
899
- if (!semantics.has(semantic2)) {
900
- diagnostics.push(error("missing-semantic", `Model does not provide required semantic ${semantic2}.`, "requirements.semantics"));
901
- }
902
- }
903
- if (!capabilities) return;
904
- const features = new Set(capabilities.features);
905
- for (const feature of shader.requirements.features) {
906
- if (!features.has(feature)) {
907
- diagnostics.push(error("missing-feature", `GPU does not provide required feature ${feature}.`, "requirements.features"));
908
- }
909
- }
910
- const formats = new Set(capabilities.formats);
911
- for (const format of shader.requirements.formats) {
912
- if (!formats.has(format)) {
913
- diagnostics.push(error("unsupported-format", `GPU runtime does not expose required format ${format}.`, "requirements.formats"));
914
- }
915
- }
916
- for (const requirement of shader.requirements.limits) {
917
- const available = capabilities.limits[requirement.name];
918
- const satisfied = available !== void 0 && (requirement.comparator === "at-least" ? available >= requirement.value : available <= requirement.value);
919
- if (!satisfied) {
920
- diagnostics.push(error(
921
- "limit-not-met",
922
- `GPU limit ${requirement.name} does not meet the ${requirement.comparator} requirement.`,
923
- "requirements.limits"
924
- ));
925
- }
926
- }
927
- }
928
- function validateModelShaderCompatibility(input) {
929
- const diagnostics = [];
930
- const { model, shader, gpuInterface, profile, capabilities } = input;
1118
+ // src/manifest-validation.ts
1119
+ var stages = ["vertex", "fragment", "compute"];
1120
+ var roles = ["material", "lighting", "outline", "shadow", "post-processing"];
1121
+ function detachedJson(value, path) {
931
1122
  try {
932
- validateShaderInterfaceRequirements({ manifest: shader, gpuInterface });
1123
+ return snapshotGpuContract(value);
933
1124
  } catch (cause) {
934
- diagnostics.push(error(
935
- "invalid-contract",
936
- cause instanceof Error ? cause.message : "Shader requirements differ from the reflected GPU interface.",
937
- "requirements"
938
- ));
939
- }
940
- if (model.gpuInterface.modelAbiHash !== model.modelAbiHash) {
941
- diagnostics.push(error("model-abi-mismatch", "Model manifest and GPU interface reference disagree on modelAbiHash.", "modelAbiHash"));
1125
+ const detail = cause instanceof GpuContractSnapshotError ? ` ${cause.message}` : "";
1126
+ throw new TypeError(`${path} must contain bounded detached JSON contract data.${detail}`);
942
1127
  }
943
- if (shader.gpuInterface.modelAbiHash !== model.modelAbiHash) {
944
- diagnostics.push(error("model-abi-mismatch", "Shader GPU interface does not match the model ABI.", "gpuInterface.modelAbiHash"));
945
- }
946
- if (!shader.compatibleModelInterfaces.some((item) => interfaceMatches(item, model))) {
947
- diagnostics.push(error("incompatible-model-interface", "Shader does not declare this exact model interface as compatible."));
948
- }
949
- if (profile) {
950
- if (!profile.compatibleModelInterfaces.some((item) => interfaceMatches(item, model))) {
951
- diagnostics.push(error("incompatible-model-interface", "Style profile does not declare this exact model interface as compatible."));
952
- }
953
- const provided = new Set(model.providedSemantics);
954
- for (const semantic2 of profile.requiredSemantics) {
955
- if (!provided.has(semantic2)) {
956
- diagnostics.push(error("missing-semantic", `Model does not provide profile semantic ${semantic2}.`, "requiredSemantics"));
957
- }
958
- }
959
- }
960
- validateRequirements(shader, gpuInterface, model, capabilities, diagnostics);
961
- if (diagnostics.length > 0) return { ok: false, diagnostics };
962
- return {
963
- ok: true,
964
- value: {
965
- modelAbiHash: model.modelAbiHash,
966
- shaderAbiHash: shader.shaderAbiHash,
967
- matchedInterfaceId: model.gpuInterface.interfaceId
968
- }
969
- };
970
1128
  }
971
-
972
- // src/manifest-validation.ts
973
- var stages = ["vertex", "fragment", "compute"];
974
- var roles = ["material", "lighting", "outline", "shadow", "post-processing"];
975
1129
  function object(value, path) {
976
1130
  if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TypeError(`${path} must be an object.`);
977
1131
  return value;
@@ -979,7 +1133,7 @@ function object(value, path) {
979
1133
  function exact(value, keys, path) {
980
1134
  const allowed = new Set(keys);
981
1135
  for (const key of Object.keys(value)) if (!allowed.has(key)) throw new TypeError(`${path}.${key} is not part of this contract version.`);
982
- for (const key of keys) if (!(key in value)) throw new TypeError(`${path}.${key} is required.`);
1136
+ for (const key of keys) if (!Object.hasOwn(value, key)) throw new TypeError(`${path}.${key} is required.`);
983
1137
  }
984
1138
  function text(value, path, maximum = 512) {
985
1139
  if (typeof value !== "string" || value.length === 0 || value.length > maximum || [...value].some((character) => character.charCodeAt(0) <= 31)) {
@@ -992,6 +1146,13 @@ function token(value, path) {
992
1146
  if (!/^[A-Za-z0-9][A-Za-z0-9._:/-]*$/u.test(result) || result.includes("..")) throw new TypeError(`${path} must be a safe token.`);
993
1147
  return result;
994
1148
  }
1149
+ function immutableVersion(value, path) {
1150
+ try {
1151
+ return assertImmutableAssetVersion(value);
1152
+ } catch {
1153
+ throw new TypeError(`${path} must be an immutable asset version: exact token required; mutable aliases, ranges, wildcards, and URLs are not allowed.`);
1154
+ }
1155
+ }
995
1156
  function enumeration(value, values, path) {
996
1157
  if (!values.includes(value)) throw new TypeError(`${path} is invalid.`);
997
1158
  return value;
@@ -1019,8 +1180,8 @@ function nullableToken(value, path) {
1019
1180
  function digest(value, path) {
1020
1181
  try {
1021
1182
  return asSha256Hex(text(value, path, 64));
1022
- } catch (cause) {
1023
- throw new TypeError(`${path} must be a lowercase SHA-256 digest.`, { cause });
1183
+ } catch {
1184
+ throw new TypeError(`${path} must be a lowercase SHA-256 digest.`);
1024
1185
  }
1025
1186
  }
1026
1187
  function uri(value, path) {
@@ -1028,8 +1189,8 @@ function uri(value, path) {
1028
1189
  let parsed;
1029
1190
  try {
1030
1191
  parsed = new URL(result);
1031
- } catch (cause) {
1032
- throw new TypeError(`${path} must be an absolute immutable asset URI.`, { cause });
1192
+ } catch {
1193
+ throw new TypeError(`${path} must be an absolute immutable asset URI.`);
1033
1194
  }
1034
1195
  if (parsed.protocol !== "https:" || parsed.username || parsed.password || parsed.hash) throw new TypeError(`${path} must be credential-free HTTPS without a fragment.`);
1035
1196
  const keys = [...parsed.searchParams.keys()].map((key) => key.toLowerCase());
@@ -1265,7 +1426,7 @@ function interfaceRef(value, path) {
1265
1426
  const input = object(value, path);
1266
1427
  exact(input, ["interfaceId", "interfaceVersion", "manifestUri", "manifestSha256", "interfaceAbiHash", "modelAbiHash"], path);
1267
1428
  token(input.interfaceId, `${path}.interfaceId`);
1268
- token(input.interfaceVersion, `${path}.interfaceVersion`);
1429
+ immutableVersion(input.interfaceVersion, `${path}.interfaceVersion`);
1269
1430
  uri(input.manifestUri, `${path}.manifestUri`);
1270
1431
  digest(input.manifestSha256, `${path}.manifestSha256`);
1271
1432
  digest(input.interfaceAbiHash, `${path}.interfaceAbiHash`);
@@ -1406,7 +1567,7 @@ function compatibleModel(value, path) {
1406
1567
  const input = object(value, path);
1407
1568
  exact(input, ["interfaceId", "interfaceVersion", "manifestSha256", "interfaceAbiHash", "modelAbiHash"], path);
1408
1569
  token(input.interfaceId, `${path}.interfaceId`);
1409
- token(input.interfaceVersion, `${path}.interfaceVersion`);
1570
+ immutableVersion(input.interfaceVersion, `${path}.interfaceVersion`);
1410
1571
  digest(input.manifestSha256, `${path}.manifestSha256`);
1411
1572
  digest(input.interfaceAbiHash, `${path}.interfaceAbiHash`);
1412
1573
  digest(input.modelAbiHash, `${path}.modelAbiHash`);
@@ -1419,7 +1580,7 @@ function validationEvidenceRef(value, path) {
1419
1580
  uri(evidence.uri, `${path}.uri`);
1420
1581
  digest(evidence.sha256, `${path}.sha256`);
1421
1582
  token(evidence.matrixId, `${path}.matrixId`);
1422
- token(evidence.matrixVersion, `${path}.matrixVersion`);
1583
+ immutableVersion(evidence.matrixVersion, `${path}.matrixVersion`);
1423
1584
  digest(evidence.matrixSha256, `${path}.matrixSha256`);
1424
1585
  const attestation = object(evidence.attestationRef, `${path}.attestationRef`);
1425
1586
  exact(attestation, ["uri", "sha256"], `${path}.attestationRef`);
@@ -1446,11 +1607,11 @@ function reflectedRecordBindingSize(record) {
1446
1607
  return Math.ceil(unrounded / record.alignment) * record.alignment;
1447
1608
  }
1448
1609
  function parseGpuInterfaceManifest(value) {
1449
- const input = object(value, "GpuInterfaceManifest");
1610
+ const input = object(detachedJson(value, "GpuInterfaceManifest"), "GpuInterfaceManifest");
1450
1611
  exact(input, ["contractVersion", "interfaceId", "interfaceVersion", "modules", "records", "bindings", "entryPoints", "vertexInputs", "overrides", "modelAbi", "modelAbiHash", "interfaceAbiHash", "generatedBy"], "GpuInterfaceManifest");
1451
1612
  if (input.contractVersion !== GPU_INTERFACE_MANIFEST_VERSION) throw new TypeError("Unsupported GPU interface contract version.");
1452
1613
  token(input.interfaceId, "GpuInterfaceManifest.interfaceId");
1453
- token(input.interfaceVersion, "GpuInterfaceManifest.interfaceVersion");
1614
+ immutableVersion(input.interfaceVersion, "GpuInterfaceManifest.interfaceVersion");
1454
1615
  const moduleValues = array(input.modules, "GpuInterfaceManifest.modules");
1455
1616
  if (moduleValues.length === 0) throw new TypeError("GpuInterfaceManifest.modules must not be empty.");
1456
1617
  const moduleIds = moduleValues.map((value2, index) => {
@@ -1632,11 +1793,11 @@ function parseGpuInterfaceManifest(value) {
1632
1793
  return freeze(input);
1633
1794
  }
1634
1795
  function parseShaderVersionManifest(value) {
1635
- const input = object(value, "ShaderVersionManifest");
1796
+ const input = object(detachedJson(value, "ShaderVersionManifest"), "ShaderVersionManifest");
1636
1797
  exact(input, ["contractVersion", "shaderId", "version", "modules", "gpuInterface", "pipelines", "renderRoles", "compatibleModelInterfaces", "requirements", "shaderAbiHash", "validationEvidence", "additionalValidationEvidence"], "ShaderVersionManifest");
1637
1798
  if (input.contractVersion !== SHADER_VERSION_MANIFEST_VERSION) throw new TypeError("Unsupported shader manifest contract version.");
1638
1799
  token(input.shaderId, "ShaderVersionManifest.shaderId");
1639
- token(input.version, "ShaderVersionManifest.version");
1800
+ immutableVersion(input.version, "ShaderVersionManifest.version");
1640
1801
  const moduleValues = array(input.modules, "ShaderVersionManifest.modules");
1641
1802
  if (moduleValues.length === 0) throw new TypeError("ShaderVersionManifest.modules must not be empty.");
1642
1803
  const moduleIds = moduleValues.map((item, index) => {
@@ -1749,7 +1910,7 @@ function parseShaderVersionManifest(value) {
1749
1910
  return freeze(input);
1750
1911
  }
1751
1912
  function parseShaderVersionManifestCore(value) {
1752
- const input = object(value, "ShaderVersionManifestCore");
1913
+ const input = object(detachedJson(value, "ShaderVersionManifestCore"), "ShaderVersionManifestCore");
1753
1914
  if ("validationEvidence" in input || "additionalValidationEvidence" in input) {
1754
1915
  throw new TypeError("ShaderVersionManifestCore must not contain validationEvidence or additionalValidationEvidence.");
1755
1916
  }
@@ -1775,11 +1936,11 @@ function parseShaderVersionManifestCore(value) {
1775
1936
  return freeze(core);
1776
1937
  }
1777
1938
  function parseShaderStyleProfileManifest(value) {
1778
- const input = object(value, "ShaderStyleProfileManifest");
1939
+ const input = object(detachedJson(value, "ShaderStyleProfileManifest"), "ShaderStyleProfileManifest");
1779
1940
  exact(input, ["contractVersion", "profileId", "version", "style", "roles", "compatibleModelInterfaces", "requiredSemantics", "requiredValidationScopes"], "ShaderStyleProfileManifest");
1780
1941
  if (input.contractVersion !== SHADER_STYLE_PROFILE_MANIFEST_VERSION) throw new TypeError("Unsupported style-profile contract version.");
1781
1942
  token(input.profileId, "ShaderStyleProfileManifest.profileId");
1782
- token(input.version, "ShaderStyleProfileManifest.version");
1943
+ immutableVersion(input.version, "ShaderStyleProfileManifest.version");
1783
1944
  token(input.style, "ShaderStyleProfileManifest.style");
1784
1945
  const roleValues = array(input.roles, "ShaderStyleProfileManifest.roles", 5);
1785
1946
  if (roleValues.length === 0) throw new TypeError("ShaderStyleProfileManifest.roles must not be empty.");
@@ -1792,7 +1953,7 @@ function parseShaderStyleProfileManifest(value) {
1792
1953
  const shader = object(role.shader, `${path}.shader`);
1793
1954
  exact(shader, ["shaderId", "version", "manifestUri", "manifestSha256"], `${path}.shader`);
1794
1955
  token(shader.shaderId, `${path}.shader.shaderId`);
1795
- token(shader.version, `${path}.shader.version`);
1956
+ immutableVersion(shader.version, `${path}.shader.version`);
1796
1957
  uri(shader.manifestUri, `${path}.shader.manifestUri`);
1797
1958
  digest(shader.manifestSha256, `${path}.shader.manifestSha256`);
1798
1959
  });
@@ -1808,7 +1969,7 @@ function parseShaderStyleProfileManifest(value) {
1808
1969
  const scope = token(requirement.scope, `${path}.scope`);
1809
1970
  if (scope === "universal") throw new TypeError(`${path}.scope must not use the reserved universal scope.`);
1810
1971
  token(requirement.matrixId, `${path}.matrixId`);
1811
- token(requirement.matrixVersion, `${path}.matrixVersion`);
1972
+ immutableVersion(requirement.matrixVersion, `${path}.matrixVersion`);
1812
1973
  const matrixSha256 = digest(requirement.matrixSha256, `${path}.matrixSha256`);
1813
1974
  if (SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES.some((policy) => policy.matrixSha256 === matrixSha256)) {
1814
1975
  throw new TypeError(`${path} must require an additive matrix policy, not the universal matrix policy.`);
@@ -1823,10 +1984,10 @@ function parseShaderStyleProfileManifest(value) {
1823
1984
  return freeze(input);
1824
1985
  }
1825
1986
  function parseModelGpuCompatibilityDescriptor(value) {
1826
- const input = object(value, "ModelGpuCompatibilityDescriptor");
1987
+ const input = object(detachedJson(value, "ModelGpuCompatibilityDescriptor"), "ModelGpuCompatibilityDescriptor");
1827
1988
  exact(input, ["modelId", "version", "gpuInterface", "modelAbiHash", "providedSemantics", "defaultStyleProfile"], "ModelGpuCompatibilityDescriptor");
1828
1989
  token(input.modelId, "ModelGpuCompatibilityDescriptor.modelId");
1829
- token(input.version, "ModelGpuCompatibilityDescriptor.version");
1990
+ immutableVersion(input.version, "ModelGpuCompatibilityDescriptor.version");
1830
1991
  const gpuInterface = interfaceRef(input.gpuInterface, "ModelGpuCompatibilityDescriptor.gpuInterface");
1831
1992
  const modelAbiHash = digest(input.modelAbiHash, "ModelGpuCompatibilityDescriptor.modelAbiHash");
1832
1993
  if (gpuInterface.modelAbiHash !== modelAbiHash) throw new TypeError("ModelGpuCompatibilityDescriptor.gpuInterface.modelAbiHash differs from modelAbiHash.");
@@ -1835,18 +1996,166 @@ function parseModelGpuCompatibilityDescriptor(value) {
1835
1996
  const profile = object(input.defaultStyleProfile, "ModelGpuCompatibilityDescriptor.defaultStyleProfile");
1836
1997
  exact(profile, ["profileId", "version", "manifestUri", "manifestSha256"], "ModelGpuCompatibilityDescriptor.defaultStyleProfile");
1837
1998
  token(profile.profileId, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.profileId");
1838
- token(profile.version, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.version");
1999
+ immutableVersion(profile.version, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.version");
1839
2000
  uri(profile.manifestUri, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.manifestUri");
1840
2001
  digest(profile.manifestSha256, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.manifestSha256");
1841
2002
  }
1842
2003
  return freeze(input);
1843
2004
  }
1844
2005
  function parseJsonBytes(bytes, label) {
2006
+ const safeLabel = typeof label === "string" && /^[A-Za-z0-9 ._-]{1,80}$/u.test(label) ? label : "GPU contract";
2007
+ let snapshot;
2008
+ try {
2009
+ snapshot = snapshotUint8Array(bytes, GPU_CONTRACT_SNAPSHOT_LIMITS.maximumInputBytes);
2010
+ } catch {
2011
+ throw new TypeError(`${safeLabel} is not bounded UTF-8 JSON.`);
2012
+ }
2013
+ let parsed;
2014
+ try {
2015
+ parsed = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(snapshot));
2016
+ } catch {
2017
+ throw new TypeError(`${safeLabel} is not valid UTF-8 JSON.`);
2018
+ }
2019
+ try {
2020
+ return snapshotGpuContract(parsed);
2021
+ } catch {
2022
+ throw new TypeError(`${safeLabel} is not bounded detached JSON contract data.`);
2023
+ }
2024
+ }
2025
+
2026
+ // src/compatibility.ts
2027
+ function error(code, message, path) {
2028
+ const bounded = [...message].map((character) => {
2029
+ const codePoint = character.codePointAt(0);
2030
+ return codePoint <= 31 || codePoint === 127 ? " " : character;
2031
+ }).slice(0, 512).join("");
2032
+ return { code, severity: "error", message: bounded, ...path ? { path } : {} };
2033
+ }
2034
+ function interfaceMatches(item, model) {
2035
+ return item.interfaceId === model.gpuInterface.interfaceId && item.interfaceVersion === model.gpuInterface.interfaceVersion && item.manifestSha256 === model.gpuInterface.manifestSha256 && item.interfaceAbiHash === model.gpuInterface.interfaceAbiHash && item.modelAbiHash === model.modelAbiHash;
2036
+ }
2037
+ function hasValidationEvidence(value) {
2038
+ return typeof value === "object" && value !== null && !Array.isArray(value) && (Object.hasOwn(value, "validationEvidence") || Object.hasOwn(value, "additionalValidationEvidence"));
2039
+ }
2040
+ function validateRequirements(shader, gpuInterface, model, capabilities, diagnostics) {
2041
+ const semantics = new Set(model.providedSemantics);
2042
+ const requiredSemantics = /* @__PURE__ */ new Set([
2043
+ ...shader.requirements.semantics,
2044
+ ...gpuInterface.modelAbi.semantics.map((projection) => projection.semantic)
2045
+ ]);
2046
+ for (const semantic2 of requiredSemantics) {
2047
+ if (!semantics.has(semantic2)) {
2048
+ diagnostics.push(error("missing-semantic", `Model does not provide required semantic ${semantic2}.`, "requirements.semantics"));
2049
+ }
2050
+ }
2051
+ if (!capabilities) return;
2052
+ const features = new Set(capabilities.features);
2053
+ for (const feature of shader.requirements.features) {
2054
+ if (!features.has(feature)) {
2055
+ diagnostics.push(error("missing-feature", `GPU does not provide required feature ${feature}.`, "requirements.features"));
2056
+ }
2057
+ }
2058
+ const formats = new Set(capabilities.formats);
2059
+ for (const format of shader.requirements.formats) {
2060
+ if (!formats.has(format)) {
2061
+ diagnostics.push(error("unsupported-format", `GPU runtime does not expose required format ${format}.`, "requirements.formats"));
2062
+ }
2063
+ }
2064
+ for (const requirement of shader.requirements.limits) {
2065
+ const available = capabilities.limits[requirement.name];
2066
+ const satisfied = available !== void 0 && (requirement.comparator === "at-least" ? available >= requirement.value : available <= requirement.value);
2067
+ if (!satisfied) {
2068
+ diagnostics.push(error(
2069
+ "limit-not-met",
2070
+ `GPU limit ${requirement.name} does not meet the ${requirement.comparator} requirement.`,
2071
+ "requirements.limits"
2072
+ ));
2073
+ }
2074
+ }
2075
+ }
2076
+ function validateModelShaderCompatibility(input) {
2077
+ const diagnostics = [];
2078
+ let model;
2079
+ let shader;
2080
+ let gpuInterface;
2081
+ let profile;
2082
+ let capabilities;
2083
+ try {
2084
+ const snapshot = snapshotGpuContract(input);
2085
+ if (typeof snapshot !== "object" || snapshot === null || Array.isArray(snapshot)) {
2086
+ throw new TypeError("GPU compatibility input must be a bounded contract object.");
2087
+ }
2088
+ const envelope = snapshot;
2089
+ const keys = Object.keys(envelope);
2090
+ const allowed = /* @__PURE__ */ new Set(["model", "shader", "gpuInterface", "profile", "capabilities"]);
2091
+ if (keys.some((key) => !allowed.has(key)) || !["model", "shader", "gpuInterface"].every((key) => Object.hasOwn(envelope, key))) {
2092
+ throw new TypeError("GPU compatibility input has unknown or missing fields.");
2093
+ }
2094
+ const modelSnapshot = envelope.model;
2095
+ const shaderSnapshot = envelope.shader;
2096
+ const gpuInterfaceSnapshot = envelope.gpuInterface;
2097
+ const profileSnapshot = Object.hasOwn(envelope, "profile") ? envelope.profile : void 0;
2098
+ model = parseModelGpuCompatibilityDescriptor(modelSnapshot);
2099
+ shader = hasValidationEvidence(shaderSnapshot) ? parseShaderVersionManifest(shaderSnapshot) : parseShaderVersionManifestCore(shaderSnapshot);
2100
+ gpuInterface = parseGpuInterfaceManifest(gpuInterfaceSnapshot);
2101
+ profile = profileSnapshot === void 0 ? void 0 : parseShaderStyleProfileManifest(profileSnapshot);
2102
+ capabilities = Object.hasOwn(envelope, "capabilities") ? envelope.capabilities : void 0;
2103
+ } catch (cause) {
2104
+ return {
2105
+ ok: false,
2106
+ diagnostics: [error(
2107
+ "invalid-contract",
2108
+ cause instanceof Error ? cause.message : "GPU compatibility contract snapshot failed."
2109
+ )]
2110
+ };
2111
+ }
1845
2112
  try {
1846
- return JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
2113
+ validateShaderInterfaceRequirements({ manifest: shader, gpuInterface });
1847
2114
  } catch (cause) {
1848
- throw new TypeError(`${label} is not valid UTF-8 JSON.`, { cause });
2115
+ diagnostics.push(error(
2116
+ "invalid-contract",
2117
+ cause instanceof Error ? cause.message : "Shader requirements differ from the reflected GPU interface.",
2118
+ "requirements"
2119
+ ));
2120
+ }
2121
+ if (model.gpuInterface.modelAbiHash !== model.modelAbiHash) {
2122
+ diagnostics.push(error("model-abi-mismatch", "Model manifest and GPU interface reference disagree on modelAbiHash.", "modelAbiHash"));
2123
+ }
2124
+ if (shader.gpuInterface.modelAbiHash !== model.modelAbiHash) {
2125
+ diagnostics.push(error("model-abi-mismatch", "Shader GPU interface does not match the model ABI.", "gpuInterface.modelAbiHash"));
2126
+ }
2127
+ if (!shader.compatibleModelInterfaces.some((item) => interfaceMatches(item, model))) {
2128
+ diagnostics.push(error("incompatible-model-interface", "Shader does not declare this exact model interface as compatible."));
1849
2129
  }
2130
+ if (profile) {
2131
+ if (!profile.compatibleModelInterfaces.some((item) => interfaceMatches(item, model))) {
2132
+ diagnostics.push(error("incompatible-model-interface", "Style profile does not declare this exact model interface as compatible."));
2133
+ }
2134
+ const provided = new Set(model.providedSemantics);
2135
+ for (const semantic2 of profile.requiredSemantics) {
2136
+ if (!provided.has(semantic2)) {
2137
+ diagnostics.push(error("missing-semantic", `Model does not provide profile semantic ${semantic2}.`, "requiredSemantics"));
2138
+ }
2139
+ }
2140
+ }
2141
+ try {
2142
+ validateRequirements(shader, gpuInterface, model, capabilities, diagnostics);
2143
+ } catch (cause) {
2144
+ diagnostics.push(error(
2145
+ "invalid-contract",
2146
+ cause instanceof Error ? cause.message : "GPU capability snapshot validation failed.",
2147
+ "capabilities"
2148
+ ));
2149
+ }
2150
+ if (diagnostics.length > 0) return { ok: false, diagnostics };
2151
+ return {
2152
+ ok: true,
2153
+ value: {
2154
+ modelAbiHash: model.modelAbiHash,
2155
+ shaderAbiHash: shader.shaderAbiHash,
2156
+ matchedInterfaceId: model.gpuInterface.interfaceId
2157
+ }
2158
+ };
1850
2159
  }
1851
2160
 
1852
2161
  // src/runtime/trusted-values.ts
@@ -1968,15 +2277,173 @@ function requireTrustedPreparedShaderStyleProfile(value) {
1968
2277
  function diagnostic(code, message, path) {
1969
2278
  return { code, severity: "error", message, ...path ? { path } : {} };
1970
2279
  }
2280
+ var CatalogLoadError = class extends TypeError {
2281
+ diagnosticCode;
2282
+ constructor(message, diagnosticCode = "invalid-contract") {
2283
+ super(message);
2284
+ this.name = "CatalogLoadError";
2285
+ this.diagnosticCode = diagnosticCode;
2286
+ }
2287
+ };
2288
+ function catalogFailure(message, diagnosticCode = "invalid-contract") {
2289
+ return new CatalogLoadError(message, diagnosticCode);
2290
+ }
2291
+ function catalogContractStep(operation, fallback) {
2292
+ try {
2293
+ return operation();
2294
+ } catch (cause) {
2295
+ if (cause instanceof CatalogLoadError) throw cause;
2296
+ throw catalogFailure(cause instanceof TypeError ? cause.message : fallback);
2297
+ }
2298
+ }
2299
+ async function catalogContractStepAsync(operation, fallback) {
2300
+ try {
2301
+ return await operation();
2302
+ } catch (cause) {
2303
+ if (cause instanceof CatalogLoadError) throw cause;
2304
+ throw catalogFailure(cause instanceof TypeError ? cause.message : fallback);
2305
+ }
2306
+ }
1971
2307
  async function verifyBytes(bytes, expected, label) {
1972
- const actual = await computeSha256(bytes);
1973
- if (actual !== expected) throw new TypeError(`${label} digest does not match its immutable reference.`);
2308
+ const actual = await catalogContractStepAsync(
2309
+ () => computeSha256(bytes),
2310
+ `${label} digest could not be computed.`
2311
+ );
2312
+ if (actual !== expected) {
2313
+ throw catalogFailure(
2314
+ `${label} digest does not match its immutable reference.`,
2315
+ "digest-mismatch"
2316
+ );
2317
+ }
1974
2318
  }
1975
- function copyBytes(bytes) {
1976
- return new Uint8Array(bytes);
2319
+ function inspectCatalogAsset(value, label, maximumBytes) {
2320
+ try {
2321
+ if (typeof value !== "object" || value === null) throw new TypeError();
2322
+ const keys = Reflect.ownKeys(value);
2323
+ if (keys.length !== 2 || !keys.includes("bytes") || !keys.includes("promoted")) {
2324
+ throw new TypeError();
2325
+ }
2326
+ const bytes = Reflect.getOwnPropertyDescriptor(value, "bytes");
2327
+ const promoted = Reflect.getOwnPropertyDescriptor(value, "promoted");
2328
+ if (!bytes?.enumerable || !Object.hasOwn(bytes, "value") || !promoted?.enumerable || !Object.hasOwn(promoted, "value") || typeof promoted.value !== "boolean") {
2329
+ throw new TypeError();
2330
+ }
2331
+ return Object.freeze({
2332
+ bytes: snapshotUint8Array(bytes.value, maximumBytes),
2333
+ promoted: promoted.value
2334
+ });
2335
+ } catch {
2336
+ throw catalogFailure(`${label} returned invalid detached asset bytes.`);
2337
+ }
2338
+ }
2339
+ async function loadCatalogAsset(operation, label, maximumBytes) {
2340
+ let value;
2341
+ try {
2342
+ value = await operation();
2343
+ } catch {
2344
+ throw catalogFailure(`${label} provider request failed.`);
2345
+ }
2346
+ return inspectCatalogAsset(value, label, maximumBytes);
1977
2347
  }
2348
+ function isCatalogAssetUri(catalog, uri2) {
2349
+ try {
2350
+ const result = catalog.isCatalogAssetUri(uri2);
2351
+ if (typeof result !== "boolean") throw new TypeError();
2352
+ return result;
2353
+ } catch {
2354
+ throw catalogFailure("Promoted catalog URI validation failed.");
2355
+ }
2356
+ }
2357
+ function inspectLoadRequest(value) {
2358
+ try {
2359
+ if (typeof value !== "object" || value === null) throw new TypeError();
2360
+ const keys = Reflect.ownKeys(value);
2361
+ if (keys.some((key) => typeof key !== "string" || !["ref", "catalog", "signal"].includes(key)) || !keys.includes("ref") || !keys.includes("catalog")) {
2362
+ throw new TypeError();
2363
+ }
2364
+ const ref = Reflect.getOwnPropertyDescriptor(value, "ref");
2365
+ const catalog = Reflect.getOwnPropertyDescriptor(value, "catalog");
2366
+ const signal = Reflect.getOwnPropertyDescriptor(value, "signal");
2367
+ if (!ref?.enumerable || !Object.hasOwn(ref, "value") || !catalog?.enumerable || !Object.hasOwn(catalog, "value") || signal !== void 0 && (!signal.enumerable || !Object.hasOwn(signal, "value"))) {
2368
+ throw new TypeError();
2369
+ }
2370
+ return Object.freeze({
2371
+ ref: ref.value,
2372
+ catalog: catalog.value,
2373
+ ...signal === void 0 ? {} : { signal: signal.value }
2374
+ });
2375
+ } catch {
2376
+ throw catalogFailure("Style profile load request must use enumerable own data properties.");
2377
+ }
2378
+ }
2379
+ function referenceObject(value, keys, label) {
2380
+ let snapshot;
2381
+ try {
2382
+ snapshot = snapshotGpuContract(value);
2383
+ } catch {
2384
+ throw catalogFailure(`${label} must contain bounded detached JSON contract data.`);
2385
+ }
2386
+ if (typeof snapshot !== "object" || snapshot === null || Array.isArray(snapshot)) {
2387
+ throw catalogFailure(`${label} must be an object.`);
2388
+ }
2389
+ const record = snapshot;
2390
+ const actual = Object.keys(record);
2391
+ if (actual.some((key) => !keys.includes(key)) || keys.some((key) => !Object.hasOwn(record, key)) || actual.some((key) => typeof record[key] !== "string")) {
2392
+ throw catalogFailure(`${label} has unknown, missing, or non-string fields.`);
2393
+ }
2394
+ return record;
2395
+ }
2396
+ function snapshotProfileRef(ref) {
2397
+ const value = referenceObject(ref, ["profileId", "version", "manifestUri", "manifestSha256"], "Style profile reference");
2398
+ const profileId = value.profileId;
2399
+ const version = value.version;
2400
+ const manifestUri = value.manifestUri;
2401
+ const manifestSha256 = value.manifestSha256;
2402
+ return Object.freeze({ profileId, version, manifestUri, manifestSha256 });
2403
+ }
2404
+ function snapshotShaderRef(ref) {
2405
+ const value = referenceObject(ref, ["shaderId", "version", "manifestUri", "manifestSha256"], "Shader version reference");
2406
+ const shaderId = value.shaderId;
2407
+ const version = value.version;
2408
+ const manifestUri = value.manifestUri;
2409
+ const manifestSha256 = value.manifestSha256;
2410
+ return Object.freeze({ shaderId, version, manifestUri, manifestSha256 });
2411
+ }
2412
+ function snapshotInterfaceRef(ref) {
2413
+ const value = referenceObject(ref, ["interfaceId", "interfaceVersion", "manifestUri", "manifestSha256", "interfaceAbiHash", "modelAbiHash"], "GPU interface reference");
2414
+ const interfaceId = value.interfaceId;
2415
+ const interfaceVersion = value.interfaceVersion;
2416
+ const manifestUri = value.manifestUri;
2417
+ const manifestSha256 = value.manifestSha256;
2418
+ const interfaceAbiHash = value.interfaceAbiHash;
2419
+ const modelAbiHash = value.modelAbiHash;
2420
+ return Object.freeze({
2421
+ interfaceId,
2422
+ interfaceVersion,
2423
+ manifestUri,
2424
+ manifestSha256,
2425
+ interfaceAbiHash,
2426
+ modelAbiHash
2427
+ });
2428
+ }
2429
+ function assertCatalogAssetVersion(value, label) {
2430
+ try {
2431
+ assertImmutableAssetVersion(value);
2432
+ } catch {
2433
+ throw catalogFailure(`${label} must use an immutable asset version represented by an exact token.`);
2434
+ }
2435
+ }
2436
+ var ABORTED_GETTER = typeof AbortSignal === "undefined" ? void 0 : Reflect.getOwnPropertyDescriptor(AbortSignal.prototype, "aborted")?.get;
1978
2437
  function throwIfAborted(signal) {
1979
- if (signal?.aborted) throw signal.reason instanceof Error ? signal.reason : new DOMException("Aborted", "AbortError");
2438
+ if (signal === void 0) return;
2439
+ let aborted;
2440
+ try {
2441
+ if (!ABORTED_GETTER) throw new TypeError();
2442
+ aborted = Reflect.apply(ABORTED_GETTER, signal, []);
2443
+ } catch {
2444
+ throw catalogFailure("Abort signal could not be inspected safely.");
2445
+ }
2446
+ if (aborted === true) throw new DOMException("Aborted", "AbortError");
1980
2447
  }
1981
2448
  function exactShaderRefKey(ref) {
1982
2449
  return `${ref.shaderId}\0${ref.version}\0${ref.manifestUri}\0${ref.manifestSha256}`;
@@ -2012,7 +2479,7 @@ function assertDistinctEvidenceOwnership(shaders) {
2012
2479
  ]) {
2013
2480
  const owner = owners.get(value);
2014
2481
  if (owner !== void 0 && owner !== shaderKey) {
2015
- throw new TypeError(`Distinct shader versions in one style profile reuse the same ${kind}.`);
2482
+ throw catalogFailure(`Distinct shader versions in one style profile reuse the same ${kind}.`);
2016
2483
  }
2017
2484
  owners.set(value, shaderKey);
2018
2485
  }
@@ -2038,102 +2505,151 @@ async function mapLimit(values, limit, operation, signal) {
2038
2505
  }
2039
2506
  async function loadInterface(catalog, ref, signal) {
2040
2507
  throwIfAborted(signal);
2041
- if (!catalog.isCatalogAssetUri(ref.manifestUri)) throw new TypeError("GPU interface URI is outside the promoted catalog root.");
2042
- const loaded = await catalog.loadInterface(ref, signal);
2043
- const bytes = copyBytes(loaded.bytes);
2508
+ assertCatalogAssetVersion(ref.interfaceVersion, "GPU interface reference");
2509
+ if (!isCatalogAssetUri(catalog, ref.manifestUri)) throw catalogFailure("GPU interface URI is outside the promoted catalog root.");
2510
+ const loaded = await loadCatalogAsset(
2511
+ () => catalog.loadInterface(ref, signal),
2512
+ "GPU interface",
2513
+ GPU_CONTRACT_SNAPSHOT_LIMITS.maximumInputBytes
2514
+ );
2515
+ const bytes = loaded.bytes;
2044
2516
  const promoted = loaded.promoted;
2045
2517
  throwIfAborted(signal);
2046
- if (!promoted) throw new TypeError("GPU interface is not promoted.");
2518
+ if (!promoted) throw catalogFailure("GPU interface is not promoted.", "unpromoted-asset");
2047
2519
  await verifyBytes(bytes, ref.manifestSha256, "GPU interface manifest");
2048
- const manifest = parseGpuInterfaceManifest(parseJsonBytes(bytes, "GPU interface manifest"));
2520
+ const manifest = catalogContractStep(
2521
+ () => parseGpuInterfaceManifest(parseJsonBytes(bytes, "GPU interface manifest")),
2522
+ "GPU interface manifest failed strict contract validation."
2523
+ );
2049
2524
  if (manifest.interfaceId !== ref.interfaceId || manifest.interfaceVersion !== ref.interfaceVersion || manifest.interfaceAbiHash !== ref.interfaceAbiHash || manifest.modelAbiHash !== ref.modelAbiHash) {
2050
- throw new TypeError("GPU interface manifest identity does not match its exact reference.");
2525
+ throw catalogFailure("GPU interface manifest identity does not match its exact reference.");
2051
2526
  }
2052
- const modelAbiHash = await computeGpuAbiHash({ kind: "model", interface: manifest });
2053
- const interfaceAbiHash = await computeGpuAbiHash({ kind: "interface", interface: manifest });
2527
+ const modelAbiHash = await catalogContractStepAsync(
2528
+ () => computeGpuAbiHash({ kind: "model", interface: manifest }),
2529
+ "GPU interface model ABI hash regeneration failed."
2530
+ );
2531
+ const interfaceAbiHash = await catalogContractStepAsync(
2532
+ () => computeGpuAbiHash({ kind: "interface", interface: manifest }),
2533
+ "GPU interface ABI hash regeneration failed."
2534
+ );
2054
2535
  if (modelAbiHash !== manifest.modelAbiHash || interfaceAbiHash !== manifest.interfaceAbiHash) {
2055
- throw new TypeError("GPU interface ABI hashes do not match regenerated structural hashes.");
2536
+ throw catalogFailure("GPU interface ABI hashes do not match regenerated structural hashes.");
2056
2537
  }
2057
2538
  return manifest;
2058
2539
  }
2059
2540
  async function loadShader(catalog, ref, signal) {
2060
2541
  throwIfAborted(signal);
2061
- if (!catalog.isCatalogAssetUri(ref.manifestUri)) throw new TypeError("Shader manifest URI is outside the promoted catalog root.");
2062
- const loaded = await catalog.loadShader(ref, signal);
2063
- const bytes = copyBytes(loaded.bytes);
2542
+ assertCatalogAssetVersion(ref.version, "Shader reference");
2543
+ if (!isCatalogAssetUri(catalog, ref.manifestUri)) throw catalogFailure("Shader manifest URI is outside the promoted catalog root.");
2544
+ const loaded = await loadCatalogAsset(
2545
+ () => catalog.loadShader(ref, signal),
2546
+ "Shader manifest",
2547
+ GPU_CONTRACT_SNAPSHOT_LIMITS.maximumInputBytes
2548
+ );
2549
+ const bytes = loaded.bytes;
2064
2550
  const promoted = loaded.promoted;
2065
2551
  throwIfAborted(signal);
2066
- if (!promoted) throw new TypeError("Shader version is not promoted.");
2552
+ if (!promoted) throw catalogFailure("Shader version is not promoted.", "unpromoted-asset");
2067
2553
  await verifyBytes(bytes, ref.manifestSha256, "Shader manifest");
2068
- const manifest = parseShaderVersionManifest(parseJsonBytes(bytes, "Shader manifest"));
2554
+ const manifest = catalogContractStep(
2555
+ () => parseShaderVersionManifest(parseJsonBytes(bytes, "Shader manifest")),
2556
+ "Shader manifest failed strict contract validation."
2557
+ );
2069
2558
  if (manifest.shaderId !== ref.shaderId || manifest.version !== ref.version) {
2070
- throw new TypeError("Shader manifest identity does not match its exact reference.");
2559
+ throw catalogFailure("Shader manifest identity does not match its exact reference.");
2071
2560
  }
2072
2561
  for (const evidence of [
2073
2562
  manifest.validationEvidence,
2074
2563
  ...manifest.additionalValidationEvidence.map((item) => item.evidence)
2075
2564
  ]) {
2076
- if (!catalog.isCatalogAssetUri(evidence.uri)) throw new TypeError("Shader validation evidence URI is outside the promoted catalog root.");
2077
- if (!catalog.isCatalogAssetUri(evidence.attestationRef.uri)) throw new TypeError("Shader validation evidence attestation URI is outside the promoted catalog root.");
2565
+ if (!isCatalogAssetUri(catalog, evidence.uri)) throw catalogFailure("Shader validation evidence URI is outside the promoted catalog root.");
2566
+ if (!isCatalogAssetUri(catalog, evidence.attestationRef.uri)) throw catalogFailure("Shader validation evidence attestation URI is outside the promoted catalog root.");
2078
2567
  }
2079
- const gpuInterface = await loadInterface(catalog, manifest.gpuInterface, signal);
2568
+ const interfaceRef2 = snapshotInterfaceRef(manifest.gpuInterface);
2569
+ const gpuInterface = await loadInterface(catalog, interfaceRef2, signal);
2080
2570
  const normalizeModules = (values) => [...values].sort((left, right) => left.moduleId < right.moduleId ? -1 : left.moduleId > right.moduleId ? 1 : 0).map(({ moduleId, sha256 }) => ({ moduleId, sha256 }));
2081
- if (canonicalizeGpuContract(normalizeModules(gpuInterface.modules)) !== canonicalizeGpuContract(normalizeModules(manifest.modules))) {
2082
- throw new TypeError("Shader modules differ from the exact reflected GPU interface module set.");
2083
- }
2084
- const shaderAbiHash = await computeGpuAbiHash({
2085
- kind: "shader",
2086
- interface: gpuInterface,
2087
- pipelines: manifest.pipelines,
2088
- requirements: manifest.requirements
2089
- });
2090
- if (shaderAbiHash !== manifest.shaderAbiHash) throw new TypeError("Shader ABI hash differs from regenerated pipeline/interface ABI.");
2571
+ if (catalogContractStep(
2572
+ () => canonicalizeGpuContract(normalizeModules(gpuInterface.modules)) !== canonicalizeGpuContract(normalizeModules(manifest.modules)),
2573
+ "Shader module-set comparison failed."
2574
+ )) {
2575
+ throw catalogFailure("Shader modules differ from the exact reflected GPU interface module set.");
2576
+ }
2577
+ const shaderAbiHash = await catalogContractStepAsync(
2578
+ () => computeGpuAbiHash({
2579
+ kind: "shader",
2580
+ interface: gpuInterface,
2581
+ pipelines: manifest.pipelines,
2582
+ requirements: manifest.requirements
2583
+ }),
2584
+ "Shader ABI hash regeneration failed."
2585
+ );
2586
+ if (shaderAbiHash !== manifest.shaderAbiHash) throw catalogFailure("Shader ABI hash differs from regenerated pipeline/interface ABI.");
2091
2587
  const modulePairs = await mapLimit(manifest.modules, 4, async (module2) => {
2092
2588
  throwIfAborted(signal);
2093
- if (!catalog.isCatalogAssetUri(module2.uri)) throw new TypeError(`Shader module ${module2.moduleId} URI is outside the promoted catalog root.`);
2094
- const asset = await catalog.loadModule(ref, module2.moduleId, module2.uri, signal);
2095
- const moduleBytes = copyBytes(asset.bytes);
2589
+ if (!isCatalogAssetUri(catalog, module2.uri)) throw catalogFailure(`Shader module ${module2.moduleId} URI is outside the promoted catalog root.`);
2590
+ const asset = await loadCatalogAsset(
2591
+ () => catalog.loadModule(ref, module2.moduleId, module2.uri, signal),
2592
+ `Shader module ${module2.moduleId}`,
2593
+ module2.byteLength
2594
+ );
2595
+ const moduleBytes = asset.bytes;
2096
2596
  const promoted2 = asset.promoted;
2097
2597
  throwIfAborted(signal);
2098
- if (!promoted2) throw new TypeError(`Shader module ${module2.moduleId} is not promoted.`);
2598
+ if (!promoted2) throw catalogFailure(`Shader module ${module2.moduleId} is not promoted.`, "unpromoted-asset");
2099
2599
  if (moduleBytes.byteLength !== module2.byteLength) {
2100
- throw new TypeError(`Shader module ${module2.moduleId} byte length does not match its manifest.`);
2600
+ throw catalogFailure(`Shader module ${module2.moduleId} byte length does not match its manifest.`);
2101
2601
  }
2102
2602
  await verifyBytes(moduleBytes, module2.sha256, `Shader module ${module2.moduleId}`);
2103
2603
  return [module2.moduleId, moduleBytes];
2104
2604
  }, signal);
2105
2605
  const decoder = new TextDecoder("utf-8", { fatal: true });
2106
- validateShaderDerivedRequirements({ manifest, gpuInterface, moduleSources: new Map(modulePairs.map(([moduleId, bytes2]) => [moduleId, decoder.decode(bytes2)])) });
2606
+ catalogContractStep(
2607
+ () => validateShaderDerivedRequirements({ manifest, gpuInterface, moduleSources: new Map(modulePairs.map(([moduleId, bytes2]) => [moduleId, decoder.decode(bytes2)])) }),
2608
+ "Shader source requirement validation failed."
2609
+ );
2107
2610
  return { ref, manifest, gpuInterface, modules: new Map(modulePairs) };
2108
2611
  }
2109
2612
  async function loadShaderStyleProfile(input) {
2110
2613
  try {
2111
- throwIfAborted(input.signal);
2112
- if (!input.catalog.isCatalogAssetUri(input.ref.manifestUri)) throw new TypeError("Style profile URI is outside the promoted catalog root.");
2113
- const loaded = await input.catalog.loadProfile(input.ref, input.signal);
2114
- const profileBytes = copyBytes(loaded.bytes);
2614
+ const request = inspectLoadRequest(input);
2615
+ const signal = request.signal;
2616
+ const catalog = request.catalog;
2617
+ throwIfAborted(signal);
2618
+ const ref = snapshotProfileRef(request.ref);
2619
+ assertCatalogAssetVersion(ref.version, "Style profile reference");
2620
+ if (!isCatalogAssetUri(catalog, ref.manifestUri)) throw catalogFailure("Style profile URI is outside the promoted catalog root.");
2621
+ const loaded = await loadCatalogAsset(
2622
+ () => catalog.loadProfile(ref, signal),
2623
+ "Style profile",
2624
+ GPU_CONTRACT_SNAPSHOT_LIMITS.maximumInputBytes
2625
+ );
2626
+ const profileBytes = loaded.bytes;
2115
2627
  const promoted = loaded.promoted;
2116
- throwIfAborted(input.signal);
2628
+ throwIfAborted(signal);
2117
2629
  if (!promoted) {
2118
2630
  return { ok: false, diagnostics: [diagnostic("unpromoted-asset", "Style profile is not promoted.")] };
2119
2631
  }
2120
- await verifyBytes(profileBytes, input.ref.manifestSha256, "Style profile manifest");
2121
- const manifest = parseShaderStyleProfileManifest(parseJsonBytes(profileBytes, "Style profile manifest"));
2122
- if (manifest.profileId !== input.ref.profileId || manifest.version !== input.ref.version) {
2632
+ await verifyBytes(profileBytes, ref.manifestSha256, "Style profile manifest");
2633
+ const manifest = catalogContractStep(
2634
+ () => parseShaderStyleProfileManifest(parseJsonBytes(profileBytes, "Style profile manifest")),
2635
+ "Style profile manifest failed strict contract validation."
2636
+ );
2637
+ if (manifest.profileId !== ref.profileId || manifest.version !== ref.version) {
2123
2638
  return { ok: false, diagnostics: [diagnostic("invalid-contract", "Style profile identity does not match its exact reference.")] };
2124
2639
  }
2125
2640
  const cache = /* @__PURE__ */ new Map();
2126
2641
  const pairs = await mapLimit(manifest.roles, 4, async (binding2) => {
2127
- throwIfAborted(input.signal);
2128
- const cacheKey = exactShaderRefKey(binding2.shader);
2642
+ throwIfAborted(signal);
2643
+ const shaderRef = snapshotShaderRef(binding2.shader);
2644
+ const cacheKey = exactShaderRefKey(shaderRef);
2129
2645
  let shader = cache.get(cacheKey);
2130
2646
  if (!shader) {
2131
- shader = loadShader(input.catalog, binding2.shader, input.signal);
2647
+ shader = loadShader(catalog, shaderRef, signal);
2132
2648
  cache.set(cacheKey, shader);
2133
2649
  }
2134
2650
  const resolved = await shader;
2135
2651
  if (!resolved.manifest.renderRoles.some((role) => role.role === binding2.role)) {
2136
- throw new TypeError(`Shader ${resolved.manifest.shaderId} does not implement role ${binding2.role}.`);
2652
+ throw catalogFailure(`Shader ${resolved.manifest.shaderId} does not implement role ${binding2.role}.`);
2137
2653
  }
2138
2654
  const validationScopes = new Map(
2139
2655
  resolved.manifest.additionalValidationEvidence.map((item) => [item.scope, item.evidence])
@@ -2141,31 +2657,34 @@ async function loadShaderStyleProfile(input) {
2141
2657
  for (const requirement of manifest.requiredValidationScopes) {
2142
2658
  const evidence = validationScopes.get(requirement.scope);
2143
2659
  if (!evidence) {
2144
- throw new TypeError(`Shader ${resolved.manifest.shaderId} lacks required validation scope ${requirement.scope}.`);
2660
+ throw catalogFailure(`Shader ${resolved.manifest.shaderId} lacks required validation scope ${requirement.scope}.`);
2145
2661
  }
2146
2662
  if (evidence.matrixId !== requirement.matrixId || evidence.matrixVersion !== requirement.matrixVersion || evidence.matrixSha256 !== requirement.matrixSha256) {
2147
- throw new TypeError(
2663
+ throw catalogFailure(
2148
2664
  `Shader ${resolved.manifest.shaderId} validation scope ${requirement.scope} is bound to a different matrix policy.`
2149
2665
  );
2150
2666
  }
2151
2667
  }
2152
2668
  return [binding2.role, resolved];
2153
- }, input.signal);
2669
+ }, signal);
2154
2670
  assertDistinctEvidenceOwnership(pairs.map(([, shader]) => shader));
2155
2671
  return {
2156
2672
  ok: true,
2157
2673
  value: trustLoadedShaderStyleProfile({
2158
- ref: input.ref,
2674
+ ref,
2159
2675
  manifest,
2160
2676
  shaders: new Map(pairs)
2161
2677
  })
2162
2678
  };
2163
2679
  } catch (cause) {
2164
- if (input.signal?.aborted) throw cause;
2165
- const code = cause instanceof TypeError && /digest/u.test(cause.message) ? "digest-mismatch" : "invalid-contract";
2680
+ if (cause instanceof DOMException && cause.name === "AbortError") throw cause;
2681
+ const known = cause instanceof CatalogLoadError ? cause : void 0;
2166
2682
  return {
2167
2683
  ok: false,
2168
- diagnostics: [diagnostic(code, cause instanceof Error ? cause.message : "Style profile loading failed.")]
2684
+ diagnostics: [diagnostic(
2685
+ known?.diagnosticCode ?? "invalid-contract",
2686
+ known?.message ?? "Style profile loading failed."
2687
+ )]
2169
2688
  };
2170
2689
  }
2171
2690
  }
@@ -2492,6 +3011,7 @@ async function activateStyleProfile(input) {
2492
3011
  SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES,
2493
3012
  activateStyleProfile,
2494
3013
  asSha256Hex,
3014
+ assertImmutableAssetVersion,
2495
3015
  canonicalizeGpuContract,
2496
3016
  computeGpuAbiHash,
2497
3017
  computeSha256,