@agirails/sdk 4.4.9 → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) 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 +95 -0
  10. package/dist/cli/commands/init.d.ts.map +1 -1
  11. package/dist/cli/commands/init.js +338 -1
  12. package/dist/cli/commands/init.js.map +1 -1
  13. package/dist/cli/commands/publish.d.ts +19 -0
  14. package/dist/cli/commands/publish.d.ts.map +1 -1
  15. package/dist/cli/commands/publish.js +14 -1
  16. package/dist/cli/commands/publish.js.map +1 -1
  17. package/dist/cli/commands/receipt.d.ts +70 -2
  18. package/dist/cli/commands/receipt.d.ts.map +1 -1
  19. package/dist/cli/commands/receipt.js +218 -3
  20. package/dist/cli/commands/receipt.js.map +1 -1
  21. package/dist/cli/commands/test.d.ts +77 -1
  22. package/dist/cli/commands/test.d.ts.map +1 -1
  23. package/dist/cli/commands/test.js +264 -2
  24. package/dist/cli/commands/test.js.map +1 -1
  25. package/dist/cli/lib/runRequest.d.ts +90 -0
  26. package/dist/cli/lib/runRequest.d.ts.map +1 -1
  27. package/dist/cli/lib/runRequest.js +300 -9
  28. package/dist/cli/lib/runRequest.js.map +1 -1
  29. package/dist/cli/lib/sentinelReflections.d.ts +111 -0
  30. package/dist/cli/lib/sentinelReflections.d.ts.map +1 -0
  31. package/dist/cli/lib/sentinelReflections.js +193 -0
  32. package/dist/cli/lib/sentinelReflections.js.map +1 -0
  33. package/dist/delivery/MockDeliveryChannel.d.ts +208 -0
  34. package/dist/delivery/MockDeliveryChannel.d.ts.map +1 -0
  35. package/dist/delivery/MockDeliveryChannel.js +445 -0
  36. package/dist/delivery/MockDeliveryChannel.js.map +1 -0
  37. package/dist/delivery/RelayDeliveryChannel.d.ts +176 -0
  38. package/dist/delivery/RelayDeliveryChannel.d.ts.map +1 -0
  39. package/dist/delivery/RelayDeliveryChannel.js +377 -0
  40. package/dist/delivery/RelayDeliveryChannel.js.map +1 -0
  41. package/dist/delivery/channel.d.ts +282 -0
  42. package/dist/delivery/channel.d.ts.map +1 -0
  43. package/dist/delivery/channel.js +76 -0
  44. package/dist/delivery/channel.js.map +1 -0
  45. package/dist/delivery/channelLog.d.ts +115 -0
  46. package/dist/delivery/channelLog.d.ts.map +1 -0
  47. package/dist/delivery/channelLog.js +94 -0
  48. package/dist/delivery/channelLog.js.map +1 -0
  49. package/dist/delivery/crypto.d.ts +312 -0
  50. package/dist/delivery/crypto.d.ts.map +1 -0
  51. package/dist/delivery/crypto.js +495 -0
  52. package/dist/delivery/crypto.js.map +1 -0
  53. package/dist/delivery/eip712.d.ts +248 -0
  54. package/dist/delivery/eip712.d.ts.map +1 -0
  55. package/dist/delivery/eip712.js +397 -0
  56. package/dist/delivery/eip712.js.map +1 -0
  57. package/dist/delivery/envelopeBuilder.d.ts +531 -0
  58. package/dist/delivery/envelopeBuilder.d.ts.map +1 -0
  59. package/dist/delivery/envelopeBuilder.js +832 -0
  60. package/dist/delivery/envelopeBuilder.js.map +1 -0
  61. package/dist/delivery/index.d.ts +53 -0
  62. package/dist/delivery/index.d.ts.map +1 -0
  63. package/dist/delivery/index.js +143 -0
  64. package/dist/delivery/index.js.map +1 -0
  65. package/dist/delivery/keys.d.ts +344 -0
  66. package/dist/delivery/keys.d.ts.map +1 -0
  67. package/dist/delivery/keys.js +513 -0
  68. package/dist/delivery/keys.js.map +1 -0
  69. package/dist/delivery/nonce-keys.d.ts +93 -0
  70. package/dist/delivery/nonce-keys.d.ts.map +1 -0
  71. package/dist/delivery/nonce-keys.js +88 -0
  72. package/dist/delivery/nonce-keys.js.map +1 -0
  73. package/dist/delivery/setupBuilder.d.ts +403 -0
  74. package/dist/delivery/setupBuilder.d.ts.map +1 -0
  75. package/dist/delivery/setupBuilder.js +554 -0
  76. package/dist/delivery/setupBuilder.js.map +1 -0
  77. package/dist/delivery/types.d.ts +722 -0
  78. package/dist/delivery/types.d.ts.map +1 -0
  79. package/dist/delivery/types.js +150 -0
  80. package/dist/delivery/types.js.map +1 -0
  81. package/dist/delivery/validate.d.ts +288 -0
  82. package/dist/delivery/validate.d.ts.map +1 -0
  83. package/dist/delivery/validate.js +648 -0
  84. package/dist/delivery/validate.js.map +1 -0
  85. package/dist/level1/Agent.d.ts +130 -0
  86. package/dist/level1/Agent.d.ts.map +1 -1
  87. package/dist/level1/Agent.js +248 -0
  88. package/dist/level1/Agent.js.map +1 -1
  89. package/dist/level1/types/Options.d.ts +62 -0
  90. package/dist/level1/types/Options.d.ts.map +1 -1
  91. package/dist/level1/types/Options.js +22 -0
  92. package/dist/level1/types/Options.js.map +1 -1
  93. package/dist/runtime/MockRuntime.d.ts +32 -0
  94. package/dist/runtime/MockRuntime.d.ts.map +1 -1
  95. package/dist/runtime/MockRuntime.js +44 -0
  96. package/dist/runtime/MockRuntime.js.map +1 -1
  97. package/package.json +6 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/delivery/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AAMH;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,cAAc,GAAG,qBAAqB,GAAG,WAAW,CAAC;AAEjE;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,MAAM,CAAC;AAE9C;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,eAAe,GAAG,WAAW,GA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;;;;;;;;;;GAaG;AACH,eAAO,MAAM,uBAAuB,eAA4C,CAAC"}
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ /**
3
+ * AIP-16 Delivery Surface — Type Definitions (Phase 2a Foundation)
4
+ * =================================================================
5
+ *
6
+ * Type-level contract for the AGIRAILS delivery layer (AIP-16 Rev 5).
7
+ *
8
+ * The delivery surface is the post-COMMITTED / pre-DELIVERED protocol
9
+ * step in which the provider hands the requester the *actual* deliverable
10
+ * (the bytes the requester paid for), with cryptographic guarantees of
11
+ * authenticity, integrity, and (optionally) confidentiality.
12
+ *
13
+ * Two privacy modes are supported in v1:
14
+ *
15
+ * - `public-v1` — body is plaintext UTF-8 JSON. Anyone observing
16
+ * the channel can read it. Useful for public
17
+ * deliverables (open data, public model outputs).
18
+ * - `x25519-aes256gcm-v1` — body is AES-256-GCM ciphertext, key derived
19
+ * via X25519 ECDH + HKDF-SHA256 between provider
20
+ * and requester ephemeral keys. End-to-end
21
+ * confidential.
22
+ *
23
+ * The delivery surface is composed of two signed objects:
24
+ *
25
+ * 1. **DeliverySetup** — signed by the *requester* (buyer). Posted to the
26
+ * channel after COMMITTED. Declares the buyer's ephemeral pubkey,
27
+ * accepted channels, and expected privacy mode.
28
+ *
29
+ * 2. **DeliveryEnvelope** — signed by the *provider* (seller). Carries
30
+ * the body bytes (plaintext or ciphertext), AEAD nonce + tag, and
31
+ * `payloadHash = keccak256(bodyBytes)` for on-chain anchoring.
32
+ *
33
+ * Both objects use a *signed projection* + *wire envelope* split:
34
+ * - The *signed* object is the canonical EIP-712 payload — exact byte
35
+ * ordering and field layout matter for cross-SDK interoperability.
36
+ * - The *wire* object wraps it with the signature and optional relay
37
+ * server metadata for transport.
38
+ *
39
+ * ## Critical conventions
40
+ *
41
+ * - **EIP-712 domain**: ALWAYS `{name: "AGIRAILS Delivery", version: "1",
42
+ * chainId, verifyingContract: kernelAddress}`. Domain reuse across
43
+ * AIP features (negotiation, receipts) would enable cross-feature
44
+ * signature replay.
45
+ *
46
+ * - **Canonical empty values**: For `scheme: "public-v1"`, the encryption
47
+ * fields (`providerEphemeralPubkey`, `nonce`, `tag`) MUST be canonical
48
+ * empty (zero-filled bytes of the correct length), NOT omitted. EIP-712
49
+ * has no concept of an "absent" field — the type schema is fixed and
50
+ * every field has a value.
51
+ *
52
+ * - **Smart wallet two-step auth**: `signerAddress` is the EOA that
53
+ * produced the signature; `requesterAddress` / `providerAddress` is the
54
+ * on-chain participant (which may be a Smart Wallet — a contract that
55
+ * does not itself sign). Verification recovers the EOA from the
56
+ * signature, then checks either equality with the participant OR that
57
+ * the participant is the Smart Wallet derived from the EOA.
58
+ *
59
+ * - **Address comparisons** are always case-insensitive (.toLowerCase()).
60
+ *
61
+ * - **Field order in EIP-712 types is IMMUTABLE.** Any reordering of
62
+ * fields in `DeliverySetupSignedV1` or `DeliveryEnvelopeSignedV1`
63
+ * constitutes a breaking SDK change because both client and server
64
+ * must encode byte-for-byte identical typed-data structures.
65
+ *
66
+ * @module delivery/types
67
+ * @see {@link https://eips.ethereum.org/EIPS/eip-712 EIP-712 Typed Structured Data}
68
+ * @see {@link https://www.rfc-editor.org/rfc/rfc5869 RFC 5869 — HKDF}
69
+ * @see {@link https://datatracker.ietf.org/doc/html/rfc7748 RFC 7748 — X25519}
70
+ */
71
+ Object.defineProperty(exports, "__esModule", { value: true });
72
+ exports.CANONICAL_EMPTY_BYTES16 = exports.CANONICAL_EMPTY_BYTES12 = exports.CANONICAL_EMPTY_BYTES32 = void 0;
73
+ // ============================================================================
74
+ // Canonical Empty Value Constants
75
+ // ============================================================================
76
+ /**
77
+ * Canonical empty `bytes32` value: 32 zero bytes, hex-encoded.
78
+ *
79
+ * Used as the value of `buyerEphemeralPubkey` (in setups) and
80
+ * `providerEphemeralPubkey` / `payloadHash` slots whenever the field is
81
+ * scheme-irrelevant. EIP-712 has no concept of an absent field; every
82
+ * field in the typed schema has a value, so we use a canonical
83
+ * "no-data" sentinel that hashes to a known, predictable value.
84
+ *
85
+ * Specifically for `public-v1` envelopes:
86
+ * - `providerEphemeralPubkey` MUST equal this constant.
87
+ *
88
+ * For setups with `expectedPrivacy: "public"`:
89
+ * - `buyerEphemeralPubkey` MUST equal this constant.
90
+ *
91
+ * NOTE: `payloadHash` is NEVER canonical-empty in practice — even an
92
+ * empty body produces `keccak256("") = 0xc5d2…`. The constant is
93
+ * exported for type-level uniformity, not because `payloadHash` is
94
+ * ever zero.
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * // 0x0000000000000000000000000000000000000000000000000000000000000000
99
+ * console.log(CANONICAL_EMPTY_BYTES32);
100
+ * ```
101
+ */
102
+ exports.CANONICAL_EMPTY_BYTES32 = ('0x' + '00'.repeat(32));
103
+ /**
104
+ * Canonical empty `bytes12` value: 12 zero bytes, hex-encoded.
105
+ *
106
+ * Used for the AES-GCM `nonce` field when `scheme: "public-v1"` (the
107
+ * envelope is not encrypted, so there is no real nonce). Receivers
108
+ * MUST reject envelopes whose scheme is `public-v1` but whose `nonce`
109
+ * is NOT this constant.
110
+ *
111
+ * For `x25519-aes256gcm-v1`, `nonce` MUST be 12 random bytes — never
112
+ * this constant; a zero nonce under a real key catastrophically breaks
113
+ * AES-GCM (key recovery via tag forgery).
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * // 0x000000000000000000000000
118
+ * console.log(CANONICAL_EMPTY_BYTES12);
119
+ * ```
120
+ */
121
+ exports.CANONICAL_EMPTY_BYTES12 = ('0x' + '00'.repeat(12));
122
+ /**
123
+ * Canonical empty `bytes16` value: 16 zero bytes, hex-encoded.
124
+ *
125
+ * Used for the AES-GCM authentication `tag` field when
126
+ * `scheme: "public-v1"` (no encryption, no tag). Receivers MUST
127
+ * reject envelopes whose scheme is `public-v1` but whose `tag` is
128
+ * NOT this constant.
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * // 0x00000000000000000000000000000000
133
+ * console.log(CANONICAL_EMPTY_BYTES16);
134
+ * ```
135
+ */
136
+ exports.CANONICAL_EMPTY_BYTES16 = ('0x' + '00'.repeat(16));
137
+ // ============================================================================
138
+ // Domain Constants
139
+ // ============================================================================
140
+ //
141
+ // The EIP-712 domain ("AGIRAILS Delivery") and the typed-data schemas
142
+ // (DeliverySetupV1, DeliveryEnvelopeV1) are intentionally defined in
143
+ // `src/delivery/eip712.ts` — they are the contract surface between
144
+ // signer, verifier, and Platform server, and live with the helpers that
145
+ // build and verify the signatures. Importing them from a single
146
+ // location keeps domain-string discipline tight.
147
+ //
148
+ // (No domain constants are re-exported here; consumers should import
149
+ // directly from `src/delivery/eip712`.)
150
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/delivery/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;;;AAgrBH,+EAA+E;AAC/E,kCAAkC;AAClC,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACU,QAAA,uBAAuB,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAkB,CAAC;AAEjF;;;;;;;;;;;;;;;;;GAiBG;AACU,QAAA,uBAAuB,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAkB,CAAC;AAEjF;;;;;;;;;;;;;GAaG;AACU,QAAA,uBAAuB,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAkB,CAAC;AAEjF,+EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAC/E,EAAE;AACF,sEAAsE;AACtE,qEAAqE;AACrE,mEAAmE;AACnE,wEAAwE;AACxE,gEAAgE;AAChE,iDAAiD;AACjD,EAAE;AACF,qEAAqE;AACrE,wCAAwC"}
@@ -0,0 +1,288 @@
1
+ /**
2
+ * AIP-16 Delivery Surface — Runtime Validation (Phase 2a)
3
+ * ========================================================
4
+ *
5
+ * Pure, dependency-light runtime validators for the delivery surface
6
+ * wire and signed shapes. Used by:
7
+ *
8
+ * - Buyer SDK when receiving a {@link DeliveryEnvelopeWireV1} from the
9
+ * relay, before signature recovery and decryption.
10
+ * - Provider SDK when receiving a {@link DeliverySetupWireV1} from the
11
+ * relay, before signature recovery and ECDH key derivation.
12
+ * - Server-side Platform routes that accept these objects over HTTP
13
+ * (mirrored in Phase 2c so client and server share the same
14
+ * validation contract — defense-in-depth against a malicious peer
15
+ * or a buggy/older client).
16
+ *
17
+ * Design notes:
18
+ *
19
+ * - Validators are PURE — they do not throw, do not perform I/O, do
20
+ * not consult network state. They return a discriminated
21
+ * {@link ValidationResult} so callers can branch cleanly.
22
+ *
23
+ * - On the first failure the validator returns; we do NOT accumulate
24
+ * error lists. The first structural defect makes downstream checks
25
+ * meaningless and the order in which we check is deliberately
26
+ * coarse → fine (top-level shape, then individual fields, then
27
+ * cross-field invariants).
28
+ *
29
+ * - The error string is a stable, machine-actionable identifier
30
+ * (snake_case, no message punctuation). Higher layers map it to a
31
+ * {@link DeliveryErrorCode} when they want a structured error.
32
+ *
33
+ * - Field order in {@link DeliverySetupSignedV1} and
34
+ * {@link DeliveryEnvelopeSignedV1} is part of the EIP-712 type hash
35
+ * and therefore part of the cross-SDK contract. The validators here
36
+ * do NOT enforce order (it cannot be enforced on a parsed
37
+ * JavaScript object), but they DO enforce the *presence and type*
38
+ * of every field — which is sufficient to guarantee that signature
39
+ * recovery has a well-formed input.
40
+ *
41
+ * - Canonical-empty rule: for `scheme: "public-v1"`, the
42
+ * encryption-related slots (`providerEphemeralPubkey`, `nonce`,
43
+ * `tag`) MUST be the canonical zero-filled values of the correct
44
+ * length — NOT omitted, NOT non-zero. This is enforced by
45
+ * {@link validateSchemeConsistency} after the per-field validators
46
+ * pass.
47
+ *
48
+ * @module delivery/validate
49
+ * @see ./types — the underlying signed/wire interfaces
50
+ * @see ./eip712 — domain + signed-type schemas (kept in lock-step)
51
+ */
52
+ import { type DeliveryEnvelopeSignedV1, type DeliveryEnvelopeWireV1, type DeliveryPrivacy, type DeliveryScheme, type DeliverySetupSignedV1, type DeliverySetupWireV1, type ParticipantRole } from './types';
53
+ /**
54
+ * Discriminated-union result of every validator in this module.
55
+ *
56
+ * - `{ ok: true }` — the object satisfies all structural and field-level
57
+ * invariants enforced here. The caller MAY proceed to signature
58
+ * recovery, smart-wallet auth, decryption, etc.
59
+ *
60
+ * - `{ ok: false, error }` — the object failed at least one invariant.
61
+ * `error` is a stable snake_case identifier suitable for logging,
62
+ * metric labels, and mapping to a {@link DeliveryErrorCode}.
63
+ *
64
+ * Errors are surfaced as VALUES (not exceptions) because every call
65
+ * site here is hot-path validation of untrusted input from the relay
66
+ * or a peer SDK — throwing would force every caller into a try/catch
67
+ * just to branch on a boolean.
68
+ */
69
+ export type ValidationResult = {
70
+ ok: true;
71
+ } | {
72
+ ok: false;
73
+ error: string;
74
+ };
75
+ /**
76
+ * True iff `s` is a string of exactly `0x` + 64 hex characters
77
+ * (case-insensitive), i.e. a well-formed `bytes32` hex value.
78
+ *
79
+ * Does NOT enforce lowercase — both lower and upper hex digits are
80
+ * accepted. Higher layers (signature recovery, canonical-empty
81
+ * checks) are responsible for case normalization where it matters.
82
+ */
83
+ export declare function isValidBytes32(s: unknown): s is `0x${string}`;
84
+ /**
85
+ * True iff `s` is a string of exactly `0x` + 24 hex characters
86
+ * (case-insensitive), i.e. a well-formed `bytes12` value — the
87
+ * AES-GCM nonce length.
88
+ */
89
+ export declare function isValidBytes12(s: unknown): s is `0x${string}`;
90
+ /**
91
+ * True iff `s` is a string of exactly `0x` + 32 hex characters
92
+ * (case-insensitive), i.e. a well-formed `bytes16` value — the
93
+ * AES-GCM authentication tag length.
94
+ */
95
+ export declare function isValidBytes16(s: unknown): s is `0x${string}`;
96
+ /**
97
+ * True iff `s` is a string that `ethers.isAddress` accepts as an EVM
98
+ * address. Accepts both lowercase and EIP-55 mixed-case checksummed
99
+ * addresses. `ethers.isAddress` returns false on invalid checksums,
100
+ * so a mixed-case address whose case is wrong is rejected here too —
101
+ * which is the intended behaviour.
102
+ *
103
+ * NOTE: We do NOT enforce a particular case at this layer; callers
104
+ * that need canonical (lowercase) comparison MUST `.toLowerCase()`
105
+ * both sides themselves, per the repo-wide convention.
106
+ */
107
+ export declare function isValidAddress(s: unknown): s is `0x${string}`;
108
+ /**
109
+ * True iff `s` is a decimal-string representation of a non-negative
110
+ * integer with no leading zeros (other than the literal `"0"`).
111
+ *
112
+ * Exists for forward-compat with future receipts-style integer
113
+ * fields that must round-trip across JSON without losing precision
114
+ * (JavaScript numbers cannot represent uint256 values).
115
+ */
116
+ export declare function isValidUintString(s: unknown): boolean;
117
+ /**
118
+ * True iff `s` is one of the {@link DeliveryScheme} discriminants.
119
+ * Type guard so downstream code can branch on `scheme` with
120
+ * exhaustiveness.
121
+ */
122
+ export declare function isValidScheme(s: unknown): s is DeliveryScheme;
123
+ /**
124
+ * True iff `s` is one of the {@link DeliveryPrivacy} discriminants.
125
+ */
126
+ export declare function isValidPrivacy(s: unknown): s is DeliveryPrivacy;
127
+ /**
128
+ * True iff `s` is one of the {@link ParticipantRole} discriminants.
129
+ */
130
+ export declare function isValidRole(s: unknown): s is ParticipantRole;
131
+ /**
132
+ * True iff `s` is the canonical empty bytes32 value (32 zero bytes,
133
+ * hex-encoded). Comparison is case-insensitive — the canonical form
134
+ * itself is all-zero so case is moot, but accepting `0x0000…` and
135
+ * `0x0000…` (uppercase X is not valid per regex) consistently is
136
+ * cheapest with a single `.toLowerCase()`.
137
+ *
138
+ * Used by {@link validateSchemeConsistency} to enforce the
139
+ * `public-v1` canonical-empty rule on `providerEphemeralPubkey`
140
+ * and (in setups) `buyerEphemeralPubkey`.
141
+ */
142
+ export declare function isCanonicalEmptyBytes32(s: string): boolean;
143
+ /**
144
+ * True iff `s` is the canonical empty bytes12 value (12 zero bytes,
145
+ * hex-encoded). Used to enforce the `public-v1` canonical-empty rule
146
+ * on the AES-GCM `nonce` slot.
147
+ */
148
+ export declare function isCanonicalEmptyBytes12(s: string): boolean;
149
+ /**
150
+ * True iff `s` is the canonical empty bytes16 value (16 zero bytes,
151
+ * hex-encoded). Used to enforce the `public-v1` canonical-empty rule
152
+ * on the AES-GCM authentication `tag` slot.
153
+ */
154
+ export declare function isCanonicalEmptyBytes16(s: string): boolean;
155
+ /**
156
+ * Validate a {@link DeliverySetupSignedV1} object's structure and
157
+ * field-level invariants.
158
+ *
159
+ * Checks performed (in order):
160
+ *
161
+ * 1. Top-level shape is a non-null object.
162
+ * 2. `version === 1` exactly (integer-equal, not string-equal).
163
+ * 3. `txId` is a well-formed bytes32 hex string.
164
+ * 4. `chainId` is a positive integer.
165
+ * 5. `kernelAddress`, `requesterAddress`, `signerAddress` are valid
166
+ * EVM addresses (case-insensitive per `ethers.isAddress`).
167
+ * 6. `buyerEphemeralPubkey` is a well-formed bytes32 hex string.
168
+ * 7. `acceptedChannels` is a non-empty bounded array of non-empty
169
+ * bounded strings.
170
+ * 8. `expectedPrivacy` is one of the {@link DeliveryPrivacy} values.
171
+ * 9. `createdAt`, `expiresAt` are positive integers (Unix seconds).
172
+ * 10. `expiresAt > createdAt` (cross-field).
173
+ *
174
+ * Does NOT verify the signature, the chainId↔network mapping, the
175
+ * smart-wallet derivation, the kernel allowlist, or the canonical-
176
+ * empty rule for `buyerEphemeralPubkey` against `expectedPrivacy` —
177
+ * those are the responsibility of higher layers (signature recovery,
178
+ * verifier modules, scheme-consistency in {@link validateSchemeConsistency}
179
+ * for envelopes; setup-side privacy/pubkey consistency is enforced
180
+ * by the setup verifier in Phase 2b).
181
+ *
182
+ * @param obj — value of `unknown` static type (validated at runtime).
183
+ * @returns {@link ValidationResult}.
184
+ */
185
+ export declare function validateSetupSigned(obj: unknown): ValidationResult;
186
+ /**
187
+ * Validate a {@link DeliverySetupWireV1} object's structure.
188
+ *
189
+ * Checks performed (in order):
190
+ *
191
+ * 1. Top-level shape is a non-null object.
192
+ * 2. `signed` validates as a {@link DeliverySetupSignedV1}.
193
+ * 3. `requesterSig` is a string starting with `0x` and of even hex
194
+ * length consistent with a typical 65-byte EIP-712 signature
195
+ * (132 hex chars + `0x` = 134 chars). We accept any `0x`-hex
196
+ * string of plausible signature length; the actual cryptographic
197
+ * validity is checked by `ethers.verifyTypedData` in the
198
+ * recovery helpers — there is no point duplicating that here.
199
+ * 4. `serverMeta`, if present, is an object with `receivedAt`
200
+ * (non-empty string) and `relayId` (non-empty string). Absence
201
+ * is fine — `serverMeta` is set by the relay on read and is not
202
+ * present on freshly built setups.
203
+ *
204
+ * @param obj — value of `unknown` static type.
205
+ * @returns {@link ValidationResult}.
206
+ */
207
+ export declare function validateSetupWire(obj: unknown): ValidationResult;
208
+ /**
209
+ * Validate a {@link DeliveryEnvelopeSignedV1} object's structure and
210
+ * field-level invariants.
211
+ *
212
+ * Checks performed (in order):
213
+ *
214
+ * 1. Top-level shape is a non-null object.
215
+ * 2. `version === 1` exactly.
216
+ * 3. `txId` is a well-formed bytes32 hex string.
217
+ * 4. `chainId` is a positive integer.
218
+ * 5. `kernelAddress`, `providerAddress`, `signerAddress` are valid
219
+ * EVM addresses.
220
+ * 6. `scheme` is one of the {@link DeliveryScheme} discriminants.
221
+ * 7. `providerEphemeralPubkey` is a well-formed bytes32 hex string.
222
+ * 8. `nonce` is a well-formed bytes12 hex string.
223
+ * 9. `payloadHash` is a well-formed bytes32 hex string.
224
+ * 10. `tag` is a well-formed bytes16 hex string.
225
+ * 11. `createdAt` is a positive integer.
226
+ * 12. Scheme/canonical-empty consistency via
227
+ * {@link validateSchemeConsistency}.
228
+ *
229
+ * Does NOT verify the signature, recompute `payloadHash`, or
230
+ * decrypt — those happen in higher layers.
231
+ *
232
+ * @param obj — value of `unknown` static type.
233
+ * @returns {@link ValidationResult}.
234
+ */
235
+ export declare function validateEnvelopeSigned(obj: unknown): ValidationResult;
236
+ /**
237
+ * Validate a {@link DeliveryEnvelopeWireV1} object's structure.
238
+ *
239
+ * Checks performed (in order):
240
+ *
241
+ * 1. Top-level shape is a non-null object.
242
+ * 2. `signed` validates as a {@link DeliveryEnvelopeSignedV1}
243
+ * (which includes the scheme/canonical-empty consistency check).
244
+ * 3. `body` is a string. For `public-v1` this is plaintext UTF-8
245
+ * JSON; for `x25519-aes256gcm-v1` this is base64-encoded
246
+ * ciphertext. We do NOT verify base64-ness here because the
247
+ * receiver will discover any malformed encoding when it
248
+ * recomputes `payloadHash`. We DO insist on non-empty — an
249
+ * empty body would imply the provider sent nothing.
250
+ * 4. `providerSig` is a `0x`-hex string of plausible signature length.
251
+ * 5. `serverMeta`, if present, is well-formed.
252
+ *
253
+ * @param obj — value of `unknown` static type.
254
+ * @returns {@link ValidationResult}.
255
+ */
256
+ export declare function validateEnvelopeWire(obj: unknown): ValidationResult;
257
+ /**
258
+ * Cross-field check enforcing the AIP-16 canonical-empty rule on a
259
+ * {@link DeliveryEnvelopeSignedV1}.
260
+ *
261
+ * Rule:
262
+ *
263
+ * - `scheme === "public-v1"` →
264
+ * `providerEphemeralPubkey === CANONICAL_EMPTY_BYTES32` AND
265
+ * `nonce === CANONICAL_EMPTY_BYTES12` AND
266
+ * `tag === CANONICAL_EMPTY_BYTES16`.
267
+ *
268
+ * - `scheme === "x25519-aes256gcm-v1"` →
269
+ * `providerEphemeralPubkey` MUST NOT be canonical empty (a zero
270
+ * X25519 public key cannot produce a usable shared secret —
271
+ * RFC 7748 §6.1 actually requires implementations to reject it)
272
+ * AND `nonce` MUST NOT be canonical empty (a zero AES-GCM nonce
273
+ * under a real key catastrophically breaks GCM) AND `tag` MUST
274
+ * NOT be canonical empty (a zero 128-bit tag has ~2^-128 chance
275
+ * of matching, so this is effectively a signal that the
276
+ * provider built the envelope incorrectly).
277
+ *
278
+ * This validator assumes the underlying field types are already
279
+ * correct (length, hex shape) — callers must run
280
+ * {@link validateEnvelopeSigned} first, which is also where this is
281
+ * invoked from automatically.
282
+ *
283
+ * @param env — already-shape-validated envelope.
284
+ * @returns {@link ValidationResult}.
285
+ */
286
+ export declare function validateSchemeConsistency(env: DeliveryEnvelopeSignedV1): ValidationResult;
287
+ export type { DeliveryEnvelopeSignedV1, DeliveryEnvelopeWireV1, DeliverySetupSignedV1, DeliverySetupWireV1, };
288
+ //# sourceMappingURL=validate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/delivery/validate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAIH,OAAO,EAIL,KAAK,wBAAwB,EAC7B,KAAK,sBAAsB,EAC3B,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACrB,MAAM,SAAS,CAAC;AAMjB;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,gBAAgB,GACxB;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GACZ;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAgFjC;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,KAAK,MAAM,EAAE,CAE7D;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,KAAK,MAAM,EAAE,CAE7D;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,KAAK,MAAM,EAAE,CAE7D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,KAAK,MAAM,EAAE,CAE7D;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAErD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,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