@hlos-ai/schemas 0.4.2 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -20,6 +20,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
+ AAREnvelopeV0Schema: () => AAREnvelopeV0Schema,
24
+ AAREnvelopeV0TypedSchema: () => AAREnvelopeV0TypedSchema,
25
+ AAR_ENVELOPE_TYPE: () => AAR_ENVELOPE_TYPE,
26
+ AAR_ENVELOPE_VERSION: () => AAR_ENVELOPE_VERSION,
23
27
  AgentListItemSchema: () => AgentListItemSchema,
24
28
  AgentPassportStubResponseSchema: () => AgentPassportStubResponseSchema,
25
29
  AgentStatusSchema: () => AgentStatusSchema,
@@ -30,7 +34,9 @@ __export(src_exports, {
30
34
  BASE64URL_SHA256_REGEX: () => BASE64URL_SHA256_REGEX,
31
35
  Base64urlEd25519SigSchema: () => Base64urlEd25519SigSchema,
32
36
  Base64urlSha256Schema: () => Base64urlSha256Schema,
37
+ CHAIN_STAGE_ORDER: () => CHAIN_STAGE_ORDER,
33
38
  CONTENT_HASH_LENGTH: () => CONTENT_HASH_LENGTH,
39
+ ChainStageTypeSchema: () => ChainStageTypeSchema,
34
40
  CorrelationIdSchema: () => CorrelationIdSchema,
35
41
  CredentialSourceSchema: () => CredentialSourceSchema,
36
42
  CrossingHashInputV0Schema: () => CrossingHashInputV0Schema,
@@ -38,8 +44,18 @@ __export(src_exports, {
38
44
  CrossingIdSchema: () => CrossingIdSchema,
39
45
  CrossingSettledReceiptSchema: () => CrossingSettledReceiptSchema,
40
46
  CrossingSnapshotV0Schema: () => CrossingSnapshotV0Schema,
47
+ CustodyReceiptContentSchema: () => CustodyReceiptContentSchema,
48
+ DispatchChainContentSchema: () => DispatchChainContentSchema,
49
+ DispatchIdBrand: () => DispatchIdBrand,
50
+ DispatchIdSchema: () => DispatchIdSchema,
41
51
  ERROR_CODE_STATUS: () => ERROR_CODE_STATUS,
52
+ EVAL_GOLDEN_FIXTURES: () => EVAL_GOLDEN_FIXTURES,
53
+ EconomicGateProofContentSchema: () => EconomicGateProofContentSchema,
42
54
  ErrorResponseSchema: () => ErrorResponseSchema,
55
+ EvalArtifactSchema: () => EvalArtifactSchema,
56
+ EvalFailureSchema: () => EvalFailureSchema,
57
+ EvalGraderResultSchema: () => EvalGraderResultSchema,
58
+ EvalTranscriptStepSchema: () => EvalTranscriptStepSchema,
43
59
  FINALITY_GOLDEN_FIXTURES: () => FINALITY_GOLDEN_FIXTURES,
44
60
  FinalityLevel: () => FinalityLevel,
45
61
  FundingSourceSchema: () => FundingSourceSchema,
@@ -48,6 +64,16 @@ __export(src_exports, {
48
64
  KernelErrorCodeSchema: () => KernelErrorCodeSchema2,
49
65
  KernelErrorSchema: () => KernelErrorSchema,
50
66
  KernelOkSchema: () => KernelOkSchema,
67
+ LIABILITY_WAIVER_TERMS_TYPE_URI: () => LIABILITY_WAIVER_TERMS_TYPE_URI,
68
+ LIABILITY_WAIVER_TERMS_VERSION: () => LIABILITY_WAIVER_TERMS_VERSION,
69
+ LiabilityAttestationContentSchema: () => LiabilityAttestationContentSchema,
70
+ LiabilityDispositionSchema: () => LiabilityDispositionSchema,
71
+ LiabilityWaiverTermsConditionsSchema: () => LiabilityWaiverTermsConditionsSchema,
72
+ LiabilityWaiverTermsHashInputSchema: () => LiabilityWaiverTermsHashInputSchema,
73
+ LiabilityWaiverTermsPartiesSchema: () => LiabilityWaiverTermsPartiesSchema,
74
+ LiabilityWaiverTermsRefV0Schema: () => LiabilityWaiverTermsRefV0Schema,
75
+ LiabilityWaiverTermsScopeSchema: () => LiabilityWaiverTermsScopeSchema,
76
+ LiabilityWaiverTermsV0Schema: () => LiabilityWaiverTermsV0Schema,
51
77
  LogInclusionProofSchema: () => LogInclusionProofSchema,
52
78
  NA_ID_PREFIX: () => NA_ID_PREFIX,
53
79
  NotarizeResponseSchema: () => NotarizeResponseSchema,
@@ -58,6 +84,7 @@ __export(src_exports, {
58
84
  PassportIdFormatSchema: () => PassportIdFormatSchema,
59
85
  PassportIdSchema: () => PassportIdSchema,
60
86
  ProviderRoleSchema: () => ProviderRoleSchema,
87
+ REASON_CODE_PATTERN: () => REASON_CODE_PATTERN,
61
88
  RECEIPT_HASH_GOLDEN_FIXTURE: () => RECEIPT_HASH_GOLDEN_FIXTURE,
62
89
  RECEIPT_TYPE_URI: () => RECEIPT_TYPE_URI,
63
90
  RECEIPT_VERSION: () => RECEIPT_VERSION,
@@ -69,9 +96,25 @@ __export(src_exports, {
69
96
  RotationEpochSchema: () => RotationEpochSchema,
70
97
  SETTLEMENT_AUTHORITY: () => SETTLEMENT_AUTHORITY,
71
98
  SIGNATURE_LENGTH: () => SIGNATURE_LENGTH,
99
+ SRR_INITIAL_REASON_CODES: () => SRR_INITIAL_REASON_CODES,
100
+ SRR_REJECTION_DOMAIN: () => SRR_REJECTION_DOMAIN,
101
+ SRR_SIGNATURE_ALGORITHM: () => SRR_SIGNATURE_ALGORITHM,
102
+ SRR_TYPE_URI: () => SRR_TYPE_URI,
103
+ SRR_V1_REJECTION_DOMAIN: () => SRR_V1_REJECTION_DOMAIN,
104
+ SRR_V1_SIGNATURE_ALGORITHM: () => SRR_V1_SIGNATURE_ALGORITHM,
105
+ SRR_V1_TYPE_URI: () => SRR_V1_TYPE_URI,
106
+ SRR_V1_VERSION: () => SRR_V1_VERSION,
107
+ SRR_VERSION: () => SRR_VERSION,
72
108
  SURFACES: () => SURFACES,
109
+ SettlementAnchorContentSchema: () => SettlementAnchorContentSchema,
110
+ SettlementExecuteErrorSchema: () => SettlementExecuteErrorSchema,
111
+ SettlementExecuteRequestSchema: () => SettlementExecuteRequestSchema,
112
+ SettlementExecuteResponseSchema: () => SettlementExecuteResponseSchema,
113
+ SettlementExecuteSuccessSchema: () => SettlementExecuteSuccessSchema,
73
114
  SignedReceiptV0LooseSchema: () => SignedReceiptV0LooseSchema,
74
115
  SignedReceiptV0Schema: () => SignedReceiptV0Schema,
116
+ SignedRejectionReceiptV0Schema: () => SignedRejectionReceiptV0Schema,
117
+ SignedRejectionReceiptV1Schema: () => SignedRejectionReceiptV1Schema,
75
118
  StackConnectionSchema: () => StackConnectionSchema,
76
119
  StackProviderSchema: () => StackProviderSchema,
77
120
  StackSchema: () => StackSchema,
@@ -84,14 +127,20 @@ __export(src_exports, {
84
127
  W_TXCTX_DOMAIN: () => W_TXCTX_DOMAIN,
85
128
  WalletIdFormatSchema: () => WalletIdFormatSchema,
86
129
  WalletIdSchema: () => WalletIdSchema,
130
+ assertRootHash: () => assertRootHash,
131
+ assertValidChainLink: () => assertValidChainLink,
87
132
  base64urlToBytes: () => base64urlToBytes,
88
133
  bytesToBase64url: () => bytesToBase64url,
89
134
  computeContentHash: () => computeContentHash,
135
+ computeLiabilityWaiverTermsHash: () => computeLiabilityWaiverTermsHash,
90
136
  computeReceiptHash: () => computeReceiptHash,
137
+ computeSrrDigest: () => computeSrrDigest,
138
+ computeSrrSigningPayload: () => computeSrrSigningPayload,
91
139
  deriveFundingSource: () => deriveFundingSource,
92
140
  encodeEpoch: () => encodeEpoch,
93
141
  error: () => error,
94
142
  generateCrossingId: () => generateCrossingId,
143
+ generateDispatchId: () => generateDispatchId,
95
144
  generateId: () => generateId,
96
145
  generatePassportId: () => generatePassportId,
97
146
  generateReceiptId: () => generateReceiptId,
@@ -100,18 +149,223 @@ __export(src_exports, {
100
149
  isCrossingSettledReceipt: () => isCrossingSettledReceipt,
101
150
  isNotaryAttestation: () => isNotaryAttestation,
102
151
  isNotaryRequest: () => isNotaryRequest,
152
+ isSettlementExecuteError: () => isSettlementExecuteError,
153
+ isSettlementExecuteSuccess: () => isSettlementExecuteSuccess,
103
154
  isSignedReceiptV0: () => isSignedReceiptV0,
104
155
  jcsCanonicalize: () => jcsCanonicalize,
105
156
  kernelError: () => kernelError,
106
157
  kernelOk: () => kernelOk,
107
158
  success: () => success,
108
- validateTimeWindow: () => validateTimeWindow
159
+ toLiabilityWaiverTermsHashInput: () => toLiabilityWaiverTermsHashInput,
160
+ validateTimeWindow: () => validateTimeWindow,
161
+ verifyAAR: () => verifyAAR,
162
+ verifyDetachedEd25519: () => verifyDetachedEd25519,
163
+ verifySignedRejectionReceipt: () => verifySignedRejectionReceipt
109
164
  });
110
165
  module.exports = __toCommonJS(src_exports);
111
166
 
112
- // src/surface.ts
167
+ // src/aar-envelope-v0.ts
168
+ var import_zod2 = require("zod");
169
+
170
+ // src/encoding.ts
113
171
  var import_zod = require("zod");
114
- var SurfaceSchema = import_zod.z.enum([
172
+ function bytesToBase64url(bytes) {
173
+ let binary = "";
174
+ for (let i = 0; i < bytes.length; i++) {
175
+ binary += String.fromCharCode(bytes[i]);
176
+ }
177
+ const base64 = btoa(binary);
178
+ return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
179
+ }
180
+ function base64urlToBytes(str) {
181
+ const base64 = str.replace(/-/g, "+").replace(/_/g, "/");
182
+ const padded = base64 + "=".repeat((4 - base64.length % 4) % 4);
183
+ const binary = atob(padded);
184
+ const bytes = new Uint8Array(binary.length);
185
+ for (let i = 0; i < binary.length; i++) {
186
+ bytes[i] = binary.charCodeAt(i);
187
+ }
188
+ return bytes;
189
+ }
190
+ var BASE64URL_SHA256_REGEX = /^[A-Za-z0-9_-]{43}$/;
191
+ var Base64urlSha256Schema = import_zod.z.string().regex(
192
+ BASE64URL_SHA256_REGEX,
193
+ "Must be 43-char base64url (32-byte SHA-256 digest)"
194
+ );
195
+ var Base64urlEd25519SigSchema = import_zod.z.string().regex(
196
+ /^[A-Za-z0-9_-]{86}$/,
197
+ "Must be 86-char base64url (64-byte Ed25519 signature)"
198
+ );
199
+
200
+ // src/aar-envelope-v0.ts
201
+ var AAR_ENVELOPE_TYPE = "https://hlos.ai/schema/AAREnvelopeV0";
202
+ var AAR_ENVELOPE_VERSION = 0;
203
+ var AAREnvelopeV0Schema = import_zod2.z.object({
204
+ "@type": import_zod2.z.literal(AAR_ENVELOPE_TYPE),
205
+ version: import_zod2.z.literal(AAR_ENVELOPE_VERSION),
206
+ content_type: import_zod2.z.string().min(1),
207
+ content_hash: Base64urlSha256Schema,
208
+ inner: import_zod2.z.unknown(),
209
+ signer_id: import_zod2.z.string().min(1),
210
+ signature: Base64urlEd25519SigSchema,
211
+ issued_at: import_zod2.z.string().datetime(),
212
+ previous_aar_hash: import_zod2.z.string().min(1)
213
+ });
214
+ var AAREnvelopeV0TypedSchema = (contentType, innerSchema) => AAREnvelopeV0Schema.extend({
215
+ content_type: import_zod2.z.literal(contentType),
216
+ inner: innerSchema
217
+ });
218
+
219
+ // src/receipt-hash.ts
220
+ var cachedSha256 = null;
221
+ function sortKeysDeep(value) {
222
+ if (Array.isArray(value)) return value.map(sortKeysDeep);
223
+ if (value !== null && typeof value === "object") {
224
+ const obj = value;
225
+ const out = {};
226
+ for (const key of Object.keys(obj).sort()) {
227
+ out[key] = sortKeysDeep(obj[key]);
228
+ }
229
+ return out;
230
+ }
231
+ return value;
232
+ }
233
+ function hasLoneSurrogate(s) {
234
+ for (let i = 0; i < s.length; i++) {
235
+ const code = s.charCodeAt(i);
236
+ if (code >= 55296 && code <= 56319) {
237
+ const next = s.charCodeAt(i + 1);
238
+ if (isNaN(next) || next < 56320 || next > 57343) return true;
239
+ i++;
240
+ } else if (code >= 56320 && code <= 57343) {
241
+ return true;
242
+ }
243
+ }
244
+ return false;
245
+ }
246
+ function jcsCanonicalize(value) {
247
+ return JSON.stringify(sortKeysDeep(value), (_key, v) => {
248
+ if (v === void 0) throw new Error("JCS: undefined is not allowed");
249
+ if (typeof v === "function") throw new Error("JCS: function is not allowed");
250
+ if (typeof v === "symbol") throw new Error("JCS: symbol is not allowed");
251
+ if (typeof v === "bigint") throw new Error("JCS: bigint is not allowed");
252
+ if (typeof v === "number" && !Number.isFinite(v))
253
+ throw new Error("JCS: non-finite number is not allowed");
254
+ if (typeof v === "string" && hasLoneSurrogate(v))
255
+ throw new Error("JCS: lone surrogate (U+D800\u2013U+DFFF) is not allowed");
256
+ return v;
257
+ });
258
+ }
259
+ function computeReceiptHash(receipt) {
260
+ const sha256 = loadSha256();
261
+ const canonical = jcsCanonicalize(receipt);
262
+ const digest = sha256(new TextEncoder().encode(canonical));
263
+ return bytesToBase64url(digest);
264
+ }
265
+ function computeContentHash(content) {
266
+ const sha256 = loadSha256();
267
+ const canonical = jcsCanonicalize(content);
268
+ const digest = sha256(new TextEncoder().encode(canonical));
269
+ return bytesToBase64url(digest);
270
+ }
271
+ function loadSha256() {
272
+ if (cachedSha256) return cachedSha256;
273
+ const moduleApi = typeof process.getBuiltinModule === "function" ? process.getBuiltinModule("module") : (
274
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
275
+ require("module")
276
+ );
277
+ const createRequire = moduleApi.createRequire;
278
+ const requireBase = typeof __filename === "string" ? __filename : `${process.cwd()}/package.json`;
279
+ const _require = createRequire(requireBase);
280
+ let sha256;
281
+ try {
282
+ sha256 = _require("@noble/hashes/sha2.js").sha256;
283
+ } catch {
284
+ try {
285
+ sha256 = _require("@noble/hashes/sha2").sha256;
286
+ } catch {
287
+ throw new Error(
288
+ "computeReceiptHash/computeContentHash requires @noble/hashes as a peer dependency. Install it: npm install @noble/hashes"
289
+ );
290
+ }
291
+ }
292
+ cachedSha256 = sha256;
293
+ return sha256;
294
+ }
295
+ var ReceiptHashSchema = Base64urlSha256Schema.describe(
296
+ "receipt_hash: base64url(SHA-256(JCS(receipt)))"
297
+ );
298
+ var RECEIPT_HASH_GOLDEN_FIXTURE = {
299
+ receipt: {
300
+ "@type": "https://hlos.ai/schema/SignedReceiptV0",
301
+ version: 0,
302
+ receipt_id: "rcpt_01HZGOLDENTEST000000000000",
303
+ content: {
304
+ type: "CrossingSettled",
305
+ crossingId: "cross_test123abc456def789ghi",
306
+ settlement_authority: "hlos.ai"
307
+ },
308
+ // Placeholder bytes (NOT a valid cryptographic signature)
309
+ content_hash: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
310
+ signature: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
311
+ key_id: "hlos-v2-1",
312
+ issued_at: "2026-01-27T00:00:00.000Z"
313
+ },
314
+ /**
315
+ * Expected JCS canonical form of the receipt.
316
+ * Keys are lexicographically sorted at all levels.
317
+ */
318
+ expectedJcs: '{"@type":"https://hlos.ai/schema/SignedReceiptV0","content":{"crossingId":"cross_test123abc456def789ghi","settlement_authority":"hlos.ai","type":"CrossingSettled"},"content_hash":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","issued_at":"2026-01-27T00:00:00.000Z","key_id":"hlos-v2-1","receipt_id":"rcpt_01HZGOLDENTEST000000000000","signature":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","version":0}',
319
+ /**
320
+ * Expected receipt_hash (FROZEN).
321
+ * Compute: JCS canonicalize receipt → SHA-256 → base64url (no padding)
322
+ *
323
+ * DO NOT CHANGE unless the receipt fixture above changes.
324
+ */
325
+ expectedReceiptHash: "uLiQVUeVKcE35Rdje2fArZQfTcECDgwK6UbmQB_36Pg"
326
+ };
327
+
328
+ // src/verify-aar.ts
329
+ function toBuffer(bytes) {
330
+ const ab = new ArrayBuffer(bytes.byteLength);
331
+ new Uint8Array(ab).set(bytes);
332
+ return ab;
333
+ }
334
+ async function importPublicKey(publicKey) {
335
+ if (typeof CryptoKey !== "undefined" && publicKey instanceof CryptoKey) {
336
+ return publicKey;
337
+ }
338
+ const raw = publicKey;
339
+ return crypto.subtle.importKey(
340
+ "raw",
341
+ toBuffer(raw),
342
+ "Ed25519",
343
+ false,
344
+ ["verify"]
345
+ );
346
+ }
347
+ async function verifyAAR(envelope, publicKey) {
348
+ const parsed = AAREnvelopeV0Schema.parse(envelope);
349
+ const contentHash = computeContentHash(parsed.inner);
350
+ if (contentHash !== parsed.content_hash) {
351
+ throw new Error("AAR content hash mismatch");
352
+ }
353
+ const key = await importPublicKey(publicKey);
354
+ const verified = await crypto.subtle.verify(
355
+ "Ed25519",
356
+ key,
357
+ toBuffer(base64urlToBytes(parsed.signature)),
358
+ toBuffer(base64urlToBytes(parsed.content_hash))
359
+ );
360
+ if (!verified) {
361
+ throw new Error(`AAR signature verification failed for signer ${parsed.signer_id}`);
362
+ }
363
+ return parsed;
364
+ }
365
+
366
+ // src/surface.ts
367
+ var import_zod3 = require("zod");
368
+ var SurfaceSchema = import_zod3.z.enum([
115
369
  "mcp",
116
370
  // Model Context Protocol servers
117
371
  "x402",
@@ -130,11 +384,11 @@ var SurfaceSchema = import_zod.z.enum([
130
384
  var SURFACES = SurfaceSchema.options;
131
385
 
132
386
  // src/response.ts
133
- var import_zod3 = require("zod");
387
+ var import_zod5 = require("zod");
134
388
 
135
389
  // src/error-codes.ts
136
- var import_zod2 = require("zod");
137
- var KernelErrorCodeSchema = import_zod2.z.enum([
390
+ var import_zod4 = require("zod");
391
+ var KernelErrorCodeSchema = import_zod4.z.enum([
138
392
  // 4xx Client Errors
139
393
  "INVALID_REQUEST",
140
394
  // 400 - Malformed request body
@@ -183,49 +437,49 @@ function error(code, message, correlationId, details) {
183
437
  }
184
438
  };
185
439
  }
186
- var SuccessResponseSchema = (dataSchema) => import_zod3.z.object({
187
- success: import_zod3.z.literal(true),
440
+ var SuccessResponseSchema = (dataSchema) => import_zod5.z.object({
441
+ success: import_zod5.z.literal(true),
188
442
  data: dataSchema,
189
- meta: import_zod3.z.object({
190
- request_id: import_zod3.z.string().optional(),
191
- correlation_id: import_zod3.z.string()
443
+ meta: import_zod5.z.object({
444
+ request_id: import_zod5.z.string().optional(),
445
+ correlation_id: import_zod5.z.string()
192
446
  }).optional()
193
447
  });
194
- var ErrorResponseSchema = import_zod3.z.object({
195
- success: import_zod3.z.literal(false),
196
- error: import_zod3.z.object({
448
+ var ErrorResponseSchema = import_zod5.z.object({
449
+ success: import_zod5.z.literal(false),
450
+ error: import_zod5.z.object({
197
451
  code: KernelErrorCodeSchema,
198
- message: import_zod3.z.string(),
199
- details: import_zod3.z.unknown().optional(),
200
- correlation_id: import_zod3.z.string()
452
+ message: import_zod5.z.string(),
453
+ details: import_zod5.z.unknown().optional(),
454
+ correlation_id: import_zod5.z.string()
201
455
  })
202
456
  });
203
457
 
204
458
  // src/receipt-v0.ts
205
- var import_zod4 = require("zod");
459
+ var import_zod6 = require("zod");
206
460
  var RECEIPT_TYPE_URI = "https://hlos.ai/schema/SignedReceiptV0";
207
461
  var RECEIPT_VERSION = 0;
208
462
  var CONTENT_HASH_LENGTH = 43;
209
463
  var SIGNATURE_LENGTH = 86;
210
- var SignedReceiptV0Schema = (contentSchema) => import_zod4.z.object({
211
- "@type": import_zod4.z.literal(RECEIPT_TYPE_URI),
212
- version: import_zod4.z.literal(RECEIPT_VERSION),
213
- receipt_id: import_zod4.z.string(),
464
+ var SignedReceiptV0Schema = (contentSchema) => import_zod6.z.object({
465
+ "@type": import_zod6.z.literal(RECEIPT_TYPE_URI),
466
+ version: import_zod6.z.literal(RECEIPT_VERSION),
467
+ receipt_id: import_zod6.z.string(),
214
468
  content: contentSchema,
215
469
  // SHA-256 digest (32 bytes) = exactly 43 chars base64url
216
- content_hash: import_zod4.z.string().regex(
470
+ content_hash: import_zod6.z.string().regex(
217
471
  /^[A-Za-z0-9_-]{43}$/,
218
472
  "content_hash must be 43-char base64url (32-byte SHA-256)"
219
473
  ),
220
474
  // Ed25519 signature (64 bytes) = exactly 86 chars base64url
221
- signature: import_zod4.z.string().regex(
475
+ signature: import_zod6.z.string().regex(
222
476
  /^[A-Za-z0-9_-]{86}$/,
223
477
  "signature must be 86-char base64url (64-byte Ed25519)"
224
478
  ),
225
- key_id: import_zod4.z.string().min(1),
226
- issued_at: import_zod4.z.string().datetime()
479
+ key_id: import_zod6.z.string().min(1),
480
+ issued_at: import_zod6.z.string().datetime()
227
481
  });
228
- var SignedReceiptV0LooseSchema = SignedReceiptV0Schema(import_zod4.z.unknown());
482
+ var SignedReceiptV0LooseSchema = SignedReceiptV0Schema(import_zod6.z.unknown());
229
483
  function isSignedReceiptV0(value) {
230
484
  if (typeof value !== "object" || value === null) return false;
231
485
  const obj = value;
@@ -233,13 +487,15 @@ function isSignedReceiptV0(value) {
233
487
  }
234
488
 
235
489
  // src/ids.ts
236
- var import_zod5 = require("zod");
237
- var WalletIdSchema = import_zod5.z.string().regex(/^wallet_[a-z0-9]{20,}$/i, "Invalid WalletId format").transform((s) => s);
238
- var PassportIdSchema = import_zod5.z.string().regex(/^passport_[a-z0-9]{20,}$/i, "Invalid PassportId format").transform((s) => s);
239
- var ReceiptIdSchema = import_zod5.z.string().regex(/^rcpt_[0-9A-HJKMNP-TV-Z]{26}$/i, "Invalid ReceiptId format").transform((s) => s);
240
- var CorrelationIdSchema = import_zod5.z.string().min(8).max(128).transform((s) => s);
241
- var IdempotencyKeySchema = import_zod5.z.string().min(1).max(256).regex(/^[\x20-\x7E]+$/, "IdempotencyKey must be printable ASCII").transform((s) => s);
242
- var CrossingIdSchema = import_zod5.z.string().regex(/^cross_[a-z0-9]{20,}$/i, "Invalid CrossingId format").transform((s) => s);
490
+ var import_zod7 = require("zod");
491
+ var DispatchIdBrand = /* @__PURE__ */ Symbol("DispatchIdBrand");
492
+ var WalletIdSchema = import_zod7.z.string().regex(/^wallet_[a-z0-9]{20,}$/i, "Invalid WalletId format").transform((s) => s);
493
+ var PassportIdSchema = import_zod7.z.string().regex(/^passport_[a-z0-9]{20,}$/i, "Invalid PassportId format").transform((s) => s);
494
+ var ReceiptIdSchema = import_zod7.z.string().regex(/^rcpt_[0-9A-HJKMNP-TV-Z]{26}$/i, "Invalid ReceiptId format").transform((s) => s);
495
+ var CorrelationIdSchema = import_zod7.z.string().min(8).max(128).transform((s) => s);
496
+ var IdempotencyKeySchema = import_zod7.z.string().min(1).max(256).regex(/^[\x20-\x7E]+$/, "IdempotencyKey must be printable ASCII").transform((s) => s);
497
+ var CrossingIdSchema = import_zod7.z.string().regex(/^cross_[a-z0-9]{20,}$/i, "Invalid CrossingId format").transform((s) => s);
498
+ var DispatchIdSchema = import_zod7.z.string().regex(/^dispatch_[a-z0-9]{20,}$/, "Invalid DispatchId format").transform((s) => s);
243
499
  function generateId(prefix) {
244
500
  const timestamp = Date.now().toString(36);
245
501
  const random = crypto.randomUUID().replace(/-/g, "").slice(0, 16);
@@ -249,10 +505,11 @@ var generateWalletId = () => generateId("wallet");
249
505
  var generatePassportId = () => generateId("passport");
250
506
  var generateReceiptId = () => generateId("rcpt");
251
507
  var generateCrossingId = () => generateId("cross");
508
+ var generateDispatchId = () => generateId("dispatch");
252
509
 
253
510
  // src/shared-contract.ts
254
- var import_zod6 = require("zod");
255
- var KernelErrorCodeSchema2 = import_zod6.z.enum([
511
+ var import_zod8 = require("zod");
512
+ var KernelErrorCodeSchema2 = import_zod8.z.enum([
256
513
  // Validation / Request errors
257
514
  "VALIDATION_ERROR",
258
515
  // 400 - Input validation failed
@@ -314,30 +571,30 @@ var ERROR_CODE_STATUS = {
314
571
  INTERNAL_ERROR: 500,
315
572
  SERVICE_UNAVAILABLE: 503
316
573
  };
317
- var KernelOkSchema = (dataSchema) => import_zod6.z.object({
318
- ok: import_zod6.z.literal(true),
319
- status: import_zod6.z.union([
320
- import_zod6.z.number().int().min(200).max(299),
321
- import_zod6.z.literal(304)
574
+ var KernelOkSchema = (dataSchema) => import_zod8.z.object({
575
+ ok: import_zod8.z.literal(true),
576
+ status: import_zod8.z.union([
577
+ import_zod8.z.number().int().min(200).max(299),
578
+ import_zod8.z.literal(304)
322
579
  ]),
323
580
  data: dataSchema
324
581
  });
325
- var KernelErrorSchema = import_zod6.z.object({
326
- ok: import_zod6.z.literal(false),
327
- status: import_zod6.z.number().int().min(400).max(599),
328
- error: import_zod6.z.object({
582
+ var KernelErrorSchema = import_zod8.z.object({
583
+ ok: import_zod8.z.literal(false),
584
+ status: import_zod8.z.number().int().min(400).max(599),
585
+ error: import_zod8.z.object({
329
586
  code: KernelErrorCodeSchema2,
330
587
  // P0 FIX: was z.string()
331
- message: import_zod6.z.string(),
332
- details: import_zod6.z.record(import_zod6.z.unknown()).optional()
588
+ message: import_zod8.z.string(),
589
+ details: import_zod8.z.record(import_zod8.z.unknown()).optional()
333
590
  })
334
591
  });
335
- var CrossingIdFormatSchema = import_zod6.z.string().regex(/^cross_[a-z0-9]{20,}$/i, "Invalid CrossingId format (expected: cross_...)");
336
- var ReceiptIdFormatSchema = import_zod6.z.string().regex(/^rcpt_[0-9A-HJKMNP-TV-Z]{26}$/i, "Invalid ReceiptId format (expected: rcpt_...)");
337
- var PassportIdFormatSchema = import_zod6.z.string().regex(/^passport_[a-z0-9]{20,}$/i, "Invalid PassportId format (expected: passport_...)");
338
- var WalletIdFormatSchema = import_zod6.z.string().regex(/^wallet_[a-z0-9]{20,}$/i, "Invalid WalletId format (expected: wallet_...)");
339
- var FundingSourceSchema = import_zod6.z.enum(["SPONSOR", "PLATFORM", "USER"]);
340
- var CredentialSourceSchema = import_zod6.z.enum([
592
+ var CrossingIdFormatSchema = import_zod8.z.string().regex(/^cross_[a-z0-9]{20,}$/i, "Invalid CrossingId format (expected: cross_...)");
593
+ var ReceiptIdFormatSchema = import_zod8.z.string().regex(/^rcpt_[0-9A-HJKMNP-TV-Z]{26}$/i, "Invalid ReceiptId format (expected: rcpt_...)");
594
+ var PassportIdFormatSchema = import_zod8.z.string().regex(/^passport_[a-z0-9]{20,}$/i, "Invalid PassportId format (expected: passport_...)");
595
+ var WalletIdFormatSchema = import_zod8.z.string().regex(/^wallet_[a-z0-9]{20,}$/i, "Invalid WalletId format (expected: wallet_...)");
596
+ var FundingSourceSchema = import_zod8.z.enum(["SPONSOR", "PLATFORM", "USER"]);
597
+ var CredentialSourceSchema = import_zod8.z.enum([
341
598
  "SPONSOR_KEY",
342
599
  // Sponsor-provisioned key
343
600
  "BYOK",
@@ -355,46 +612,46 @@ function deriveFundingSource(credentialSource) {
355
612
  return "PLATFORM";
356
613
  }
357
614
  }
358
- var CrossingSnapshotV0Schema = import_zod6.z.object({
615
+ var CrossingSnapshotV0Schema = import_zod8.z.object({
359
616
  crossingId: CrossingIdFormatSchema,
360
- capabilityId: import_zod6.z.string(),
617
+ capabilityId: import_zod8.z.string(),
361
618
  passportId: PassportIdFormatSchema,
362
619
  // Scoping
363
- event_id: import_zod6.z.string().nullable(),
364
- access_window_id: import_zod6.z.string().nullable(),
365
- access_grant_id: import_zod6.z.string().nullable(),
620
+ event_id: import_zod8.z.string().nullable(),
621
+ access_window_id: import_zod8.z.string().nullable(),
622
+ access_grant_id: import_zod8.z.string().nullable(),
366
623
  // Attribution
367
- attribution_org_id: import_zod6.z.string().nullable(),
624
+ attribution_org_id: import_zod8.z.string().nullable(),
368
625
  funding_source: FundingSourceSchema.nullable(),
369
626
  credential_source: CredentialSourceSchema
370
627
  });
371
- var CrossingHashInputV0Schema = import_zod6.z.object({
372
- v: import_zod6.z.literal(0),
628
+ var CrossingHashInputV0Schema = import_zod8.z.object({
629
+ v: import_zod8.z.literal(0),
373
630
  snapshot: CrossingSnapshotV0Schema,
374
631
  attested_receipt_id: ReceiptIdFormatSchema
375
632
  });
376
633
  var SETTLEMENT_AUTHORITY = "hlos.ai";
377
- var CrossingSettledReceiptSchema = import_zod6.z.object({
378
- type: import_zod6.z.literal("CrossingSettled"),
634
+ var CrossingSettledReceiptSchema = import_zod8.z.object({
635
+ type: import_zod8.z.literal("CrossingSettled"),
379
636
  crossingId: CrossingIdFormatSchema,
380
637
  // Scoping (powers adoption + ROI views)
381
- event_id: import_zod6.z.string().nullable(),
382
- access_window_id: import_zod6.z.string().nullable(),
383
- access_grant_id: import_zod6.z.string().nullable(),
638
+ event_id: import_zod8.z.string().nullable(),
639
+ access_window_id: import_zod8.z.string().nullable(),
640
+ access_grant_id: import_zod8.z.string().nullable(),
384
641
  // Attribution
385
- attribution_org_id: import_zod6.z.string().nullable(),
642
+ attribution_org_id: import_zod8.z.string().nullable(),
386
643
  funding_source: FundingSourceSchema.nullable(),
387
644
  credential_source: CredentialSourceSchema,
388
645
  // Authority (LITERAL)
389
- settlement_authority: import_zod6.z.literal(SETTLEMENT_AUTHORITY),
646
+ settlement_authority: import_zod8.z.literal(SETTLEMENT_AUTHORITY),
390
647
  // Binding
391
- crossing_hash: import_zod6.z.string(),
648
+ crossing_hash: import_zod8.z.string(),
392
649
  // sha256 base64url of CrossingHashInputV0
393
- attested_receipt_id: import_zod6.z.string(),
650
+ attested_receipt_id: import_zod8.z.string(),
394
651
  // Timestamp
395
- settled_at: import_zod6.z.string().datetime()
652
+ settled_at: import_zod8.z.string().datetime()
396
653
  });
397
- var AvailabilityTypeSchema = import_zod6.z.enum([
654
+ var AvailabilityTypeSchema = import_zod8.z.enum([
398
655
  "EVENT_SPONSOR",
399
656
  // Sponsor-funded for specific event
400
657
  "EVERGREEN",
@@ -402,7 +659,7 @@ var AvailabilityTypeSchema = import_zod6.z.enum([
402
659
  "CATALOG"
403
660
  // User-paid from catalog
404
661
  ]);
405
- var ProviderRoleSchema = import_zod6.z.enum([
662
+ var ProviderRoleSchema = import_zod8.z.enum([
406
663
  "AI",
407
664
  // AI/LLM providers (Gemini, GPT, Claude)
408
665
  "DATABASE",
@@ -422,35 +679,35 @@ var ProviderRoleSchema = import_zod6.z.enum([
422
679
  "OTHER"
423
680
  // Catch-all for new categories
424
681
  ]);
425
- var StackProviderSchema = import_zod6.z.object({
426
- provider_id: import_zod6.z.string(),
682
+ var StackProviderSchema = import_zod8.z.object({
683
+ provider_id: import_zod8.z.string(),
427
684
  role: ProviderRoleSchema,
428
685
  // P1: Now a constrained enum
429
- display_name: import_zod6.z.string(),
430
- budget_allocation: import_zod6.z.number().nonnegative(),
431
- sku_ids: import_zod6.z.array(import_zod6.z.string()),
686
+ display_name: import_zod8.z.string(),
687
+ budget_allocation: import_zod8.z.number().nonnegative(),
688
+ sku_ids: import_zod8.z.array(import_zod8.z.string()),
432
689
  availability_type: AvailabilityTypeSchema
433
690
  });
434
- var StackSchema = import_zod6.z.object({
435
- id: import_zod6.z.string(),
436
- slug: import_zod6.z.string(),
437
- name: import_zod6.z.string(),
438
- tagline: import_zod6.z.string(),
439
- icon: import_zod6.z.string(),
440
- providers: import_zod6.z.array(StackProviderSchema),
441
- github_template: import_zod6.z.string().nullable(),
442
- total_budget: import_zod6.z.number().nonnegative(),
443
- event_id: import_zod6.z.string().nullable()
691
+ var StackSchema = import_zod8.z.object({
692
+ id: import_zod8.z.string(),
693
+ slug: import_zod8.z.string(),
694
+ name: import_zod8.z.string(),
695
+ tagline: import_zod8.z.string(),
696
+ icon: import_zod8.z.string(),
697
+ providers: import_zod8.z.array(StackProviderSchema),
698
+ github_template: import_zod8.z.string().nullable(),
699
+ total_budget: import_zod8.z.number().nonnegative(),
700
+ event_id: import_zod8.z.string().nullable()
444
701
  // null = evergreen
445
702
  });
446
- var StackConnectionSchema = import_zod6.z.object({
447
- id: import_zod6.z.string(),
448
- stack_id: import_zod6.z.string(),
449
- passport_id: import_zod6.z.string(),
450
- team_id: import_zod6.z.string().nullable(),
451
- environment_id: import_zod6.z.string(),
452
- connected_at: import_zod6.z.string().datetime(),
453
- connected_providers: import_zod6.z.array(import_zod6.z.string())
703
+ var StackConnectionSchema = import_zod8.z.object({
704
+ id: import_zod8.z.string(),
705
+ stack_id: import_zod8.z.string(),
706
+ passport_id: import_zod8.z.string(),
707
+ team_id: import_zod8.z.string().nullable(),
708
+ environment_id: import_zod8.z.string(),
709
+ connected_at: import_zod8.z.string().datetime(),
710
+ connected_providers: import_zod8.z.array(import_zod8.z.string())
454
711
  });
455
712
  function kernelOk(data, status = 200) {
456
713
  return { ok: true, status, data };
@@ -519,7 +776,7 @@ function isCrossingSettledReceipt(value) {
519
776
  }
520
777
 
521
778
  // src/w.ts
522
- var import_zod7 = require("zod");
779
+ var import_zod9 = require("zod");
523
780
  var W_RPID_DOMAIN = new TextEncoder().encode("W:RPID:v1");
524
781
  var W_TXCTX_DOMAIN = new TextEncoder().encode("W:TXCTX:v1");
525
782
  var RFC3339_CAPTURING = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(\.(\d{1,9}))?(Z|([+-])(\d{2}):(\d{2}))$/;
@@ -597,36 +854,36 @@ function encodeEpoch(epoch) {
597
854
  view.setBigUint64(0, BigInt(ms), false);
598
855
  return new Uint8Array(buf);
599
856
  }
600
- var RelyingPartyIdSchema = import_zod7.z.object({
857
+ var RelyingPartyIdSchema = import_zod9.z.object({
601
858
  /** RP domain (e.g., "merchant.example.com") */
602
- domain: import_zod7.z.string().min(1).max(253),
859
+ domain: import_zod9.z.string().min(1).max(253),
603
860
  /** Audience URI (e.g., "https://merchant.example.com/verify") */
604
- audience_uri: import_zod7.z.string().url(),
861
+ audience_uri: import_zod9.z.string().url(),
605
862
  /** SHA-256 hash of verifier's public key (hex, 64 chars) */
606
- verifier_key_hash: import_zod7.z.string().regex(/^[a-f0-9]{64}$/, "Must be 64-char lowercase hex")
863
+ verifier_key_hash: import_zod9.z.string().regex(/^[a-f0-9]{64}$/, "Must be 64-char lowercase hex")
607
864
  });
608
- var RotationEpochSchema = import_zod7.z.union([
609
- import_zod7.z.number().int().nonnegative(),
610
- import_zod7.z.string().datetime({ offset: true })
865
+ var RotationEpochSchema = import_zod9.z.union([
866
+ import_zod9.z.number().int().nonnegative(),
867
+ import_zod9.z.string().datetime({ offset: true })
611
868
  // Requires timezone offset (RFC3339)
612
869
  ]);
613
- var RPIDSchema = import_zod7.z.string().length(43, "RPID must be base64url-encoded 32 bytes (43 chars, no padding)").regex(/^[A-Za-z0-9_-]+$/, "Must be base64url (no padding)");
614
- var TransactionContextSchema = import_zod7.z.object({
870
+ var RPIDSchema = import_zod9.z.string().length(43, "RPID must be base64url-encoded 32 bytes (43 chars, no padding)").regex(/^[A-Za-z0-9_-]+$/, "Must be base64url (no padding)");
871
+ var TransactionContextSchema = import_zod9.z.object({
615
872
  // Required core (stable)
616
873
  relying_party_id: RelyingPartyIdSchema,
617
874
  /** sha256(JCS({ intent, request })) — see computeOperationHash() */
618
- operation_hash: import_zod7.z.string().regex(/^[a-f0-9]{64}$/, "Must be 64-char lowercase hex"),
875
+ operation_hash: import_zod9.z.string().regex(/^[a-f0-9]{64}$/, "Must be 64-char lowercase hex"),
619
876
  /** Validity start (RFC3339) */
620
- not_before: import_zod7.z.string().datetime({ offset: true }),
877
+ not_before: import_zod9.z.string().datetime({ offset: true }),
621
878
  /** Validity end (RFC3339) */
622
- not_after: import_zod7.z.string().datetime({ offset: true }),
879
+ not_after: import_zod9.z.string().datetime({ offset: true }),
623
880
  // Optional (part of hash, must be consistent)
624
- amount: import_zod7.z.number().nonnegative().optional(),
625
- currency: import_zod7.z.string().length(3).optional(),
626
- surface_id: import_zod7.z.string().optional(),
627
- channel_id: import_zod7.z.string().optional()
881
+ amount: import_zod9.z.number().nonnegative().optional(),
882
+ currency: import_zod9.z.string().length(3).optional(),
883
+ surface_id: import_zod9.z.string().optional(),
884
+ channel_id: import_zod9.z.string().optional()
628
885
  });
629
- var TransactionContextHashSchema = import_zod7.z.string().regex(/^[a-f0-9]{64}$/, "Must be 64-char lowercase hex");
886
+ var TransactionContextHashSchema = import_zod9.z.string().regex(/^[a-f0-9]{64}$/, "Must be 64-char lowercase hex");
630
887
  var W_GOLDEN_FIXTURES = {
631
888
  /**
632
889
  * encodeEpoch(1706486400000) = 2024-01-29T00:00:00.000Z
@@ -682,236 +939,199 @@ function validateTimeWindow(context) {
682
939
  }
683
940
 
684
941
  // src/agents.ts
685
- var import_zod8 = require("zod");
686
- var AgentStatusSchema = import_zod8.z.enum(["ACTIVE", "PENDING", "SUSPENDED", "REVOKED"]).or(import_zod8.z.string().min(1));
687
- var AgentTypeSchema = import_zod8.z.enum(["CUSTOM", "CLAUDE", "GPT", "GEMINI", "CURSOR", "COPILOT", "OTHER"]).or(import_zod8.z.string().min(1));
688
- var AgentListItemSchema = import_zod8.z.object({
689
- id: import_zod8.z.string().min(1),
690
- external_id: import_zod8.z.string().min(1),
691
- name: import_zod8.z.string().min(1),
942
+ var import_zod10 = require("zod");
943
+ var AgentStatusSchema = import_zod10.z.enum(["ACTIVE", "PENDING", "SUSPENDED", "REVOKED"]).or(import_zod10.z.string().min(1));
944
+ var AgentTypeSchema = import_zod10.z.enum(["CUSTOM", "CLAUDE", "GPT", "GEMINI", "CURSOR", "COPILOT", "OTHER"]).or(import_zod10.z.string().min(1));
945
+ var AgentListItemSchema = import_zod10.z.object({
946
+ id: import_zod10.z.string().min(1),
947
+ external_id: import_zod10.z.string().min(1),
948
+ name: import_zod10.z.string().min(1),
692
949
  status: AgentStatusSchema,
693
950
  agent_type: AgentTypeSchema,
694
- trust_score: import_zod8.z.number().int().min(0).max(1e3),
695
- hosting_model: import_zod8.z.null(),
696
- declared_tier: import_zod8.z.null(),
697
- created_at: import_zod8.z.string().datetime()
951
+ trust_score: import_zod10.z.number().int().min(0).max(1e3),
952
+ hosting_model: import_zod10.z.null(),
953
+ declared_tier: import_zod10.z.null(),
954
+ created_at: import_zod10.z.string().datetime()
698
955
  }).passthrough();
699
- var AgentsListResponseSchema = import_zod8.z.object({
700
- agents: import_zod8.z.array(AgentListItemSchema),
701
- _meta: import_zod8.z.object({
702
- source: import_zod8.z.literal("hlos")
956
+ var AgentsListResponseSchema = import_zod10.z.object({
957
+ agents: import_zod10.z.array(AgentListItemSchema),
958
+ _meta: import_zod10.z.object({
959
+ source: import_zod10.z.literal("hlos")
703
960
  })
704
961
  }).passthrough();
705
- var AgentPassportStubResponseSchema = import_zod8.z.object({
706
- passport_id: import_zod8.z.null(),
707
- agent_id: import_zod8.z.string().min(1),
708
- hosting_model: import_zod8.z.null(),
709
- declared_tier: import_zod8.z.null(),
710
- effective_tier: import_zod8.z.null(),
711
- finality_level: import_zod8.z.null(),
712
- graph: import_zod8.z.object({
713
- incoming_edges: import_zod8.z.null(),
714
- outgoing_edges: import_zod8.z.null(),
715
- active_visas: import_zod8.z.null()
962
+ var AgentPassportStubResponseSchema = import_zod10.z.object({
963
+ passport_id: import_zod10.z.null(),
964
+ agent_id: import_zod10.z.string().min(1),
965
+ hosting_model: import_zod10.z.null(),
966
+ declared_tier: import_zod10.z.null(),
967
+ effective_tier: import_zod10.z.null(),
968
+ finality_level: import_zod10.z.null(),
969
+ graph: import_zod10.z.object({
970
+ incoming_edges: import_zod10.z.null(),
971
+ outgoing_edges: import_zod10.z.null(),
972
+ active_visas: import_zod10.z.null()
716
973
  }).passthrough(),
717
- links: import_zod8.z.object({
718
- passport_url: import_zod8.z.string().startsWith("/agent-passport/agents/"),
719
- docs_url: import_zod8.z.literal("/agents/passport")
974
+ links: import_zod10.z.object({
975
+ passport_url: import_zod10.z.string().startsWith("/agent-passport/agents/"),
976
+ docs_url: import_zod10.z.literal("/agents/passport")
720
977
  }).passthrough(),
721
- _meta: import_zod8.z.object({
722
- source: import_zod8.z.literal("stub")
978
+ _meta: import_zod10.z.object({
979
+ source: import_zod10.z.literal("stub")
723
980
  })
724
981
  }).passthrough();
725
982
 
726
- // src/encoding.ts
727
- var import_zod9 = require("zod");
728
- function bytesToBase64url(bytes) {
729
- let binary = "";
730
- for (let i = 0; i < bytes.length; i++) {
731
- binary += String.fromCharCode(bytes[i]);
732
- }
733
- const base64 = btoa(binary);
734
- return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
735
- }
736
- function base64urlToBytes(str) {
737
- const base64 = str.replace(/-/g, "+").replace(/_/g, "/");
738
- const padded = base64 + "=".repeat((4 - base64.length % 4) % 4);
739
- const binary = atob(padded);
740
- const bytes = new Uint8Array(binary.length);
741
- for (let i = 0; i < binary.length; i++) {
742
- bytes[i] = binary.charCodeAt(i);
743
- }
744
- return bytes;
745
- }
746
- var BASE64URL_SHA256_REGEX = /^[A-Za-z0-9_-]{43}$/;
747
- var Base64urlSha256Schema = import_zod9.z.string().regex(
748
- BASE64URL_SHA256_REGEX,
749
- "Must be 43-char base64url (32-byte SHA-256 digest)"
983
+ // src/dispatch-chain.ts
984
+ var import_zod11 = require("zod");
985
+ var CHAIN_STAGE_ORDER = ["CR", "LAT", "EGP", "SA"];
986
+ var ChainStageTypeSchema = import_zod11.z.enum(CHAIN_STAGE_ORDER);
987
+ var ReceiptHashRefSchema = Base64urlSha256Schema.describe(
988
+ "receipt_hash: base64url(SHA-256(JCS(entire_receipt_envelope)))"
750
989
  );
751
- var Base64urlEd25519SigSchema = import_zod9.z.string().regex(
752
- /^[A-Za-z0-9_-]{86}$/,
753
- "Must be 86-char base64url (64-byte Ed25519 signature)"
990
+ var ContentHashRefSchema = Base64urlSha256Schema.describe(
991
+ "content_hash reference: base64url(SHA-256(JCS(content_field_only)))"
754
992
  );
755
-
756
- // src/receipt-hash.ts
757
- var import_meta = {};
758
- var cachedSha256 = null;
759
- function sortKeysDeep(value) {
760
- if (Array.isArray(value)) return value.map(sortKeysDeep);
761
- if (value !== null && typeof value === "object") {
762
- const obj = value;
763
- const out = {};
764
- for (const key of Object.keys(obj).sort()) {
765
- out[key] = sortKeysDeep(obj[key]);
766
- }
767
- return out;
993
+ var CustodyReceiptContentSchema = import_zod11.z.object({
994
+ type: import_zod11.z.literal("CustodyReceipt"),
995
+ stage_type: import_zod11.z.literal("CR"),
996
+ stage_version: import_zod11.z.literal(0),
997
+ stage_index: import_zod11.z.literal(0),
998
+ dispatch_id: DispatchIdSchema,
999
+ previous_receipt_hash: import_zod11.z.null(),
1000
+ // CR-specific
1001
+ actor_passport_id: import_zod11.z.string().min(1),
1002
+ surface: import_zod11.z.string().min(1),
1003
+ task_scope: import_zod11.z.string().min(1),
1004
+ settlement_authority: import_zod11.z.literal(SETTLEMENT_AUTHORITY)
1005
+ }).strict();
1006
+ var LiabilityAttestationContentSchema = import_zod11.z.object({
1007
+ type: import_zod11.z.literal("LiabilityAttestation"),
1008
+ stage_type: import_zod11.z.literal("LAT"),
1009
+ stage_version: import_zod11.z.literal(0),
1010
+ stage_index: import_zod11.z.literal(1),
1011
+ dispatch_id: DispatchIdSchema,
1012
+ previous_receipt_hash: ReceiptHashRefSchema,
1013
+ chain_root_content_hash: ContentHashRefSchema,
1014
+ // LAT-specific
1015
+ policy_snapshot_hash: Base64urlSha256Schema,
1016
+ capabilities_granted: import_zod11.z.array(import_zod11.z.string().min(1)).min(1),
1017
+ authorization_scope: import_zod11.z.string().min(1),
1018
+ /** Receipt issuer authority (HLOS issues all chain artifacts). */
1019
+ settlement_authority: import_zod11.z.literal(SETTLEMENT_AUTHORITY)
1020
+ }).strict();
1021
+ var EconomicGateProofContentSchema = import_zod11.z.object({
1022
+ type: import_zod11.z.literal("EconomicGateProof"),
1023
+ stage_type: import_zod11.z.literal("EGP"),
1024
+ stage_version: import_zod11.z.literal(0),
1025
+ stage_index: import_zod11.z.literal(2),
1026
+ dispatch_id: DispatchIdSchema,
1027
+ previous_receipt_hash: ReceiptHashRefSchema,
1028
+ chain_root_content_hash: ContentHashRefSchema,
1029
+ // EGP-specific
1030
+ wallet_id: import_zod11.z.string().min(1),
1031
+ hold_id: import_zod11.z.string().min(1).optional(),
1032
+ amount_mills: import_zod11.z.number().int().nonnegative(),
1033
+ currency: import_zod11.z.literal("USD"),
1034
+ settlement_authority: import_zod11.z.literal(SETTLEMENT_AUTHORITY)
1035
+ }).strict();
1036
+ var SettlementAnchorContentSchema = import_zod11.z.object({
1037
+ type: import_zod11.z.literal("SettlementAnchor"),
1038
+ stage_type: import_zod11.z.literal("SA"),
1039
+ stage_version: import_zod11.z.literal(0),
1040
+ stage_index: import_zod11.z.literal(3),
1041
+ dispatch_id: DispatchIdSchema,
1042
+ previous_receipt_hash: ReceiptHashRefSchema,
1043
+ chain_root_content_hash: ContentHashRefSchema,
1044
+ // SA-specific
1045
+ settlement_receipt_hash: ReceiptHashRefSchema,
1046
+ crossing_id: import_zod11.z.string().optional(),
1047
+ final_amount_mills: import_zod11.z.number().int().nonnegative(),
1048
+ settlement_authority: import_zod11.z.literal(SETTLEMENT_AUTHORITY)
1049
+ }).strict();
1050
+ var DispatchChainContentSchema = import_zod11.z.discriminatedUnion("type", [
1051
+ CustodyReceiptContentSchema,
1052
+ LiabilityAttestationContentSchema,
1053
+ EconomicGateProofContentSchema,
1054
+ SettlementAnchorContentSchema
1055
+ ]);
1056
+ function assertValidChainLink(expectedPreviousHash, actualPreviousHash, stageType) {
1057
+ if (expectedPreviousHash !== actualPreviousHash) {
1058
+ throw new Error(
1059
+ `Chain link broken at ${stageType}: expected previous_receipt_hash=${expectedPreviousHash}, got=${actualPreviousHash}`
1060
+ );
768
1061
  }
769
- return value;
770
1062
  }
771
- function jcsCanonicalize(value) {
772
- return JSON.stringify(sortKeysDeep(value), (_key, v) => {
773
- if (v === void 0) throw new Error("JCS: undefined is not allowed");
774
- if (typeof v === "function") throw new Error("JCS: function is not allowed");
775
- if (typeof v === "symbol") throw new Error("JCS: symbol is not allowed");
776
- if (typeof v === "bigint") throw new Error("JCS: bigint is not allowed");
777
- if (typeof v === "number" && !Number.isFinite(v))
778
- throw new Error("JCS: non-finite number is not allowed");
779
- return v;
780
- });
781
- }
782
- function computeReceiptHash(receipt) {
783
- const sha256 = loadSha256();
784
- const canonical = jcsCanonicalize(receipt);
785
- const digest = sha256(new TextEncoder().encode(canonical));
786
- return bytesToBase64url(digest);
787
- }
788
- function computeContentHash(content) {
789
- const sha256 = loadSha256();
790
- const canonical = jcsCanonicalize(content);
791
- const digest = sha256(new TextEncoder().encode(canonical));
792
- return bytesToBase64url(digest);
793
- }
794
- function loadSha256() {
795
- if (cachedSha256) return cachedSha256;
796
- let _require;
797
- try {
798
- const { createRequire } = require("module");
799
- _require = createRequire(import_meta.url);
800
- } catch {
801
- _require = require;
802
- }
803
- let sha256;
804
- try {
805
- sha256 = _require("@noble/hashes/sha2.js").sha256;
806
- } catch {
807
- try {
808
- sha256 = _require("@noble/hashes/sha2").sha256;
809
- } catch {
810
- throw new Error(
811
- "computeReceiptHash/computeContentHash requires @noble/hashes as a peer dependency. Install it: npm install @noble/hashes"
812
- );
813
- }
1063
+ function assertRootHash(actualRootHash, expectedRootHash, stageType) {
1064
+ if (actualRootHash !== expectedRootHash) {
1065
+ throw new Error(
1066
+ `Chain root mismatch at ${stageType}: expected chain_root_content_hash=${expectedRootHash}, got=${actualRootHash}`
1067
+ );
814
1068
  }
815
- cachedSha256 = sha256;
816
- return sha256;
817
1069
  }
818
- var ReceiptHashSchema = Base64urlSha256Schema.describe(
819
- "receipt_hash: base64url(SHA-256(JCS(receipt)))"
820
- );
821
- var RECEIPT_HASH_GOLDEN_FIXTURE = {
822
- receipt: {
823
- "@type": "https://hlos.ai/schema/SignedReceiptV0",
824
- version: 0,
825
- receipt_id: "rcpt_01HZGOLDENTEST000000000000",
826
- content: {
827
- type: "CrossingSettled",
828
- crossingId: "cross_test123abc456def789ghi",
829
- settlement_authority: "hlos.ai"
830
- },
831
- // Placeholder bytes (NOT a valid cryptographic signature)
832
- content_hash: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
833
- signature: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
834
- key_id: "hlos-v2-1",
835
- issued_at: "2026-01-27T00:00:00.000Z"
836
- },
837
- /**
838
- * Expected JCS canonical form of the receipt.
839
- * Keys are lexicographically sorted at all levels.
840
- */
841
- expectedJcs: '{"@type":"https://hlos.ai/schema/SignedReceiptV0","content":{"crossingId":"cross_test123abc456def789ghi","settlement_authority":"hlos.ai","type":"CrossingSettled"},"content_hash":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","issued_at":"2026-01-27T00:00:00.000Z","key_id":"hlos-v2-1","receipt_id":"rcpt_01HZGOLDENTEST000000000000","signature":"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","version":0}',
842
- /**
843
- * Expected receipt_hash (FROZEN).
844
- * Compute: JCS canonicalize receipt → SHA-256 → base64url (no padding)
845
- *
846
- * DO NOT CHANGE unless the receipt fixture above changes.
847
- */
848
- expectedReceiptHash: "uLiQVUeVKcE35Rdje2fArZQfTcECDgwK6UbmQB_36Pg"
849
- };
850
1070
 
851
1071
  // src/finality.ts
852
- var import_zod10 = require("zod");
1072
+ var import_zod12 = require("zod");
853
1073
  var NA_ID_PREFIX = "na_";
854
1074
  var FinalityLevel = {
855
1075
  SOFT: "SOFT",
856
1076
  HARD: "HARD"
857
1077
  };
858
- var NotaryAttestationIdFormatSchema = import_zod10.z.string().regex(
1078
+ var NotaryAttestationIdFormatSchema = import_zod12.z.string().regex(
859
1079
  /^na_[a-zA-Z0-9]{20,}$/,
860
1080
  "NA ID must match na_[a-zA-Z0-9]{20,}"
861
1081
  );
862
- var LogInclusionProofSchema = import_zod10.z.object({
1082
+ var LogInclusionProofSchema = import_zod12.z.object({
863
1083
  /** Merkle root hash (base64url SHA-256) */
864
1084
  root: Base64urlSha256Schema,
865
1085
  /** Sibling hashes along the path (base64url SHA-256 each) */
866
- proof: import_zod10.z.array(Base64urlSha256Schema),
1086
+ proof: import_zod12.z.array(Base64urlSha256Schema),
867
1087
  /** Leaf index in the log */
868
- index: import_zod10.z.number().int().nonnegative()
1088
+ index: import_zod12.z.number().int().nonnegative()
869
1089
  });
870
- var NotaryAttestationSchema = import_zod10.z.object({
1090
+ var NotaryAttestationSchema = import_zod12.z.object({
871
1091
  // --- Required ---
872
1092
  /** Unique NA identifier */
873
1093
  na_id: NotaryAttestationIdFormatSchema,
874
1094
  /** The receipt_hash this NA attests to */
875
1095
  receipt_hash: Base64urlSha256Schema,
876
1096
  /** Notary service identifier (e.g. "staampid") */
877
- notary_id: import_zod10.z.string().min(1),
1097
+ notary_id: import_zod12.z.string().min(1),
878
1098
  /** ISO 8601 timestamp when NA was issued */
879
- issued_at: import_zod10.z.string().datetime(),
1099
+ issued_at: import_zod12.z.string().datetime(),
880
1100
  /** Notary's countersignature (base64url encoded) */
881
- signature: import_zod10.z.string().min(1),
1101
+ signature: import_zod12.z.string().min(1),
882
1102
  /** Signature algorithm (e.g. "EdDSA") */
883
- signature_alg: import_zod10.z.string().min(1),
1103
+ signature_alg: import_zod12.z.string().min(1),
884
1104
  // --- Optional (future-proof) ---
885
1105
  /** Receipt type being attested */
886
- receipt_type: import_zod10.z.string().optional(),
1106
+ receipt_type: import_zod12.z.string().optional(),
887
1107
  /** Receipt version being attested */
888
- receipt_version: import_zod10.z.number().int().nonnegative().optional(),
1108
+ receipt_version: import_zod12.z.number().int().nonnegative().optional(),
889
1109
  /** Settlement authority that issued the receipt (cross-check) */
890
- settlement_authority: import_zod10.z.string().optional(),
1110
+ settlement_authority: import_zod12.z.string().optional(),
891
1111
  /** TTL in seconds for this attestation */
892
- validity_window_seconds: import_zod10.z.number().int().positive().optional(),
1112
+ validity_window_seconds: import_zod12.z.number().int().positive().optional(),
893
1113
  /** ISO 8601 expiry (derived from issued_at + validity_window_seconds) */
894
- expires_at: import_zod10.z.string().datetime().optional(),
1114
+ expires_at: import_zod12.z.string().datetime().optional(),
895
1115
  /** Merkle proof for append-only log inclusion */
896
1116
  log_inclusion: LogInclusionProofSchema.optional()
897
1117
  });
898
- var NotaryRequestSchema = import_zod10.z.object({
1118
+ var NotaryRequestSchema = import_zod12.z.object({
899
1119
  /** receipt_hash to be attested (base64url SHA-256) */
900
1120
  receipt_hash: Base64urlSha256Schema,
901
1121
  /** Must be literal 'hlos.ai' */
902
- settlement_authority: import_zod10.z.literal(SETTLEMENT_AUTHORITY),
1122
+ settlement_authority: import_zod12.z.literal(SETTLEMENT_AUTHORITY),
903
1123
  /** Crossing this receipt belongs to */
904
- crossing_id: import_zod10.z.string().min(1),
1124
+ crossing_id: import_zod12.z.string().min(1),
905
1125
  /** Type of the receipt being attested */
906
- receipt_type: import_zod10.z.string().min(1),
1126
+ receipt_type: import_zod12.z.string().min(1),
907
1127
  /** Version of the receipt being attested */
908
- receipt_version: import_zod10.z.number().int().nonnegative(),
1128
+ receipt_version: import_zod12.z.number().int().nonnegative(),
909
1129
  /** ISO 8601 timestamp of the request */
910
- timestamp: import_zod10.z.string().datetime(),
1130
+ timestamp: import_zod12.z.string().datetime(),
911
1131
  /** Optional: requested validity window in seconds */
912
- validity_window_seconds: import_zod10.z.number().int().positive().optional()
1132
+ validity_window_seconds: import_zod12.z.number().int().positive().optional()
913
1133
  });
914
- var NotarizeStatusSchema = import_zod10.z.enum([
1134
+ var NotarizeStatusSchema = import_zod12.z.enum([
915
1135
  "HARD",
916
1136
  // NA obtained, finality upgraded
917
1137
  "PENDING",
@@ -921,7 +1141,7 @@ var NotarizeStatusSchema = import_zod10.z.enum([
921
1141
  "ALREADY_HARD"
922
1142
  // Receipt already has NA
923
1143
  ]);
924
- var NotarizeResponseSchema = import_zod10.z.object({
1144
+ var NotarizeResponseSchema = import_zod12.z.object({
925
1145
  /** Finality status after this operation */
926
1146
  status: NotarizeStatusSchema,
927
1147
  /** The receipt_hash that was notarized */
@@ -931,13 +1151,13 @@ var NotarizeResponseSchema = import_zod10.z.object({
931
1151
  /** The full NA object (optional embed) */
932
1152
  na: NotaryAttestationSchema.optional(),
933
1153
  /** Notary service identifier */
934
- notary: import_zod10.z.string().min(1).optional(),
1154
+ notary: import_zod12.z.string().min(1).optional(),
935
1155
  /** NA ID for retrieval */
936
- notary_receipt_id: import_zod10.z.string().optional(),
1156
+ notary_receipt_id: import_zod12.z.string().optional(),
937
1157
  /** ISO 8601 timestamp */
938
- timestamp: import_zod10.z.string().datetime(),
1158
+ timestamp: import_zod12.z.string().datetime(),
939
1159
  /** Error details (present when status is FAILED) */
940
- error: import_zod10.z.string().optional()
1160
+ error: import_zod12.z.string().optional()
941
1161
  });
942
1162
  function isNotaryAttestation(value) {
943
1163
  return NotaryAttestationSchema.safeParse(value).success;
@@ -945,17 +1165,17 @@ function isNotaryAttestation(value) {
945
1165
  function isNotaryRequest(value) {
946
1166
  return NotaryRequestSchema.safeParse(value).success;
947
1167
  }
948
- var ArtifactRefSchema = import_zod10.z.object({
1168
+ var ArtifactRefSchema = import_zod12.z.object({
949
1169
  /** Artifact type */
950
- type: import_zod10.z.enum(["CR", "LAT", "EGP", "SA", "SignedReceiptV0", "NA"]),
1170
+ type: import_zod12.z.enum(["CR", "LAT", "EGP", "SA", "SignedReceiptV0", "NA"]),
951
1171
  /** base64url SHA-256 hash of the artifact */
952
1172
  hash: Base64urlSha256Schema,
953
1173
  /** Issuer of the artifact */
954
- issuer: import_zod10.z.string().min(1),
1174
+ issuer: import_zod12.z.string().min(1),
955
1175
  /** Schema version */
956
- version: import_zod10.z.string().min(1),
1176
+ version: import_zod12.z.string().min(1),
957
1177
  /** Optional retrieval URI */
958
- uri: import_zod10.z.string().url().optional()
1178
+ uri: import_zod12.z.string().url().optional()
959
1179
  });
960
1180
  var FINALITY_GOLDEN_FIXTURES = {
961
1181
  /** Sample NotaryAttestation */
@@ -989,8 +1209,569 @@ var FINALITY_GOLDEN_FIXTURES = {
989
1209
  timestamp: "2026-01-27T00:01:00.000Z"
990
1210
  }
991
1211
  };
1212
+
1213
+ // src/eval-artifact.ts
1214
+ var import_zod13 = require("zod");
1215
+ var ULID_REGEX = /^[0-9A-HJKMNP-TV-Z]{26}$/;
1216
+ var EvalTranscriptStageSchema = import_zod13.z.union([
1217
+ ChainStageTypeSchema,
1218
+ import_zod13.z.literal("HTTP")
1219
+ ]);
1220
+ var EvalTranscriptStepSchema = import_zod13.z.object({
1221
+ step_index: import_zod13.z.number().int().nonnegative(),
1222
+ stage: EvalTranscriptStageSchema,
1223
+ input_hash: Base64urlSha256Schema,
1224
+ output_hash: Base64urlSha256Schema.nullable(),
1225
+ verdict: import_zod13.z.enum(["pass", "fail", "skip"]),
1226
+ error: import_zod13.z.string().nullable(),
1227
+ elapsed_ms: import_zod13.z.number().int().nonnegative()
1228
+ }).strict();
1229
+ var EvalGraderResultSchema = import_zod13.z.object({
1230
+ grader_id: import_zod13.z.string().min(1),
1231
+ verdict: import_zod13.z.enum(["pass", "fail"]),
1232
+ confidence: import_zod13.z.number().min(0).max(1),
1233
+ details: import_zod13.z.string().nullable()
1234
+ }).strict();
1235
+ var EvalFailureSchema = import_zod13.z.object({
1236
+ step_index: import_zod13.z.number().int().nonnegative(),
1237
+ grader_id: import_zod13.z.string().min(1),
1238
+ code: import_zod13.z.string().min(1),
1239
+ message: import_zod13.z.string().nullable()
1240
+ }).strict();
1241
+ var EvalArtifactSchema = import_zod13.z.object({
1242
+ schema_version: import_zod13.z.literal(1),
1243
+ // Trial metadata
1244
+ trial_id: import_zod13.z.string().regex(ULID_REGEX, "Expected ULID format"),
1245
+ seed: import_zod13.z.string().nullable(),
1246
+ suite: import_zod13.z.string().min(1),
1247
+ environment: import_zod13.z.enum(["local", "ci", "staging", "production"]),
1248
+ started_at: import_zod13.z.string().datetime(),
1249
+ completed_at: import_zod13.z.string().datetime().nullable(),
1250
+ duration_ms: import_zod13.z.number().int().nonnegative().nullable(),
1251
+ // Transcript — ordered steps
1252
+ transcript: import_zod13.z.array(EvalTranscriptStepSchema),
1253
+ // Grader results
1254
+ grader_results: import_zod13.z.array(EvalGraderResultSchema),
1255
+ // Compact failure records
1256
+ failures: import_zod13.z.array(EvalFailureSchema),
1257
+ // Aggregate metrics
1258
+ pass_rate: import_zod13.z.number().min(0).max(1),
1259
+ consecutive_pass_rate: import_zod13.z.number().min(0).max(1),
1260
+ k: import_zod13.z.number().int().positive()
1261
+ }).strict();
1262
+ var DUMMY_HASH = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
1263
+ var EVAL_GOLDEN_FIXTURES = {
1264
+ /**
1265
+ * Valid 4-step transcript (CR→LAT→EGP→SA, all pass).
1266
+ */
1267
+ valid_full_pass: {
1268
+ schema_version: 1,
1269
+ trial_id: "01HZABCDEF1234567890ABCDEF",
1270
+ seed: "test-seed-001",
1271
+ suite: "kernel-invariant",
1272
+ environment: "ci",
1273
+ started_at: "2026-02-22T10:00:00.000Z",
1274
+ completed_at: "2026-02-22T10:00:01.234Z",
1275
+ duration_ms: 1234,
1276
+ transcript: [
1277
+ { step_index: 0, stage: "CR", input_hash: DUMMY_HASH, output_hash: DUMMY_HASH, verdict: "pass", error: null, elapsed_ms: 5 },
1278
+ { step_index: 1, stage: "LAT", input_hash: DUMMY_HASH, output_hash: DUMMY_HASH, verdict: "pass", error: null, elapsed_ms: 8 },
1279
+ { step_index: 2, stage: "EGP", input_hash: DUMMY_HASH, output_hash: DUMMY_HASH, verdict: "pass", error: null, elapsed_ms: 3 },
1280
+ { step_index: 3, stage: "SA", input_hash: DUMMY_HASH, output_hash: DUMMY_HASH, verdict: "pass", error: null, elapsed_ms: 12 }
1281
+ ],
1282
+ grader_results: [
1283
+ { grader_id: "cr_grader", verdict: "pass", confidence: 1, details: null },
1284
+ { grader_id: "lat_grader", verdict: "pass", confidence: 1, details: null },
1285
+ { grader_id: "egp_grader", verdict: "pass", confidence: 1, details: null },
1286
+ { grader_id: "sa_grader", verdict: "pass", confidence: 1, details: null }
1287
+ ],
1288
+ failures: [],
1289
+ pass_rate: 1,
1290
+ consecutive_pass_rate: 1,
1291
+ k: 10
1292
+ },
1293
+ /**
1294
+ * Single failure: LAT grader fails (broken CR→LAT binding).
1295
+ */
1296
+ lat_failure: {
1297
+ schema_version: 1,
1298
+ trial_id: "01HZABCDEF1234567890ABCDEG",
1299
+ seed: "test-seed-002",
1300
+ suite: "kernel-invariant",
1301
+ environment: "ci",
1302
+ started_at: "2026-02-22T10:01:00.000Z",
1303
+ completed_at: "2026-02-22T10:01:00.456Z",
1304
+ duration_ms: 456,
1305
+ transcript: [
1306
+ { step_index: 0, stage: "CR", input_hash: DUMMY_HASH, output_hash: DUMMY_HASH, verdict: "pass", error: null, elapsed_ms: 5 },
1307
+ { step_index: 1, stage: "LAT", input_hash: DUMMY_HASH, output_hash: null, verdict: "fail", error: "CR hash mismatch", elapsed_ms: 3 },
1308
+ { step_index: 2, stage: "EGP", input_hash: DUMMY_HASH, output_hash: null, verdict: "skip", error: null, elapsed_ms: 0 },
1309
+ { step_index: 3, stage: "SA", input_hash: DUMMY_HASH, output_hash: null, verdict: "skip", error: null, elapsed_ms: 0 }
1310
+ ],
1311
+ grader_results: [
1312
+ { grader_id: "cr_grader", verdict: "pass", confidence: 1, details: null },
1313
+ { grader_id: "lat_grader", verdict: "fail", confidence: 1, details: "LAT.cr_hash does not match computed CR hash" },
1314
+ { grader_id: "egp_grader", verdict: "pass", confidence: 0, details: "Skipped: LAT failed" },
1315
+ { grader_id: "sa_grader", verdict: "pass", confidence: 0, details: "Skipped: upstream failure" }
1316
+ ],
1317
+ failures: [
1318
+ { step_index: 1, grader_id: "lat_grader", code: "BINDING_MISMATCH", message: "LAT.cr_hash does not match computed CR hash" }
1319
+ ],
1320
+ pass_rate: 0.9,
1321
+ consecutive_pass_rate: 0.9,
1322
+ k: 10
1323
+ },
1324
+ /**
1325
+ * Partial artifact: run crashed mid-flight.
1326
+ */
1327
+ partial_crash: {
1328
+ schema_version: 1,
1329
+ trial_id: "01HZABCDEF1234567890ABCDEH",
1330
+ seed: null,
1331
+ suite: "kernel-invariant",
1332
+ environment: "local",
1333
+ started_at: "2026-02-22T10:02:00.000Z",
1334
+ completed_at: null,
1335
+ duration_ms: null,
1336
+ transcript: [
1337
+ { step_index: 0, stage: "CR", input_hash: DUMMY_HASH, output_hash: DUMMY_HASH, verdict: "pass", error: null, elapsed_ms: 5 }
1338
+ ],
1339
+ grader_results: [
1340
+ { grader_id: "cr_grader", verdict: "pass", confidence: 1, details: null }
1341
+ ],
1342
+ failures: [],
1343
+ pass_rate: 0,
1344
+ consecutive_pass_rate: 0,
1345
+ k: 10
1346
+ }
1347
+ };
1348
+
1349
+ // src/settlement-execute.ts
1350
+ var import_zod14 = require("zod");
1351
+ var ULID_REGEX2 = /^[0-9A-HJKMNP-TV-Z]{26}$/;
1352
+ var UlidSchema = import_zod14.z.string().regex(ULID_REGEX2, "Expected ULID format");
1353
+ var UlidOrUuidSchema = import_zod14.z.string().min(1);
1354
+ var HashVersionSchema = import_zod14.z.enum(["v1", "v2"]);
1355
+ var SettlementModeSchema = import_zod14.z.enum(["execute", "dry_run"]);
1356
+ var NotaryStatusSchema = import_zod14.z.enum(["skipped", "verified", "failed"]);
1357
+ var SettlementExecuteRequestSchema = import_zod14.z.object({
1358
+ idempotency_key: UlidOrUuidSchema,
1359
+ seed: import_zod14.z.string().nullable().optional(),
1360
+ hash_version: HashVersionSchema.default("v2"),
1361
+ mode: SettlementModeSchema.default("execute"),
1362
+ flow: import_zod14.z.object({
1363
+ wallet_id: import_zod14.z.string().min(1),
1364
+ sku: import_zod14.z.string().min(1),
1365
+ amount: import_zod14.z.string().min(1),
1366
+ currency: import_zod14.z.literal("USD"),
1367
+ metadata: import_zod14.z.record(import_zod14.z.unknown()).optional()
1368
+ })
1369
+ }).strict();
1370
+ var ArtifactsBlockSchema = import_zod14.z.object({
1371
+ cr: import_zod14.z.record(import_zod14.z.unknown()).nullable(),
1372
+ lat: import_zod14.z.record(import_zod14.z.unknown()).nullable(),
1373
+ egp: import_zod14.z.record(import_zod14.z.unknown()).nullable(),
1374
+ sa: import_zod14.z.record(import_zod14.z.unknown()).nullable()
1375
+ });
1376
+ var HashesBlockSchema = import_zod14.z.object({
1377
+ cr_hash: Base64urlSha256Schema.nullable(),
1378
+ lat_hash: Base64urlSha256Schema.nullable(),
1379
+ egp_hash: Base64urlSha256Schema.nullable(),
1380
+ sa_hash: Base64urlSha256Schema.nullable()
1381
+ });
1382
+ var SignatureEnvelopeSchema = import_zod14.z.object({
1383
+ alg: import_zod14.z.literal("ed25519"),
1384
+ sig: import_zod14.z.string().min(1),
1385
+ pub: import_zod14.z.string().min(1)
1386
+ });
1387
+ var NotaryBlockSchema = import_zod14.z.object({
1388
+ status: NotaryStatusSchema,
1389
+ run_notary: import_zod14.z.object({
1390
+ subject_hash: Base64urlSha256Schema,
1391
+ sig: import_zod14.z.string().min(1),
1392
+ pub: import_zod14.z.string().min(1)
1393
+ }).nullable(),
1394
+ graph_notary: import_zod14.z.object({
1395
+ subject_hash: Base64urlSha256Schema,
1396
+ sig: import_zod14.z.string().min(1),
1397
+ pub: import_zod14.z.string().min(1)
1398
+ }).nullable()
1399
+ });
1400
+ var TimingBlockSchema = import_zod14.z.object({
1401
+ started_at: import_zod14.z.string().datetime(),
1402
+ completed_at: import_zod14.z.string().datetime().nullable(),
1403
+ duration_ms: import_zod14.z.number().int().nonnegative().nullable()
1404
+ });
1405
+ var SettlementExecuteSuccessSchema = import_zod14.z.object({
1406
+ schema_version: import_zod14.z.literal(1),
1407
+ flow_id: UlidSchema,
1408
+ suite_id: import_zod14.z.string().min(1),
1409
+ seed: import_zod14.z.string().nullable(),
1410
+ hash_version: HashVersionSchema,
1411
+ artifacts: ArtifactsBlockSchema.extend({
1412
+ cr: import_zod14.z.record(import_zod14.z.unknown()),
1413
+ lat: import_zod14.z.record(import_zod14.z.unknown()),
1414
+ egp: import_zod14.z.record(import_zod14.z.unknown()),
1415
+ sa: import_zod14.z.record(import_zod14.z.unknown())
1416
+ }),
1417
+ hashes: HashesBlockSchema.extend({
1418
+ cr_hash: Base64urlSha256Schema,
1419
+ lat_hash: Base64urlSha256Schema,
1420
+ egp_hash: Base64urlSha256Schema,
1421
+ sa_hash: Base64urlSha256Schema
1422
+ }),
1423
+ signatures: import_zod14.z.object({
1424
+ settlement: import_zod14.z.object({
1425
+ cr_sig: SignatureEnvelopeSchema,
1426
+ lat_sig: SignatureEnvelopeSchema,
1427
+ sa_sig: SignatureEnvelopeSchema
1428
+ }),
1429
+ notary: NotaryBlockSchema
1430
+ }),
1431
+ receipt: import_zod14.z.object({
1432
+ // Kernel receipt IDs currently follow rcpt_ + variable base36/random suffix.
1433
+ receipt_id: import_zod14.z.string().regex(/^rcpt_/, "Expected kernel receipt ID (rcpt_... format)"),
1434
+ status: import_zod14.z.enum(["stored", "pending"]),
1435
+ receipt_hash: Base64urlSha256Schema
1436
+ }),
1437
+ run: import_zod14.z.object({
1438
+ run_id: UlidSchema,
1439
+ final_state_hash: Base64urlSha256Schema,
1440
+ terminal_event_hash: Base64urlSha256Schema,
1441
+ sealed_at: import_zod14.z.string().datetime()
1442
+ }),
1443
+ timing: TimingBlockSchema.extend({
1444
+ completed_at: import_zod14.z.string().datetime(),
1445
+ duration_ms: import_zod14.z.number().int().nonnegative()
1446
+ })
1447
+ });
1448
+ var SettlementErrorCodeSchema = import_zod14.z.enum([
1449
+ "INSUFFICIENT_FUNDS",
1450
+ "POLICY_DENIED",
1451
+ "INVARIANT_FAILED",
1452
+ "INVALID_AMOUNT_FORMAT",
1453
+ "INVALID_AMOUNT_NEGATIVE",
1454
+ "INVALID_JSON",
1455
+ "INTERNAL"
1456
+ ]);
1457
+ var SettlementExecuteErrorSchema = import_zod14.z.object({
1458
+ schema_version: import_zod14.z.literal(1),
1459
+ flow_id: UlidSchema,
1460
+ suite_id: import_zod14.z.string().min(1),
1461
+ seed: import_zod14.z.string().nullable(),
1462
+ hash_version: HashVersionSchema,
1463
+ error: import_zod14.z.object({
1464
+ code: SettlementErrorCodeSchema,
1465
+ message: import_zod14.z.string(),
1466
+ details: import_zod14.z.record(import_zod14.z.unknown()).optional()
1467
+ }),
1468
+ partial: import_zod14.z.object({
1469
+ artifacts: ArtifactsBlockSchema,
1470
+ hashes: HashesBlockSchema
1471
+ }),
1472
+ timing: TimingBlockSchema
1473
+ });
1474
+ var SettlementExecuteResponseSchema = import_zod14.z.union([
1475
+ SettlementExecuteSuccessSchema,
1476
+ SettlementExecuteErrorSchema
1477
+ ]);
1478
+ function isSettlementExecuteSuccess(response) {
1479
+ return "artifacts" in response && !("error" in response);
1480
+ }
1481
+ function isSettlementExecuteError(response) {
1482
+ return "error" in response;
1483
+ }
1484
+
1485
+ // src/srr-v0.ts
1486
+ var import_zod15 = require("zod");
1487
+ var SRR_TYPE_URI = "https://hlos.ai/schema/SignedRejectionReceiptV0";
1488
+ var SRR_VERSION = 0;
1489
+ var SRR_REJECTION_DOMAIN = "kernel:k:rejection:v1";
1490
+ var SRR_SIGNATURE_ALGORITHM = "Ed25519";
1491
+ var SRR_INITIAL_REASON_CODES = [
1492
+ "BUDGET_EXCEEDED",
1493
+ "POLICY_VIOLATION",
1494
+ "SAFETY_GATE_FAILED",
1495
+ "DELEGATION_REVOKED",
1496
+ "SETTLEMENT_TIMEOUT"
1497
+ ];
1498
+ var REASON_CODE_PATTERN = /^[A-Z][A-Z0-9_]{2,63}$/;
1499
+ var SignedRejectionReceiptV0Schema = import_zod15.z.object({
1500
+ "@type": import_zod15.z.literal(SRR_TYPE_URI),
1501
+ version: import_zod15.z.literal(SRR_VERSION),
1502
+ receipt_id: import_zod15.z.string().regex(
1503
+ /^srr_[0-9A-HJKMNP-TV-Z]{26}$/i,
1504
+ "receipt_id must be srr_ + 26-char ULID"
1505
+ ),
1506
+ crossing_id: import_zod15.z.string().min(1),
1507
+ reason_code: import_zod15.z.string().regex(REASON_CODE_PATTERN, "reason_code must be UPPER_SNAKE_CASE, 3-64 chars"),
1508
+ reason_message: import_zod15.z.string().min(1),
1509
+ details: import_zod15.z.record(import_zod15.z.unknown()).optional(),
1510
+ commitment_hash: Base64urlSha256Schema.optional(),
1511
+ issuer_id: import_zod15.z.string().min(1),
1512
+ rejected_at: import_zod15.z.string().datetime(),
1513
+ issuer_public_key_ref: import_zod15.z.string().min(1),
1514
+ signature_algorithm: import_zod15.z.literal(SRR_SIGNATURE_ALGORITHM),
1515
+ signature: Base64urlEd25519SigSchema
1516
+ }).strict();
1517
+
1518
+ // src/liability-waiver-terms-v0.ts
1519
+ var import_zod16 = require("zod");
1520
+ var LIABILITY_WAIVER_TERMS_TYPE_URI = "https://hlos.ai/schema/LiabilityWaiverTermsV0";
1521
+ var LIABILITY_WAIVER_TERMS_VERSION = 0;
1522
+ var LiabilityDispositionSchema = import_zod16.z.enum([
1523
+ "ABSORB",
1524
+ "RELEASE",
1525
+ "TRANSFER",
1526
+ "DISPUTE"
1527
+ ]);
1528
+ var LiabilityWaiverTermsPartiesSchema = import_zod16.z.object({
1529
+ offered_by: import_zod16.z.string().min(1).optional(),
1530
+ offered_to: import_zod16.z.string().min(1).optional(),
1531
+ beneficiary: import_zod16.z.string().min(1).optional(),
1532
+ burdened_party: import_zod16.z.string().min(1).optional()
1533
+ }).strict();
1534
+ var LiabilityWaiverTermsScopeSchema = import_zod16.z.object({
1535
+ crossing_id: import_zod16.z.string().min(1).optional(),
1536
+ commitment_hash: Base64urlSha256Schema.optional(),
1537
+ claim_scope: import_zod16.z.string().min(1).optional()
1538
+ }).strict();
1539
+ var LiabilityWaiverTermsConditionsSchema = import_zod16.z.object({
1540
+ effective_if: import_zod16.z.record(import_zod16.z.unknown()).optional(),
1541
+ expires_at: import_zod16.z.string().datetime().optional(),
1542
+ jurisdiction: import_zod16.z.string().min(1).optional()
1543
+ }).strict();
1544
+ var LiabilityWaiverTermsHashInputSchema = import_zod16.z.object({
1545
+ parties: LiabilityWaiverTermsPartiesSchema,
1546
+ liability_effect: LiabilityDispositionSchema,
1547
+ scope: LiabilityWaiverTermsScopeSchema,
1548
+ conditions: LiabilityWaiverTermsConditionsSchema.optional(),
1549
+ canonical_terms: import_zod16.z.record(import_zod16.z.unknown()).optional()
1550
+ }).strict();
1551
+ var LiabilityWaiverTermsRefV0Schema = import_zod16.z.object({
1552
+ waiver_id: import_zod16.z.string().min(1).optional(),
1553
+ terms_hash: Base64urlSha256Schema,
1554
+ type: import_zod16.z.literal(LIABILITY_WAIVER_TERMS_TYPE_URI),
1555
+ version: import_zod16.z.literal(LIABILITY_WAIVER_TERMS_VERSION)
1556
+ }).strict();
1557
+ var LiabilityWaiverTermsV0Schema = import_zod16.z.object({
1558
+ "@type": import_zod16.z.literal(LIABILITY_WAIVER_TERMS_TYPE_URI),
1559
+ version: import_zod16.z.literal(LIABILITY_WAIVER_TERMS_VERSION),
1560
+ waiver_id: import_zod16.z.string().min(1),
1561
+ terms_hash: Base64urlSha256Schema,
1562
+ parties: LiabilityWaiverTermsPartiesSchema,
1563
+ liability_effect: LiabilityDispositionSchema,
1564
+ scope: LiabilityWaiverTermsScopeSchema,
1565
+ conditions: LiabilityWaiverTermsConditionsSchema.optional(),
1566
+ human_readable_summary: import_zod16.z.string().min(1).optional(),
1567
+ canonical_terms: import_zod16.z.record(import_zod16.z.unknown()).optional()
1568
+ }).strict();
1569
+ var cachedSha2562 = null;
1570
+ function loadSha2562() {
1571
+ if (cachedSha2562) return cachedSha2562;
1572
+ const moduleApi = typeof process.getBuiltinModule === "function" ? process.getBuiltinModule("module") : require("module");
1573
+ const createRequire = moduleApi.createRequire;
1574
+ const requireBase = typeof __filename === "string" ? __filename : `${process.cwd()}/package.json`;
1575
+ const _require = createRequire(requireBase);
1576
+ let sha256;
1577
+ try {
1578
+ sha256 = _require("@noble/hashes/sha2.js").sha256;
1579
+ } catch {
1580
+ try {
1581
+ sha256 = _require("@noble/hashes/sha2").sha256;
1582
+ } catch {
1583
+ throw new Error(
1584
+ "Liability waiver hashing requires @noble/hashes as a peer dependency. Install it: npm install @noble/hashes"
1585
+ );
1586
+ }
1587
+ }
1588
+ cachedSha2562 = sha256;
1589
+ return sha256;
1590
+ }
1591
+ function toLiabilityWaiverTermsHashInput(terms) {
1592
+ return {
1593
+ parties: terms.parties,
1594
+ liability_effect: terms.liability_effect,
1595
+ scope: terms.scope,
1596
+ ...terms.conditions !== void 0 ? { conditions: terms.conditions } : {},
1597
+ ...terms.canonical_terms !== void 0 ? { canonical_terms: terms.canonical_terms } : {}
1598
+ };
1599
+ }
1600
+ function computeLiabilityWaiverTermsHash(input) {
1601
+ const sha256 = loadSha2562();
1602
+ const canonical = jcsCanonicalize(input);
1603
+ const digest = sha256(new TextEncoder().encode(canonical));
1604
+ return bytesToBase64url(digest);
1605
+ }
1606
+
1607
+ // src/srr-v1.ts
1608
+ var import_zod17 = require("zod");
1609
+ var SRR_V1_TYPE_URI = "https://hlos.ai/schema/SignedRejectionReceiptV1";
1610
+ var SRR_V1_VERSION = 1;
1611
+ var SRR_V1_REJECTION_DOMAIN = "kernel:u:rejection:v1";
1612
+ var SRR_V1_SIGNATURE_ALGORITHM = SRR_SIGNATURE_ALGORITHM;
1613
+ var SignedRejectionReceiptV1Schema = import_zod17.z.object({
1614
+ "@type": import_zod17.z.literal(SRR_V1_TYPE_URI),
1615
+ version: import_zod17.z.literal(SRR_V1_VERSION),
1616
+ receipt_id: import_zod17.z.string().regex(
1617
+ /^srr_[0-9A-HJKMNP-TV-Z]{26}$/i,
1618
+ "receipt_id must be srr_ + 26-char ULID"
1619
+ ),
1620
+ crossing_id: import_zod17.z.string().min(1),
1621
+ reason_code: import_zod17.z.string().regex(REASON_CODE_PATTERN, "reason_code must be UPPER_SNAKE_CASE, 3-64 chars"),
1622
+ reason_message: import_zod17.z.string().min(1),
1623
+ details: import_zod17.z.record(import_zod17.z.unknown()).optional(),
1624
+ commitment_hash: Base64urlSha256Schema.optional(),
1625
+ issuer_id: import_zod17.z.string().min(1),
1626
+ rejected_at: import_zod17.z.string().datetime(),
1627
+ issuer_public_key_ref: import_zod17.z.string().min(1),
1628
+ signature_algorithm: import_zod17.z.literal(SRR_V1_SIGNATURE_ALGORITHM),
1629
+ liability_disposition: LiabilityDispositionSchema,
1630
+ waiver_terms_ref: LiabilityWaiverTermsRefV0Schema.optional(),
1631
+ signature: Base64urlEd25519SigSchema
1632
+ }).strict().superRefine((value, ctx) => {
1633
+ if ((value.liability_disposition === "RELEASE" || value.liability_disposition === "TRANSFER") && value.waiver_terms_ref === void 0) {
1634
+ ctx.addIssue({
1635
+ code: import_zod17.z.ZodIssueCode.custom,
1636
+ path: ["waiver_terms_ref"],
1637
+ message: "waiver_terms_ref is required for RELEASE and TRANSFER"
1638
+ });
1639
+ }
1640
+ });
1641
+
1642
+ // src/srr-signing.ts
1643
+ var textEncoder = new TextEncoder();
1644
+ var DOMAIN_BYTES_V0 = textEncoder.encode(SRR_REJECTION_DOMAIN);
1645
+ var DOMAIN_BYTES_V1 = textEncoder.encode(SRR_V1_REJECTION_DOMAIN);
1646
+ var cachedSha2563 = null;
1647
+ function loadSha2563() {
1648
+ if (cachedSha2563) return cachedSha2563;
1649
+ const moduleApi = typeof process.getBuiltinModule === "function" ? process.getBuiltinModule("module") : require("module");
1650
+ const createRequire = moduleApi.createRequire;
1651
+ const requireBase = typeof __filename === "string" ? __filename : `${process.cwd()}/package.json`;
1652
+ const _require = createRequire(requireBase);
1653
+ let sha256;
1654
+ try {
1655
+ sha256 = _require("@noble/hashes/sha2.js").sha256;
1656
+ } catch {
1657
+ try {
1658
+ sha256 = _require("@noble/hashes/sha2").sha256;
1659
+ } catch {
1660
+ throw new Error(
1661
+ "SRR signing requires @noble/hashes as a peer dependency. Install it: npm install @noble/hashes"
1662
+ );
1663
+ }
1664
+ }
1665
+ cachedSha2563 = sha256;
1666
+ return sha256;
1667
+ }
1668
+ function computeSrrSigningPayload(unsignedSrr) {
1669
+ const sha256 = loadSha2563();
1670
+ const canonical = jcsCanonicalize(unsignedSrr);
1671
+ const digest = sha256(textEncoder.encode(canonical));
1672
+ const domainBytes = unsignedSrr["@type"] === SRR_V1_TYPE_URI ? DOMAIN_BYTES_V1 : unsignedSrr["@type"] === SRR_TYPE_URI ? DOMAIN_BYTES_V0 : (() => {
1673
+ throw new Error("Unsupported SRR type for signing payload construction");
1674
+ })();
1675
+ const payload = new Uint8Array(domainBytes.length + digest.length);
1676
+ payload.set(domainBytes, 0);
1677
+ payload.set(digest, domainBytes.length);
1678
+ return payload;
1679
+ }
1680
+ function computeSrrDigest(signedSrr) {
1681
+ const sha256 = loadSha2563();
1682
+ const canonical = jcsCanonicalize(signedSrr);
1683
+ return bytesToBase64url(sha256(textEncoder.encode(canonical)));
1684
+ }
1685
+
1686
+ // src/srr-verify.ts
1687
+ var cachedVerify = null;
1688
+ function loadVerify() {
1689
+ if (cachedVerify) return cachedVerify;
1690
+ const moduleApi = typeof process.getBuiltinModule === "function" ? process.getBuiltinModule("module") : require("module");
1691
+ const createRequire = moduleApi.createRequire;
1692
+ const requireBase = typeof __filename === "string" ? __filename : `${process.cwd()}/package.json`;
1693
+ const _require = createRequire(requireBase);
1694
+ let ed25519Module;
1695
+ try {
1696
+ ed25519Module = _require("@noble/ed25519");
1697
+ } catch {
1698
+ throw new Error(
1699
+ "SRR verification requires @noble/ed25519 as a peer dependency. Install it: npm install @noble/ed25519"
1700
+ );
1701
+ }
1702
+ if (!ed25519Module.hashes?.sha512) {
1703
+ let sha512Fn;
1704
+ try {
1705
+ const sha2 = _require("@noble/hashes/sha2.js");
1706
+ sha512Fn = (...m) => sha2.sha512(ed25519Module.etc.concatBytes(...m));
1707
+ } catch {
1708
+ try {
1709
+ const sha2 = _require("@noble/hashes/sha2");
1710
+ sha512Fn = (...m) => sha2.sha512(ed25519Module.etc.concatBytes(...m));
1711
+ } catch {
1712
+ throw new Error(
1713
+ "SRR verification requires @noble/hashes as a peer dependency. Install it: npm install @noble/hashes"
1714
+ );
1715
+ }
1716
+ }
1717
+ if (!ed25519Module.hashes) ed25519Module.hashes = {};
1718
+ ed25519Module.hashes.sha512 = sha512Fn;
1719
+ }
1720
+ const verify = ed25519Module.verify;
1721
+ cachedVerify = verify;
1722
+ return verify;
1723
+ }
1724
+ async function verifyDetachedEd25519(params) {
1725
+ const verify = loadVerify();
1726
+ try {
1727
+ return await verify(params.signature, params.signingPayload, params.publicKey);
1728
+ } catch {
1729
+ return false;
1730
+ }
1731
+ }
1732
+ async function verifySignedRejectionReceipt(params) {
1733
+ const { srr, publicKey } = params;
1734
+ if (!srr || typeof srr !== "object") {
1735
+ return { valid: false, reason: "SCHEMA_VIOLATION" };
1736
+ }
1737
+ if (typeof srr.signature_algorithm === "string" && srr.signature_algorithm !== SRR_SIGNATURE_ALGORITHM) {
1738
+ return { valid: false, reason: "UNSUPPORTED_ALGORITHM" };
1739
+ }
1740
+ const wireType = srr["@type"];
1741
+ if (wireType !== SRR_V1_TYPE_URI && wireType !== SRR_TYPE_URI) {
1742
+ return { valid: false, reason: "SCHEMA_VIOLATION" };
1743
+ }
1744
+ const parseResult = wireType === SRR_V1_TYPE_URI ? SignedRejectionReceiptV1Schema.safeParse(srr) : SignedRejectionReceiptV0Schema.safeParse(srr);
1745
+ if (!parseResult.success) {
1746
+ return { valid: false, reason: "SCHEMA_VIOLATION" };
1747
+ }
1748
+ const parsedSrr = parseResult.data;
1749
+ let signingPayload;
1750
+ try {
1751
+ const { signature, ...unsignedFields } = parsedSrr;
1752
+ signingPayload = computeSrrSigningPayload(unsignedFields);
1753
+ } catch {
1754
+ return { valid: false, reason: "PAYLOAD_CONSTRUCTION_ERROR" };
1755
+ }
1756
+ let signatureBytes;
1757
+ try {
1758
+ signatureBytes = base64urlToBytes(parsedSrr.signature);
1759
+ } catch {
1760
+ return { valid: false, reason: "INVALID_SIGNATURE" };
1761
+ }
1762
+ const valid = await verifyDetachedEd25519({
1763
+ signingPayload,
1764
+ signature: signatureBytes,
1765
+ publicKey
1766
+ });
1767
+ return valid ? { valid: true } : { valid: false, reason: "INVALID_SIGNATURE" };
1768
+ }
992
1769
  // Annotate the CommonJS export names for ESM import in node:
993
1770
  0 && (module.exports = {
1771
+ AAREnvelopeV0Schema,
1772
+ AAREnvelopeV0TypedSchema,
1773
+ AAR_ENVELOPE_TYPE,
1774
+ AAR_ENVELOPE_VERSION,
994
1775
  AgentListItemSchema,
995
1776
  AgentPassportStubResponseSchema,
996
1777
  AgentStatusSchema,
@@ -1001,7 +1782,9 @@ var FINALITY_GOLDEN_FIXTURES = {
1001
1782
  BASE64URL_SHA256_REGEX,
1002
1783
  Base64urlEd25519SigSchema,
1003
1784
  Base64urlSha256Schema,
1785
+ CHAIN_STAGE_ORDER,
1004
1786
  CONTENT_HASH_LENGTH,
1787
+ ChainStageTypeSchema,
1005
1788
  CorrelationIdSchema,
1006
1789
  CredentialSourceSchema,
1007
1790
  CrossingHashInputV0Schema,
@@ -1009,8 +1792,18 @@ var FINALITY_GOLDEN_FIXTURES = {
1009
1792
  CrossingIdSchema,
1010
1793
  CrossingSettledReceiptSchema,
1011
1794
  CrossingSnapshotV0Schema,
1795
+ CustodyReceiptContentSchema,
1796
+ DispatchChainContentSchema,
1797
+ DispatchIdBrand,
1798
+ DispatchIdSchema,
1012
1799
  ERROR_CODE_STATUS,
1800
+ EVAL_GOLDEN_FIXTURES,
1801
+ EconomicGateProofContentSchema,
1013
1802
  ErrorResponseSchema,
1803
+ EvalArtifactSchema,
1804
+ EvalFailureSchema,
1805
+ EvalGraderResultSchema,
1806
+ EvalTranscriptStepSchema,
1014
1807
  FINALITY_GOLDEN_FIXTURES,
1015
1808
  FinalityLevel,
1016
1809
  FundingSourceSchema,
@@ -1019,6 +1812,16 @@ var FINALITY_GOLDEN_FIXTURES = {
1019
1812
  KernelErrorCodeSchema,
1020
1813
  KernelErrorSchema,
1021
1814
  KernelOkSchema,
1815
+ LIABILITY_WAIVER_TERMS_TYPE_URI,
1816
+ LIABILITY_WAIVER_TERMS_VERSION,
1817
+ LiabilityAttestationContentSchema,
1818
+ LiabilityDispositionSchema,
1819
+ LiabilityWaiverTermsConditionsSchema,
1820
+ LiabilityWaiverTermsHashInputSchema,
1821
+ LiabilityWaiverTermsPartiesSchema,
1822
+ LiabilityWaiverTermsRefV0Schema,
1823
+ LiabilityWaiverTermsScopeSchema,
1824
+ LiabilityWaiverTermsV0Schema,
1022
1825
  LogInclusionProofSchema,
1023
1826
  NA_ID_PREFIX,
1024
1827
  NotarizeResponseSchema,
@@ -1029,6 +1832,7 @@ var FINALITY_GOLDEN_FIXTURES = {
1029
1832
  PassportIdFormatSchema,
1030
1833
  PassportIdSchema,
1031
1834
  ProviderRoleSchema,
1835
+ REASON_CODE_PATTERN,
1032
1836
  RECEIPT_HASH_GOLDEN_FIXTURE,
1033
1837
  RECEIPT_TYPE_URI,
1034
1838
  RECEIPT_VERSION,
@@ -1040,9 +1844,25 @@ var FINALITY_GOLDEN_FIXTURES = {
1040
1844
  RotationEpochSchema,
1041
1845
  SETTLEMENT_AUTHORITY,
1042
1846
  SIGNATURE_LENGTH,
1847
+ SRR_INITIAL_REASON_CODES,
1848
+ SRR_REJECTION_DOMAIN,
1849
+ SRR_SIGNATURE_ALGORITHM,
1850
+ SRR_TYPE_URI,
1851
+ SRR_V1_REJECTION_DOMAIN,
1852
+ SRR_V1_SIGNATURE_ALGORITHM,
1853
+ SRR_V1_TYPE_URI,
1854
+ SRR_V1_VERSION,
1855
+ SRR_VERSION,
1043
1856
  SURFACES,
1857
+ SettlementAnchorContentSchema,
1858
+ SettlementExecuteErrorSchema,
1859
+ SettlementExecuteRequestSchema,
1860
+ SettlementExecuteResponseSchema,
1861
+ SettlementExecuteSuccessSchema,
1044
1862
  SignedReceiptV0LooseSchema,
1045
1863
  SignedReceiptV0Schema,
1864
+ SignedRejectionReceiptV0Schema,
1865
+ SignedRejectionReceiptV1Schema,
1046
1866
  StackConnectionSchema,
1047
1867
  StackProviderSchema,
1048
1868
  StackSchema,
@@ -1055,14 +1875,20 @@ var FINALITY_GOLDEN_FIXTURES = {
1055
1875
  W_TXCTX_DOMAIN,
1056
1876
  WalletIdFormatSchema,
1057
1877
  WalletIdSchema,
1878
+ assertRootHash,
1879
+ assertValidChainLink,
1058
1880
  base64urlToBytes,
1059
1881
  bytesToBase64url,
1060
1882
  computeContentHash,
1883
+ computeLiabilityWaiverTermsHash,
1061
1884
  computeReceiptHash,
1885
+ computeSrrDigest,
1886
+ computeSrrSigningPayload,
1062
1887
  deriveFundingSource,
1063
1888
  encodeEpoch,
1064
1889
  error,
1065
1890
  generateCrossingId,
1891
+ generateDispatchId,
1066
1892
  generateId,
1067
1893
  generatePassportId,
1068
1894
  generateReceiptId,
@@ -1071,11 +1897,17 @@ var FINALITY_GOLDEN_FIXTURES = {
1071
1897
  isCrossingSettledReceipt,
1072
1898
  isNotaryAttestation,
1073
1899
  isNotaryRequest,
1900
+ isSettlementExecuteError,
1901
+ isSettlementExecuteSuccess,
1074
1902
  isSignedReceiptV0,
1075
1903
  jcsCanonicalize,
1076
1904
  kernelError,
1077
1905
  kernelOk,
1078
1906
  success,
1079
- validateTimeWindow
1907
+ toLiabilityWaiverTermsHashInput,
1908
+ validateTimeWindow,
1909
+ verifyAAR,
1910
+ verifyDetachedEd25519,
1911
+ verifySignedRejectionReceipt
1080
1912
  });
1081
1913
  //# sourceMappingURL=index.cjs.map