@agirails/sdk 4.4.9 → 4.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/dist/builders/DeliveryProofBuilder.d.ts +224 -13
  2. package/dist/builders/DeliveryProofBuilder.d.ts.map +1 -1
  3. package/dist/builders/DeliveryProofBuilder.js +247 -13
  4. package/dist/builders/DeliveryProofBuilder.js.map +1 -1
  5. package/dist/cli/agirails.d.ts +85 -1
  6. package/dist/cli/agirails.d.ts.map +1 -1
  7. package/dist/cli/agirails.js +429 -154
  8. package/dist/cli/agirails.js.map +1 -1
  9. package/dist/cli/commands/init.d.ts +54 -0
  10. package/dist/cli/commands/init.d.ts.map +1 -1
  11. package/dist/cli/commands/init.js +193 -1
  12. package/dist/cli/commands/init.js.map +1 -1
  13. package/dist/cli/commands/receipt.d.ts +70 -2
  14. package/dist/cli/commands/receipt.d.ts.map +1 -1
  15. package/dist/cli/commands/receipt.js +218 -3
  16. package/dist/cli/commands/receipt.js.map +1 -1
  17. package/dist/cli/commands/test.d.ts +77 -1
  18. package/dist/cli/commands/test.d.ts.map +1 -1
  19. package/dist/cli/commands/test.js +264 -2
  20. package/dist/cli/commands/test.js.map +1 -1
  21. package/dist/cli/lib/runRequest.d.ts +90 -0
  22. package/dist/cli/lib/runRequest.d.ts.map +1 -1
  23. package/dist/cli/lib/runRequest.js +300 -9
  24. package/dist/cli/lib/runRequest.js.map +1 -1
  25. package/dist/cli/lib/sentinelReflections.d.ts +111 -0
  26. package/dist/cli/lib/sentinelReflections.d.ts.map +1 -0
  27. package/dist/cli/lib/sentinelReflections.js +193 -0
  28. package/dist/cli/lib/sentinelReflections.js.map +1 -0
  29. package/dist/delivery/MockDeliveryChannel.d.ts +208 -0
  30. package/dist/delivery/MockDeliveryChannel.d.ts.map +1 -0
  31. package/dist/delivery/MockDeliveryChannel.js +445 -0
  32. package/dist/delivery/MockDeliveryChannel.js.map +1 -0
  33. package/dist/delivery/RelayDeliveryChannel.d.ts +176 -0
  34. package/dist/delivery/RelayDeliveryChannel.d.ts.map +1 -0
  35. package/dist/delivery/RelayDeliveryChannel.js +377 -0
  36. package/dist/delivery/RelayDeliveryChannel.js.map +1 -0
  37. package/dist/delivery/channel.d.ts +282 -0
  38. package/dist/delivery/channel.d.ts.map +1 -0
  39. package/dist/delivery/channel.js +76 -0
  40. package/dist/delivery/channel.js.map +1 -0
  41. package/dist/delivery/channelLog.d.ts +115 -0
  42. package/dist/delivery/channelLog.d.ts.map +1 -0
  43. package/dist/delivery/channelLog.js +94 -0
  44. package/dist/delivery/channelLog.js.map +1 -0
  45. package/dist/delivery/crypto.d.ts +312 -0
  46. package/dist/delivery/crypto.d.ts.map +1 -0
  47. package/dist/delivery/crypto.js +495 -0
  48. package/dist/delivery/crypto.js.map +1 -0
  49. package/dist/delivery/eip712.d.ts +248 -0
  50. package/dist/delivery/eip712.d.ts.map +1 -0
  51. package/dist/delivery/eip712.js +397 -0
  52. package/dist/delivery/eip712.js.map +1 -0
  53. package/dist/delivery/envelopeBuilder.d.ts +531 -0
  54. package/dist/delivery/envelopeBuilder.d.ts.map +1 -0
  55. package/dist/delivery/envelopeBuilder.js +832 -0
  56. package/dist/delivery/envelopeBuilder.js.map +1 -0
  57. package/dist/delivery/index.d.ts +53 -0
  58. package/dist/delivery/index.d.ts.map +1 -0
  59. package/dist/delivery/index.js +143 -0
  60. package/dist/delivery/index.js.map +1 -0
  61. package/dist/delivery/keys.d.ts +344 -0
  62. package/dist/delivery/keys.d.ts.map +1 -0
  63. package/dist/delivery/keys.js +513 -0
  64. package/dist/delivery/keys.js.map +1 -0
  65. package/dist/delivery/nonce-keys.d.ts +93 -0
  66. package/dist/delivery/nonce-keys.d.ts.map +1 -0
  67. package/dist/delivery/nonce-keys.js +88 -0
  68. package/dist/delivery/nonce-keys.js.map +1 -0
  69. package/dist/delivery/setupBuilder.d.ts +403 -0
  70. package/dist/delivery/setupBuilder.d.ts.map +1 -0
  71. package/dist/delivery/setupBuilder.js +554 -0
  72. package/dist/delivery/setupBuilder.js.map +1 -0
  73. package/dist/delivery/types.d.ts +722 -0
  74. package/dist/delivery/types.d.ts.map +1 -0
  75. package/dist/delivery/types.js +150 -0
  76. package/dist/delivery/types.js.map +1 -0
  77. package/dist/delivery/validate.d.ts +288 -0
  78. package/dist/delivery/validate.d.ts.map +1 -0
  79. package/dist/delivery/validate.js +648 -0
  80. package/dist/delivery/validate.js.map +1 -0
  81. package/dist/level1/Agent.d.ts +130 -0
  82. package/dist/level1/Agent.d.ts.map +1 -1
  83. package/dist/level1/Agent.js +248 -0
  84. package/dist/level1/Agent.js.map +1 -1
  85. package/dist/level1/types/Options.d.ts +62 -0
  86. package/dist/level1/types/Options.d.ts.map +1 -1
  87. package/dist/level1/types/Options.js +22 -0
  88. package/dist/level1/types/Options.js.map +1 -1
  89. package/dist/runtime/MockRuntime.d.ts +32 -0
  90. package/dist/runtime/MockRuntime.d.ts.map +1 -1
  91. package/dist/runtime/MockRuntime.js +44 -0
  92. package/dist/runtime/MockRuntime.js.map +1 -1
  93. package/package.json +6 -1
@@ -0,0 +1,648 @@
1
+ "use strict";
2
+ /**
3
+ * AIP-16 Delivery Surface — Runtime Validation (Phase 2a)
4
+ * ========================================================
5
+ *
6
+ * Pure, dependency-light runtime validators for the delivery surface
7
+ * wire and signed shapes. Used by:
8
+ *
9
+ * - Buyer SDK when receiving a {@link DeliveryEnvelopeWireV1} from the
10
+ * relay, before signature recovery and decryption.
11
+ * - Provider SDK when receiving a {@link DeliverySetupWireV1} from the
12
+ * relay, before signature recovery and ECDH key derivation.
13
+ * - Server-side Platform routes that accept these objects over HTTP
14
+ * (mirrored in Phase 2c so client and server share the same
15
+ * validation contract — defense-in-depth against a malicious peer
16
+ * or a buggy/older client).
17
+ *
18
+ * Design notes:
19
+ *
20
+ * - Validators are PURE — they do not throw, do not perform I/O, do
21
+ * not consult network state. They return a discriminated
22
+ * {@link ValidationResult} so callers can branch cleanly.
23
+ *
24
+ * - On the first failure the validator returns; we do NOT accumulate
25
+ * error lists. The first structural defect makes downstream checks
26
+ * meaningless and the order in which we check is deliberately
27
+ * coarse → fine (top-level shape, then individual fields, then
28
+ * cross-field invariants).
29
+ *
30
+ * - The error string is a stable, machine-actionable identifier
31
+ * (snake_case, no message punctuation). Higher layers map it to a
32
+ * {@link DeliveryErrorCode} when they want a structured error.
33
+ *
34
+ * - Field order in {@link DeliverySetupSignedV1} and
35
+ * {@link DeliveryEnvelopeSignedV1} is part of the EIP-712 type hash
36
+ * and therefore part of the cross-SDK contract. The validators here
37
+ * do NOT enforce order (it cannot be enforced on a parsed
38
+ * JavaScript object), but they DO enforce the *presence and type*
39
+ * of every field — which is sufficient to guarantee that signature
40
+ * recovery has a well-formed input.
41
+ *
42
+ * - Canonical-empty rule: for `scheme: "public-v1"`, the
43
+ * encryption-related slots (`providerEphemeralPubkey`, `nonce`,
44
+ * `tag`) MUST be the canonical zero-filled values of the correct
45
+ * length — NOT omitted, NOT non-zero. This is enforced by
46
+ * {@link validateSchemeConsistency} after the per-field validators
47
+ * pass.
48
+ *
49
+ * @module delivery/validate
50
+ * @see ./types — the underlying signed/wire interfaces
51
+ * @see ./eip712 — domain + signed-type schemas (kept in lock-step)
52
+ */
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ exports.validateSchemeConsistency = exports.validateEnvelopeWire = exports.validateEnvelopeSigned = exports.validateSetupWire = exports.validateSetupSigned = exports.isCanonicalEmptyBytes16 = exports.isCanonicalEmptyBytes12 = exports.isCanonicalEmptyBytes32 = exports.isValidRole = exports.isValidPrivacy = exports.isValidScheme = exports.isValidUintString = exports.isValidAddress = exports.isValidBytes16 = exports.isValidBytes12 = exports.isValidBytes32 = void 0;
55
+ const ethers_1 = require("ethers");
56
+ const types_1 = require("./types");
57
+ // ============================================================================
58
+ // Internal Constants
59
+ // ============================================================================
60
+ //
61
+ // Hex regexes here are intentionally compiled once at module scope (not
62
+ // per-call) — they are exercised on every inbound wire object, and the
63
+ // per-call regex cost would otherwise be a measurable share of the
64
+ // validation budget.
65
+ //
66
+ // We accept BOTH cases of A-F in the hex body so that callers using
67
+ // checksum-cased addresses or mixed-case bytes32 (e.g. straight from
68
+ // `ethers.hexlify`, which currently lowercases but may not always)
69
+ // are not punished by this layer. The signed types canonicalize
70
+ // addresses to lowercase later, before signature recovery.
71
+ const BYTES32_HEX_RE = /^0x[0-9a-fA-F]{64}$/;
72
+ const BYTES16_HEX_RE = /^0x[0-9a-fA-F]{32}$/;
73
+ const BYTES12_HEX_RE = /^0x[0-9a-fA-F]{24}$/;
74
+ const UINT_STRING_RE = /^(0|[1-9][0-9]*)$/;
75
+ /**
76
+ * Allowed delivery schemes (kept in lock-step with {@link DeliveryScheme}).
77
+ * Exported as a tuple-cast Set so adding a new scheme is a single
78
+ * source-of-truth edit visible to all validators.
79
+ */
80
+ const ALLOWED_SCHEMES = new Set([
81
+ 'x25519-aes256gcm-v1',
82
+ 'public-v1',
83
+ ]);
84
+ /**
85
+ * Allowed expected-privacy values (kept in lock-step with
86
+ * {@link DeliveryPrivacy}).
87
+ */
88
+ const ALLOWED_PRIVACY = new Set([
89
+ 'encrypted',
90
+ 'public',
91
+ ]);
92
+ /**
93
+ * Allowed participant role tokens (kept in lock-step with
94
+ * {@link ParticipantRole}).
95
+ */
96
+ const ALLOWED_ROLES = new Set([
97
+ 'provider',
98
+ 'requester',
99
+ ]);
100
+ /**
101
+ * Lowercased canonical-empty hex strings, computed once at module load
102
+ * so comparisons in {@link validateSchemeConsistency} are a fast string
103
+ * equality on already-normalized values.
104
+ */
105
+ const CANONICAL_EMPTY_BYTES32_LC = types_1.CANONICAL_EMPTY_BYTES32.toLowerCase();
106
+ const CANONICAL_EMPTY_BYTES12_LC = types_1.CANONICAL_EMPTY_BYTES12.toLowerCase();
107
+ const CANONICAL_EMPTY_BYTES16_LC = types_1.CANONICAL_EMPTY_BYTES16.toLowerCase();
108
+ /**
109
+ * Maximum reasonable `acceptedChannels` array length. The v1 channel
110
+ * registry has exactly one entry (`agirails-relay-v1`); we accept up
111
+ * to 32 to leave room for future channels without making the cap a
112
+ * forwards-compat hazard, but reject obviously-pathological lists
113
+ * that could be used to inflate signed-payload size.
114
+ */
115
+ const MAX_ACCEPTED_CHANNELS = 32;
116
+ /**
117
+ * Maximum reasonable length of a single channel identifier string.
118
+ * The v1 identifier `agirails-relay-v1` is 17 chars; a 256-char cap
119
+ * provides ample room for namespaced future identifiers (e.g.
120
+ * `libp2p://Qm…`) while preventing memory amplification attacks.
121
+ */
122
+ const MAX_CHANNEL_ID_LENGTH = 256;
123
+ // ============================================================================
124
+ // Primitive Validators
125
+ // ============================================================================
126
+ /**
127
+ * True iff `s` is a string of exactly `0x` + 64 hex characters
128
+ * (case-insensitive), i.e. a well-formed `bytes32` hex value.
129
+ *
130
+ * Does NOT enforce lowercase — both lower and upper hex digits are
131
+ * accepted. Higher layers (signature recovery, canonical-empty
132
+ * checks) are responsible for case normalization where it matters.
133
+ */
134
+ function isValidBytes32(s) {
135
+ return typeof s === 'string' && BYTES32_HEX_RE.test(s);
136
+ }
137
+ exports.isValidBytes32 = isValidBytes32;
138
+ /**
139
+ * True iff `s` is a string of exactly `0x` + 24 hex characters
140
+ * (case-insensitive), i.e. a well-formed `bytes12` value — the
141
+ * AES-GCM nonce length.
142
+ */
143
+ function isValidBytes12(s) {
144
+ return typeof s === 'string' && BYTES12_HEX_RE.test(s);
145
+ }
146
+ exports.isValidBytes12 = isValidBytes12;
147
+ /**
148
+ * True iff `s` is a string of exactly `0x` + 32 hex characters
149
+ * (case-insensitive), i.e. a well-formed `bytes16` value — the
150
+ * AES-GCM authentication tag length.
151
+ */
152
+ function isValidBytes16(s) {
153
+ return typeof s === 'string' && BYTES16_HEX_RE.test(s);
154
+ }
155
+ exports.isValidBytes16 = isValidBytes16;
156
+ /**
157
+ * True iff `s` is a string that `ethers.isAddress` accepts as an EVM
158
+ * address. Accepts both lowercase and EIP-55 mixed-case checksummed
159
+ * addresses. `ethers.isAddress` returns false on invalid checksums,
160
+ * so a mixed-case address whose case is wrong is rejected here too —
161
+ * which is the intended behaviour.
162
+ *
163
+ * NOTE: We do NOT enforce a particular case at this layer; callers
164
+ * that need canonical (lowercase) comparison MUST `.toLowerCase()`
165
+ * both sides themselves, per the repo-wide convention.
166
+ */
167
+ function isValidAddress(s) {
168
+ return typeof s === 'string' && (0, ethers_1.isAddress)(s);
169
+ }
170
+ exports.isValidAddress = isValidAddress;
171
+ /**
172
+ * True iff `s` is a decimal-string representation of a non-negative
173
+ * integer with no leading zeros (other than the literal `"0"`).
174
+ *
175
+ * Exists for forward-compat with future receipts-style integer
176
+ * fields that must round-trip across JSON without losing precision
177
+ * (JavaScript numbers cannot represent uint256 values).
178
+ */
179
+ function isValidUintString(s) {
180
+ return typeof s === 'string' && UINT_STRING_RE.test(s);
181
+ }
182
+ exports.isValidUintString = isValidUintString;
183
+ /**
184
+ * True iff `s` is one of the {@link DeliveryScheme} discriminants.
185
+ * Type guard so downstream code can branch on `scheme` with
186
+ * exhaustiveness.
187
+ */
188
+ function isValidScheme(s) {
189
+ return typeof s === 'string' && ALLOWED_SCHEMES.has(s);
190
+ }
191
+ exports.isValidScheme = isValidScheme;
192
+ /**
193
+ * True iff `s` is one of the {@link DeliveryPrivacy} discriminants.
194
+ */
195
+ function isValidPrivacy(s) {
196
+ return typeof s === 'string' && ALLOWED_PRIVACY.has(s);
197
+ }
198
+ exports.isValidPrivacy = isValidPrivacy;
199
+ /**
200
+ * True iff `s` is one of the {@link ParticipantRole} discriminants.
201
+ */
202
+ function isValidRole(s) {
203
+ return typeof s === 'string' && ALLOWED_ROLES.has(s);
204
+ }
205
+ exports.isValidRole = isValidRole;
206
+ // ============================================================================
207
+ // Canonical-Empty Checks
208
+ // ============================================================================
209
+ /**
210
+ * True iff `s` is the canonical empty bytes32 value (32 zero bytes,
211
+ * hex-encoded). Comparison is case-insensitive — the canonical form
212
+ * itself is all-zero so case is moot, but accepting `0x0000…` and
213
+ * `0x0000…` (uppercase X is not valid per regex) consistently is
214
+ * cheapest with a single `.toLowerCase()`.
215
+ *
216
+ * Used by {@link validateSchemeConsistency} to enforce the
217
+ * `public-v1` canonical-empty rule on `providerEphemeralPubkey`
218
+ * and (in setups) `buyerEphemeralPubkey`.
219
+ */
220
+ function isCanonicalEmptyBytes32(s) {
221
+ return typeof s === 'string' && s.toLowerCase() === CANONICAL_EMPTY_BYTES32_LC;
222
+ }
223
+ exports.isCanonicalEmptyBytes32 = isCanonicalEmptyBytes32;
224
+ /**
225
+ * True iff `s` is the canonical empty bytes12 value (12 zero bytes,
226
+ * hex-encoded). Used to enforce the `public-v1` canonical-empty rule
227
+ * on the AES-GCM `nonce` slot.
228
+ */
229
+ function isCanonicalEmptyBytes12(s) {
230
+ return typeof s === 'string' && s.toLowerCase() === CANONICAL_EMPTY_BYTES12_LC;
231
+ }
232
+ exports.isCanonicalEmptyBytes12 = isCanonicalEmptyBytes12;
233
+ /**
234
+ * True iff `s` is the canonical empty bytes16 value (16 zero bytes,
235
+ * hex-encoded). Used to enforce the `public-v1` canonical-empty rule
236
+ * on the AES-GCM authentication `tag` slot.
237
+ */
238
+ function isCanonicalEmptyBytes16(s) {
239
+ return typeof s === 'string' && s.toLowerCase() === CANONICAL_EMPTY_BYTES16_LC;
240
+ }
241
+ exports.isCanonicalEmptyBytes16 = isCanonicalEmptyBytes16;
242
+ // ============================================================================
243
+ // Internal Helpers
244
+ // ============================================================================
245
+ /**
246
+ * Convenience: type guard for non-null objects. Narrows `unknown` to
247
+ * a record we can index into without TS complaining. Excludes arrays
248
+ * because arrays are objects-with-numeric-keys and would otherwise
249
+ * pass through this guard misleadingly.
250
+ */
251
+ function isObjectLike(x) {
252
+ return typeof x === 'object' && x !== null && !Array.isArray(x);
253
+ }
254
+ /**
255
+ * True iff `n` is a finite integer (no NaN, no Infinity, no
256
+ * fractional component) AND strictly positive (Unix-seconds timestamps
257
+ * are always > 0 in our era).
258
+ */
259
+ function isPositiveInteger(n) {
260
+ return (typeof n === 'number' &&
261
+ Number.isFinite(n) &&
262
+ Number.isInteger(n) &&
263
+ n > 0);
264
+ }
265
+ /**
266
+ * True iff `arr` is a non-empty array of non-empty strings, each at
267
+ * most {@link MAX_CHANNEL_ID_LENGTH} characters, with at most
268
+ * {@link MAX_ACCEPTED_CHANNELS} entries.
269
+ *
270
+ * The length caps are not part of the AIP-16 spec; they are local
271
+ * structural-validation guards against pathological inputs that
272
+ * could inflate the signed-payload size or the cost of downstream
273
+ * processing.
274
+ */
275
+ function isValidAcceptedChannels(arr) {
276
+ if (!Array.isArray(arr)) {
277
+ return false;
278
+ }
279
+ if (arr.length === 0 || arr.length > MAX_ACCEPTED_CHANNELS) {
280
+ return false;
281
+ }
282
+ for (const c of arr) {
283
+ if (typeof c !== 'string') {
284
+ return false;
285
+ }
286
+ if (c.length === 0 || c.length > MAX_CHANNEL_ID_LENGTH) {
287
+ return false;
288
+ }
289
+ }
290
+ return true;
291
+ }
292
+ /**
293
+ * Build a failure result with the given error identifier. Tiny
294
+ * helper that exists so call sites read as a single expression.
295
+ */
296
+ function fail(error) {
297
+ return { ok: false, error };
298
+ }
299
+ /**
300
+ * Singleton success result reused across all validators — these
301
+ * objects are immutable from this module's perspective and reusing
302
+ * a single instance eliminates allocation on the common (valid) path.
303
+ */
304
+ const OK = { ok: true };
305
+ // ============================================================================
306
+ // Setup Signed Validator
307
+ // ============================================================================
308
+ /**
309
+ * Validate a {@link DeliverySetupSignedV1} object's structure and
310
+ * field-level invariants.
311
+ *
312
+ * Checks performed (in order):
313
+ *
314
+ * 1. Top-level shape is a non-null object.
315
+ * 2. `version === 1` exactly (integer-equal, not string-equal).
316
+ * 3. `txId` is a well-formed bytes32 hex string.
317
+ * 4. `chainId` is a positive integer.
318
+ * 5. `kernelAddress`, `requesterAddress`, `signerAddress` are valid
319
+ * EVM addresses (case-insensitive per `ethers.isAddress`).
320
+ * 6. `buyerEphemeralPubkey` is a well-formed bytes32 hex string.
321
+ * 7. `acceptedChannels` is a non-empty bounded array of non-empty
322
+ * bounded strings.
323
+ * 8. `expectedPrivacy` is one of the {@link DeliveryPrivacy} values.
324
+ * 9. `createdAt`, `expiresAt` are positive integers (Unix seconds).
325
+ * 10. `expiresAt > createdAt` (cross-field).
326
+ *
327
+ * Does NOT verify the signature, the chainId↔network mapping, the
328
+ * smart-wallet derivation, the kernel allowlist, or the canonical-
329
+ * empty rule for `buyerEphemeralPubkey` against `expectedPrivacy` —
330
+ * those are the responsibility of higher layers (signature recovery,
331
+ * verifier modules, scheme-consistency in {@link validateSchemeConsistency}
332
+ * for envelopes; setup-side privacy/pubkey consistency is enforced
333
+ * by the setup verifier in Phase 2b).
334
+ *
335
+ * @param obj — value of `unknown` static type (validated at runtime).
336
+ * @returns {@link ValidationResult}.
337
+ */
338
+ function validateSetupSigned(obj) {
339
+ if (!isObjectLike(obj)) {
340
+ return fail('setup_signed_not_object');
341
+ }
342
+ if (obj.version !== 1) {
343
+ return fail('setup_version_invalid');
344
+ }
345
+ if (!isValidBytes32(obj.txId)) {
346
+ return fail('setup_txid_invalid');
347
+ }
348
+ if (typeof obj.chainId !== 'number' ||
349
+ !Number.isInteger(obj.chainId) ||
350
+ obj.chainId <= 0) {
351
+ return fail('setup_chain_id_invalid');
352
+ }
353
+ if (!isValidAddress(obj.kernelAddress)) {
354
+ return fail('setup_kernel_address_invalid');
355
+ }
356
+ if (!isValidAddress(obj.requesterAddress)) {
357
+ return fail('setup_requester_address_invalid');
358
+ }
359
+ if (!isValidAddress(obj.signerAddress)) {
360
+ return fail('setup_signer_address_invalid');
361
+ }
362
+ if (!isValidBytes32(obj.buyerEphemeralPubkey)) {
363
+ return fail('setup_buyer_pubkey_invalid');
364
+ }
365
+ if (!isValidAcceptedChannels(obj.acceptedChannels)) {
366
+ return fail('setup_accepted_channels_invalid');
367
+ }
368
+ if (!isValidPrivacy(obj.expectedPrivacy)) {
369
+ return fail('setup_expected_privacy_invalid');
370
+ }
371
+ if (!isPositiveInteger(obj.createdAt)) {
372
+ return fail('setup_created_at_invalid');
373
+ }
374
+ if (!isPositiveInteger(obj.expiresAt)) {
375
+ return fail('setup_expires_at_invalid');
376
+ }
377
+ if (obj.expiresAt <= obj.createdAt) {
378
+ return fail('expiresAt_before_createdAt');
379
+ }
380
+ return OK;
381
+ }
382
+ exports.validateSetupSigned = validateSetupSigned;
383
+ // ============================================================================
384
+ // Setup Wire Validator
385
+ // ============================================================================
386
+ /**
387
+ * Validate a {@link DeliverySetupWireV1} object's structure.
388
+ *
389
+ * Checks performed (in order):
390
+ *
391
+ * 1. Top-level shape is a non-null object.
392
+ * 2. `signed` validates as a {@link DeliverySetupSignedV1}.
393
+ * 3. `requesterSig` is a string starting with `0x` and of even hex
394
+ * length consistent with a typical 65-byte EIP-712 signature
395
+ * (132 hex chars + `0x` = 134 chars). We accept any `0x`-hex
396
+ * string of plausible signature length; the actual cryptographic
397
+ * validity is checked by `ethers.verifyTypedData` in the
398
+ * recovery helpers — there is no point duplicating that here.
399
+ * 4. `serverMeta`, if present, is an object with `receivedAt`
400
+ * (non-empty string) and `relayId` (non-empty string). Absence
401
+ * is fine — `serverMeta` is set by the relay on read and is not
402
+ * present on freshly built setups.
403
+ *
404
+ * @param obj — value of `unknown` static type.
405
+ * @returns {@link ValidationResult}.
406
+ */
407
+ function validateSetupWire(obj) {
408
+ if (!isObjectLike(obj)) {
409
+ return fail('setup_wire_not_object');
410
+ }
411
+ const signedResult = validateSetupSigned(obj.signed);
412
+ if (!signedResult.ok) {
413
+ return signedResult;
414
+ }
415
+ if (!isValidSignatureHex(obj.requesterSig)) {
416
+ return fail('setup_requester_sig_invalid');
417
+ }
418
+ if (obj.serverMeta !== undefined) {
419
+ const sm = obj.serverMeta;
420
+ if (!isObjectLike(sm)) {
421
+ return fail('setup_server_meta_invalid');
422
+ }
423
+ if (typeof sm.receivedAt !== 'string' || sm.receivedAt.length === 0) {
424
+ return fail('setup_server_meta_received_at_invalid');
425
+ }
426
+ if (typeof sm.relayId !== 'string' || sm.relayId.length === 0) {
427
+ return fail('setup_server_meta_relay_id_invalid');
428
+ }
429
+ }
430
+ return OK;
431
+ }
432
+ exports.validateSetupWire = validateSetupWire;
433
+ // ============================================================================
434
+ // Envelope Signed Validator
435
+ // ============================================================================
436
+ /**
437
+ * Validate a {@link DeliveryEnvelopeSignedV1} object's structure and
438
+ * field-level invariants.
439
+ *
440
+ * Checks performed (in order):
441
+ *
442
+ * 1. Top-level shape is a non-null object.
443
+ * 2. `version === 1` exactly.
444
+ * 3. `txId` is a well-formed bytes32 hex string.
445
+ * 4. `chainId` is a positive integer.
446
+ * 5. `kernelAddress`, `providerAddress`, `signerAddress` are valid
447
+ * EVM addresses.
448
+ * 6. `scheme` is one of the {@link DeliveryScheme} discriminants.
449
+ * 7. `providerEphemeralPubkey` is a well-formed bytes32 hex string.
450
+ * 8. `nonce` is a well-formed bytes12 hex string.
451
+ * 9. `payloadHash` is a well-formed bytes32 hex string.
452
+ * 10. `tag` is a well-formed bytes16 hex string.
453
+ * 11. `createdAt` is a positive integer.
454
+ * 12. Scheme/canonical-empty consistency via
455
+ * {@link validateSchemeConsistency}.
456
+ *
457
+ * Does NOT verify the signature, recompute `payloadHash`, or
458
+ * decrypt — those happen in higher layers.
459
+ *
460
+ * @param obj — value of `unknown` static type.
461
+ * @returns {@link ValidationResult}.
462
+ */
463
+ function validateEnvelopeSigned(obj) {
464
+ if (!isObjectLike(obj)) {
465
+ return fail('envelope_signed_not_object');
466
+ }
467
+ if (obj.version !== 1) {
468
+ return fail('envelope_version_invalid');
469
+ }
470
+ if (!isValidBytes32(obj.txId)) {
471
+ return fail('envelope_txid_invalid');
472
+ }
473
+ if (typeof obj.chainId !== 'number' ||
474
+ !Number.isInteger(obj.chainId) ||
475
+ obj.chainId <= 0) {
476
+ return fail('envelope_chain_id_invalid');
477
+ }
478
+ if (!isValidAddress(obj.kernelAddress)) {
479
+ return fail('envelope_kernel_address_invalid');
480
+ }
481
+ if (!isValidAddress(obj.providerAddress)) {
482
+ return fail('envelope_provider_address_invalid');
483
+ }
484
+ if (!isValidAddress(obj.signerAddress)) {
485
+ return fail('envelope_signer_address_invalid');
486
+ }
487
+ if (!isValidScheme(obj.scheme)) {
488
+ return fail('envelope_scheme_invalid');
489
+ }
490
+ if (!isValidBytes32(obj.providerEphemeralPubkey)) {
491
+ return fail('envelope_provider_pubkey_invalid');
492
+ }
493
+ if (!isValidBytes12(obj.nonce)) {
494
+ return fail('envelope_nonce_invalid');
495
+ }
496
+ if (!isValidBytes32(obj.payloadHash)) {
497
+ return fail('envelope_payload_hash_invalid');
498
+ }
499
+ if (!isValidBytes16(obj.tag)) {
500
+ return fail('envelope_tag_invalid');
501
+ }
502
+ if (!isPositiveInteger(obj.createdAt)) {
503
+ return fail('envelope_created_at_invalid');
504
+ }
505
+ // Cross-field: scheme ↔ canonical-empty invariant. At this point we
506
+ // know every field has the right TYPE and LENGTH; the consistency
507
+ // check confirms the VALUES are correct for the declared scheme.
508
+ return validateSchemeConsistency(obj);
509
+ }
510
+ exports.validateEnvelopeSigned = validateEnvelopeSigned;
511
+ // ============================================================================
512
+ // Envelope Wire Validator
513
+ // ============================================================================
514
+ /**
515
+ * Validate a {@link DeliveryEnvelopeWireV1} object's structure.
516
+ *
517
+ * Checks performed (in order):
518
+ *
519
+ * 1. Top-level shape is a non-null object.
520
+ * 2. `signed` validates as a {@link DeliveryEnvelopeSignedV1}
521
+ * (which includes the scheme/canonical-empty consistency check).
522
+ * 3. `body` is a string. For `public-v1` this is plaintext UTF-8
523
+ * JSON; for `x25519-aes256gcm-v1` this is base64-encoded
524
+ * ciphertext. We do NOT verify base64-ness here because the
525
+ * receiver will discover any malformed encoding when it
526
+ * recomputes `payloadHash`. We DO insist on non-empty — an
527
+ * empty body would imply the provider sent nothing.
528
+ * 4. `providerSig` is a `0x`-hex string of plausible signature length.
529
+ * 5. `serverMeta`, if present, is well-formed.
530
+ *
531
+ * @param obj — value of `unknown` static type.
532
+ * @returns {@link ValidationResult}.
533
+ */
534
+ function validateEnvelopeWire(obj) {
535
+ if (!isObjectLike(obj)) {
536
+ return fail('envelope_wire_not_object');
537
+ }
538
+ const signedResult = validateEnvelopeSigned(obj.signed);
539
+ if (!signedResult.ok) {
540
+ return signedResult;
541
+ }
542
+ if (typeof obj.body !== 'string' || obj.body.length === 0) {
543
+ return fail('envelope_body_invalid');
544
+ }
545
+ if (!isValidSignatureHex(obj.providerSig)) {
546
+ return fail('envelope_provider_sig_invalid');
547
+ }
548
+ if (obj.serverMeta !== undefined) {
549
+ const sm = obj.serverMeta;
550
+ if (!isObjectLike(sm)) {
551
+ return fail('envelope_server_meta_invalid');
552
+ }
553
+ if (typeof sm.receivedAt !== 'string' || sm.receivedAt.length === 0) {
554
+ return fail('envelope_server_meta_received_at_invalid');
555
+ }
556
+ if (typeof sm.relayId !== 'string' || sm.relayId.length === 0) {
557
+ return fail('envelope_server_meta_relay_id_invalid');
558
+ }
559
+ }
560
+ return OK;
561
+ }
562
+ exports.validateEnvelopeWire = validateEnvelopeWire;
563
+ // ============================================================================
564
+ // Scheme Consistency (Canonical-Empty Rule)
565
+ // ============================================================================
566
+ /**
567
+ * Cross-field check enforcing the AIP-16 canonical-empty rule on a
568
+ * {@link DeliveryEnvelopeSignedV1}.
569
+ *
570
+ * Rule:
571
+ *
572
+ * - `scheme === "public-v1"` →
573
+ * `providerEphemeralPubkey === CANONICAL_EMPTY_BYTES32` AND
574
+ * `nonce === CANONICAL_EMPTY_BYTES12` AND
575
+ * `tag === CANONICAL_EMPTY_BYTES16`.
576
+ *
577
+ * - `scheme === "x25519-aes256gcm-v1"` →
578
+ * `providerEphemeralPubkey` MUST NOT be canonical empty (a zero
579
+ * X25519 public key cannot produce a usable shared secret —
580
+ * RFC 7748 §6.1 actually requires implementations to reject it)
581
+ * AND `nonce` MUST NOT be canonical empty (a zero AES-GCM nonce
582
+ * under a real key catastrophically breaks GCM) AND `tag` MUST
583
+ * NOT be canonical empty (a zero 128-bit tag has ~2^-128 chance
584
+ * of matching, so this is effectively a signal that the
585
+ * provider built the envelope incorrectly).
586
+ *
587
+ * This validator assumes the underlying field types are already
588
+ * correct (length, hex shape) — callers must run
589
+ * {@link validateEnvelopeSigned} first, which is also where this is
590
+ * invoked from automatically.
591
+ *
592
+ * @param env — already-shape-validated envelope.
593
+ * @returns {@link ValidationResult}.
594
+ */
595
+ function validateSchemeConsistency(env) {
596
+ if (env.scheme === 'public-v1') {
597
+ if (!isCanonicalEmptyBytes32(env.providerEphemeralPubkey)) {
598
+ return fail('envelope_public_pubkey_not_canonical_empty');
599
+ }
600
+ if (!isCanonicalEmptyBytes12(env.nonce)) {
601
+ return fail('envelope_public_nonce_not_canonical_empty');
602
+ }
603
+ if (!isCanonicalEmptyBytes16(env.tag)) {
604
+ return fail('envelope_public_tag_not_canonical_empty');
605
+ }
606
+ return OK;
607
+ }
608
+ if (env.scheme === 'x25519-aes256gcm-v1') {
609
+ if (isCanonicalEmptyBytes32(env.providerEphemeralPubkey)) {
610
+ return fail('envelope_encrypted_pubkey_is_canonical_empty');
611
+ }
612
+ if (isCanonicalEmptyBytes12(env.nonce)) {
613
+ return fail('envelope_encrypted_nonce_is_canonical_empty');
614
+ }
615
+ if (isCanonicalEmptyBytes16(env.tag)) {
616
+ return fail('envelope_encrypted_tag_is_canonical_empty');
617
+ }
618
+ return OK;
619
+ }
620
+ // Unreachable if validateEnvelopeSigned has run, but guards against
621
+ // direct callers using a malformed scheme via the public type cast.
622
+ return fail('envelope_scheme_invalid');
623
+ }
624
+ exports.validateSchemeConsistency = validateSchemeConsistency;
625
+ // ============================================================================
626
+ // Internal: Signature-Shape Heuristic
627
+ // ============================================================================
628
+ /**
629
+ * True iff `s` is a `0x`-prefixed hex string of length consistent
630
+ * with a standard 65-byte secp256k1 EIP-712 signature (r ‖ s ‖ v).
631
+ * Specifically: `0x` + 130 hex characters.
632
+ *
633
+ * This is a *shape* check; cryptographic validity is established by
634
+ * `ethers.verifyTypedData` in the recovery helpers — there is no
635
+ * value in re-implementing that here, and doing so would risk
636
+ * disagreeing with ethers on edge cases.
637
+ *
638
+ * We do NOT export this helper as part of the public API because
639
+ * downstream code that wants signature validation should use the
640
+ * recovery helpers in `./eip712.ts`; the shape check is internal
641
+ * structural validation only.
642
+ */
643
+ function isValidSignatureHex(s) {
644
+ return (typeof s === 'string' &&
645
+ s.length === 132 &&
646
+ /^0x[0-9a-fA-F]{130}$/.test(s));
647
+ }
648
+ //# sourceMappingURL=validate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.js","sourceRoot":"","sources":["../../src/delivery/validate.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;;;AAEH,mCAAmC;AAEnC,mCAWiB;AA0BjB,+EAA+E;AAC/E,qBAAqB;AACrB,+EAA+E;AAC/E,EAAE;AACF,wEAAwE;AACxE,uEAAuE;AACvE,mEAAmE;AACnE,qBAAqB;AACrB,EAAE;AACF,oEAAoE;AACpE,qEAAqE;AACrE,mEAAmE;AACnE,gEAAgE;AAChE,2DAA2D;AAE3D,MAAM,cAAc,GAAG,qBAAqB,CAAC;AAC7C,MAAM,cAAc,GAAG,qBAAqB,CAAC;AAC7C,MAAM,cAAc,GAAG,qBAAqB,CAAC;AAC7C,MAAM,cAAc,GAAG,mBAAmB,CAAC;AAE3C;;;;GAIG;AACH,MAAM,eAAe,GAAgC,IAAI,GAAG,CAAiB;IAC3E,qBAAqB;IACrB,WAAW;CACZ,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,eAAe,GAAiC,IAAI,GAAG,CAAkB;IAC7E,WAAW;IACX,QAAQ;CACT,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,aAAa,GAAiC,IAAI,GAAG,CAAkB;IAC3E,UAAU;IACV,WAAW;CACZ,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,0BAA0B,GAAG,+BAAuB,CAAC,WAAW,EAAE,CAAC;AACzE,MAAM,0BAA0B,GAAG,+BAAuB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