@x402r/evm 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/README.md +26 -9
  2. package/dist/cjs/escrow/client/index.cjs +227 -0
  3. package/dist/cjs/escrow/client/index.cjs.map +1 -0
  4. package/dist/cjs/escrow/client/index.d.cts +23 -0
  5. package/dist/cjs/escrow/client/index.d.ts +23 -0
  6. package/dist/cjs/escrow/client/index.js +223 -0
  7. package/dist/cjs/escrow/client/index.js.map +1 -0
  8. package/dist/cjs/escrow/facilitator/index.cjs +359 -0
  9. package/dist/cjs/escrow/facilitator/index.cjs.map +1 -0
  10. package/dist/cjs/escrow/facilitator/index.d.cts +53 -0
  11. package/dist/{escrow → cjs/escrow}/facilitator/index.d.ts +18 -14
  12. package/dist/cjs/escrow/facilitator/index.js +358 -0
  13. package/dist/cjs/escrow/facilitator/index.js.map +1 -0
  14. package/dist/cjs/escrow/server/index.cjs +222 -0
  15. package/dist/cjs/escrow/server/index.cjs.map +1 -0
  16. package/dist/cjs/escrow/server/index.d.cts +78 -0
  17. package/dist/cjs/escrow/server/index.d.ts +78 -0
  18. package/dist/cjs/escrow/server/index.js +217 -0
  19. package/dist/cjs/escrow/server/index.js.map +1 -0
  20. package/dist/{shared/types.d.ts → cjs/escrow/types/index.d.ts} +13 -4
  21. package/dist/cjs/escrow/types/index.js +40 -0
  22. package/dist/cjs/escrow/types/index.js.map +1 -0
  23. package/dist/cjs/index.cjs +215 -0
  24. package/dist/cjs/index.cjs.map +1 -0
  25. package/dist/cjs/index.d.cts +22 -0
  26. package/dist/cjs/index.d.ts +54 -0
  27. package/dist/cjs/index.js +223 -0
  28. package/dist/cjs/index.js.map +1 -0
  29. package/dist/cjs/scheme-CNrmuyp3.d.ts +22 -0
  30. package/dist/esm/chunk-DLIBGHEY.mjs +85 -0
  31. package/dist/esm/chunk-DLIBGHEY.mjs.map +1 -0
  32. package/dist/esm/chunk-IYUU7AJZ.mjs +187 -0
  33. package/dist/esm/chunk-IYUU7AJZ.mjs.map +1 -0
  34. package/dist/esm/chunk-JBHVAJN3.mjs +13 -0
  35. package/dist/esm/chunk-JBHVAJN3.mjs.map +1 -0
  36. package/dist/esm/chunk-NSSMTXJJ.mjs +8 -0
  37. package/dist/esm/chunk-NSSMTXJJ.mjs.map +1 -0
  38. package/dist/esm/escrow/client/index.d.mts +23 -0
  39. package/dist/esm/escrow/client/index.mjs +20 -0
  40. package/dist/esm/escrow/client/index.mjs.map +1 -0
  41. package/dist/esm/escrow/facilitator/index.d.mts +53 -0
  42. package/dist/esm/escrow/facilitator/index.mjs +230 -0
  43. package/dist/esm/escrow/facilitator/index.mjs.map +1 -0
  44. package/dist/esm/escrow/server/index.d.mts +78 -0
  45. package/dist/esm/escrow/server/index.mjs +191 -0
  46. package/dist/esm/escrow/server/index.mjs.map +1 -0
  47. package/dist/esm/index.d.mts +54 -0
  48. package/dist/esm/index.mjs +15 -0
  49. package/dist/esm/index.mjs.map +1 -0
  50. package/dist/esm/scheme-CNrmuyp3.d.mts +22 -0
  51. package/package.json +42 -16
  52. package/src/escrow/client/index.ts +3 -88
  53. package/src/escrow/client/register.ts +33 -0
  54. package/src/escrow/client/scheme.ts +107 -0
  55. package/src/escrow/facilitator/index.ts +3 -204
  56. package/src/escrow/facilitator/register.ts +33 -0
  57. package/src/escrow/facilitator/scheme.ts +289 -0
  58. package/src/escrow/index.ts +3 -0
  59. package/src/escrow/server/index.ts +3 -133
  60. package/src/escrow/server/register.ts +34 -0
  61. package/src/escrow/server/scheme.ts +226 -0
  62. package/src/escrow/shared/constants.ts +65 -0
  63. package/src/escrow/shared/nonce.ts +175 -0
  64. package/src/escrow/shared/types.ts +69 -0
  65. package/src/escrow/shared/utils.ts +16 -0
  66. package/dist/escrow/client/index.d.ts +0 -24
  67. package/dist/escrow/client/index.d.ts.map +0 -1
  68. package/dist/escrow/client/index.js +0 -45
  69. package/dist/escrow/client/index.js.map +0 -1
  70. package/dist/escrow/facilitator/index.d.ts.map +0 -1
  71. package/dist/escrow/facilitator/index.js +0 -146
  72. package/dist/escrow/facilitator/index.js.map +0 -1
  73. package/dist/escrow/server/index.d.ts +0 -68
  74. package/dist/escrow/server/index.d.ts.map +0 -1
  75. package/dist/escrow/server/index.js +0 -80
  76. package/dist/escrow/server/index.js.map +0 -1
  77. package/dist/shared/constants.d.ts +0 -98
  78. package/dist/shared/constants.d.ts.map +0 -1
  79. package/dist/shared/constants.js +0 -39
  80. package/dist/shared/constants.js.map +0 -1
  81. package/dist/shared/nonce.d.ts +0 -41
  82. package/dist/shared/nonce.d.ts.map +0 -1
  83. package/dist/shared/nonce.js +0 -155
  84. package/dist/shared/nonce.js.map +0 -1
  85. package/dist/shared/types.d.ts.map +0 -1
  86. package/dist/shared/types.js +0 -2
  87. package/dist/shared/types.js.map +0 -1
  88. package/src/shared/constants.ts +0 -43
  89. package/src/shared/nonce.ts +0 -202
  90. package/src/shared/types.ts +0 -43
package/README.md CHANGED
@@ -13,26 +13,43 @@ npm install @x402r/evm
13
13
  ### Client — Create payment payloads
14
14
 
15
15
  ```typescript
16
- import { createPaymentPayload } from "@x402r/evm/escrow/client";
16
+ import { EscrowEvmScheme, registerEscrowEvmScheme } from '@x402r/evm/escrow/client'
17
+ import { x402Client } from '@x402/core/client'
17
18
 
18
- const payload = await createPaymentPayload(requirements, walletClient);
19
+ const client = new x402Client()
20
+ registerEscrowEvmScheme(client, { signer })
21
+ // or with specific networks:
22
+ registerEscrowEvmScheme(client, { signer, networks: 'eip155:84532' })
19
23
  ```
20
24
 
21
25
  ### Server — Register with x402 resource server
22
26
 
23
27
  ```typescript
24
- import { EscrowServerScheme } from "@x402r/evm/escrow/server";
28
+ import { EscrowServerScheme, registerEscrowEvmScheme } from '@x402r/evm/escrow/server'
29
+ import { x402ResourceServer } from '@x402/core/server'
25
30
 
26
- const scheme = new EscrowServerScheme();
27
- server.register("eip155:84532", scheme);
31
+ const server = new x402ResourceServer(facilitatorConfig)
32
+ registerEscrowEvmScheme(server)
33
+ // or with specific networks:
34
+ registerEscrowEvmScheme(server, { networks: 'eip155:84532' })
35
+ ```
36
+
37
+ ### Facilitator — Verify and settle payments
38
+
39
+ ```typescript
40
+ import { EscrowFacilitatorScheme, registerEscrowEvmScheme } from '@x402r/evm/escrow/facilitator'
41
+ import { x402Facilitator } from '@x402/core/facilitator'
42
+
43
+ const facilitator = new x402Facilitator()
44
+ registerEscrowEvmScheme(facilitator, { signer, networks: 'eip155:84532' })
28
45
  ```
29
46
 
30
47
  ## Exports
31
48
 
32
- - `@x402r/evm/escrow/client` — `createPaymentPayload()`, `EscrowScheme`
33
- - `@x402r/evm/escrow/server` — `EscrowServerScheme`
34
- - `@x402r/evm/escrow/facilitator` — Settlement and verification
35
- - `@x402r/evm/escrow/types` — `EscrowExtra`, `EscrowPayload`
49
+ - `@x402r/evm` — `EscrowEvmScheme` (client scheme class)
50
+ - `@x402r/evm/escrow/client` — `EscrowEvmScheme`, `registerEscrowEvmScheme()`, `EvmClientConfig`
51
+ - `@x402r/evm/escrow/server` — `EscrowServerScheme`, `registerEscrowEvmScheme()`, `EvmResourceServerConfig`
52
+ - `@x402r/evm/escrow/facilitator` — `EscrowFacilitatorScheme`, `registerEscrowEvmScheme()`, `EvmFacilitatorConfig`
36
53
 
37
54
  ## Links
38
55
 
@@ -0,0 +1,227 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
+
22
+ // src/escrow/client/index.ts
23
+ var client_exports = {};
24
+ __export(client_exports, {
25
+ EscrowEvmScheme: () => EscrowEvmScheme,
26
+ registerEscrowEvmScheme: () => registerEscrowEvmScheme
27
+ });
28
+ module.exports = __toCommonJS(client_exports);
29
+
30
+ // src/escrow/shared/nonce.ts
31
+ var import_viem = require("viem");
32
+
33
+ // src/escrow/shared/constants.ts
34
+ var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
35
+ var MAX_UINT48 = 281474976710655;
36
+ var RECEIVE_AUTHORIZATION_TYPES = {
37
+ ReceiveWithAuthorization: [
38
+ { name: "from", type: "address" },
39
+ { name: "to", type: "address" },
40
+ { name: "value", type: "uint256" },
41
+ { name: "validAfter", type: "uint256" },
42
+ { name: "validBefore", type: "uint256" },
43
+ { name: "nonce", type: "bytes32" }
44
+ ]
45
+ };
46
+
47
+ // src/escrow/shared/nonce.ts
48
+ var PAYMENT_INFO_TYPEHASH = (0, import_viem.keccak256)(
49
+ new TextEncoder().encode(
50
+ "PaymentInfo(address operator,address payer,address receiver,address token,uint120 maxAmount,uint48 preApprovalExpiry,uint48 authorizationExpiry,uint48 refundExpiry,uint16 minFeeBps,uint16 maxFeeBps,address feeReceiver,uint256 salt)"
51
+ )
52
+ );
53
+ function computeEscrowNonce(chainId, escrowAddress, paymentInfo) {
54
+ const paymentInfoEncoded = (0, import_viem.encodeAbiParameters)(
55
+ [
56
+ { name: "typehash", type: "bytes32" },
57
+ { name: "operator", type: "address" },
58
+ { name: "payer", type: "address" },
59
+ { name: "receiver", type: "address" },
60
+ { name: "token", type: "address" },
61
+ { name: "maxAmount", type: "uint120" },
62
+ { name: "preApprovalExpiry", type: "uint48" },
63
+ { name: "authorizationExpiry", type: "uint48" },
64
+ { name: "refundExpiry", type: "uint48" },
65
+ { name: "minFeeBps", type: "uint16" },
66
+ { name: "maxFeeBps", type: "uint16" },
67
+ { name: "feeReceiver", type: "address" },
68
+ { name: "salt", type: "uint256" }
69
+ ],
70
+ [
71
+ PAYMENT_INFO_TYPEHASH,
72
+ paymentInfo.operator,
73
+ ZERO_ADDRESS,
74
+ // payer-agnostic
75
+ paymentInfo.receiver,
76
+ paymentInfo.token,
77
+ BigInt(paymentInfo.maxAmount),
78
+ paymentInfo.preApprovalExpiry,
79
+ paymentInfo.authorizationExpiry,
80
+ paymentInfo.refundExpiry,
81
+ paymentInfo.minFeeBps,
82
+ paymentInfo.maxFeeBps,
83
+ paymentInfo.feeReceiver,
84
+ BigInt(paymentInfo.salt)
85
+ ]
86
+ );
87
+ const paymentInfoHash = (0, import_viem.keccak256)(paymentInfoEncoded);
88
+ const outerEncoded = (0, import_viem.encodeAbiParameters)(
89
+ [
90
+ { name: "chainId", type: "uint256" },
91
+ { name: "escrow", type: "address" },
92
+ { name: "paymentInfoHash", type: "bytes32" }
93
+ ],
94
+ [BigInt(chainId), escrowAddress, paymentInfoHash]
95
+ );
96
+ return (0, import_viem.keccak256)(outerEncoded);
97
+ }
98
+ async function signERC3009(signer, authorization, extra, tokenAddress, chainId) {
99
+ const domain = {
100
+ name: extra.name,
101
+ version: extra.version,
102
+ chainId,
103
+ verifyingContract: (0, import_viem.getAddress)(tokenAddress)
104
+ };
105
+ const message = {
106
+ from: (0, import_viem.getAddress)(authorization.from),
107
+ to: (0, import_viem.getAddress)(authorization.to),
108
+ value: BigInt(authorization.value),
109
+ validAfter: BigInt(authorization.validAfter),
110
+ validBefore: BigInt(authorization.validBefore),
111
+ nonce: authorization.nonce
112
+ };
113
+ return signer.signTypedData({
114
+ domain,
115
+ types: RECEIVE_AUTHORIZATION_TYPES,
116
+ primaryType: "ReceiveWithAuthorization",
117
+ message
118
+ });
119
+ }
120
+ function generateSalt() {
121
+ const bytes = new Uint8Array(32);
122
+ crypto.getRandomValues(bytes);
123
+ return (0, import_viem.toHex)(bytes);
124
+ }
125
+
126
+ // src/escrow/shared/utils.ts
127
+ function parseChainId(network) {
128
+ const parts = network.split(":");
129
+ if (parts.length !== 2 || parts[0] !== "eip155") {
130
+ throw new Error(
131
+ `Invalid network format: ${network}. Expected 'eip155:<chainId>'`
132
+ );
133
+ }
134
+ const chainId = parseInt(parts[1], 10);
135
+ if (isNaN(chainId)) {
136
+ throw new Error(`Invalid chainId in network: ${network}`);
137
+ }
138
+ return chainId;
139
+ }
140
+
141
+ // src/escrow/client/scheme.ts
142
+ var EscrowEvmScheme = class {
143
+ constructor(signer) {
144
+ this.signer = signer;
145
+ __publicField(this, "scheme", "escrow");
146
+ }
147
+ async createPaymentPayload(x402Version, requirements, _context) {
148
+ if (x402Version !== 2) {
149
+ throw new Error(
150
+ `Unsupported x402Version: ${x402Version}. Only version 2 is supported.`
151
+ );
152
+ }
153
+ const extra = requirements.extra;
154
+ if (!extra.name) {
155
+ throw new Error(
156
+ `EIP-712 domain parameter 'name' is required in payment requirements for asset ${requirements.asset}`
157
+ );
158
+ }
159
+ if (!extra.version) {
160
+ throw new Error(
161
+ `EIP-712 domain parameter 'version' is required in payment requirements for asset ${requirements.asset}`
162
+ );
163
+ }
164
+ const {
165
+ escrowAddress,
166
+ operatorAddress,
167
+ tokenCollector,
168
+ minFeeBps = 0,
169
+ maxFeeBps = 0,
170
+ feeReceiver,
171
+ preApprovalExpirySeconds,
172
+ refundExpirySeconds,
173
+ authorizationExpirySeconds
174
+ } = extra;
175
+ const chainId = parseChainId(requirements.network);
176
+ const maxAmount = requirements.amount;
177
+ const paymentInfo = {
178
+ operator: operatorAddress,
179
+ receiver: requirements.payTo,
180
+ token: requirements.asset,
181
+ maxAmount,
182
+ preApprovalExpiry: preApprovalExpirySeconds ?? MAX_UINT48,
183
+ authorizationExpiry: authorizationExpirySeconds ?? MAX_UINT48,
184
+ refundExpiry: refundExpirySeconds ?? MAX_UINT48,
185
+ minFeeBps,
186
+ maxFeeBps,
187
+ feeReceiver: feeReceiver ?? operatorAddress,
188
+ salt: generateSalt()
189
+ };
190
+ const nonce = computeEscrowNonce(chainId, escrowAddress, paymentInfo);
191
+ const authorization = {
192
+ from: this.signer.address,
193
+ to: tokenCollector,
194
+ value: maxAmount,
195
+ validAfter: "0",
196
+ validBefore: String(paymentInfo.preApprovalExpiry),
197
+ nonce
198
+ };
199
+ const signature = await signERC3009(
200
+ this.signer,
201
+ authorization,
202
+ extra,
203
+ requirements.asset,
204
+ chainId
205
+ );
206
+ return {
207
+ x402Version,
208
+ payload: { authorization, signature, paymentInfo }
209
+ };
210
+ }
211
+ };
212
+
213
+ // src/escrow/client/register.ts
214
+ function registerEscrowEvmScheme(client, config) {
215
+ const scheme = new EscrowEvmScheme(config.signer);
216
+ const networks = config.networks ? Array.isArray(config.networks) ? config.networks : [config.networks] : ["eip155:*"];
217
+ for (const network of networks) {
218
+ client.register(network, scheme);
219
+ }
220
+ return client;
221
+ }
222
+ // Annotate the CommonJS export names for ESM import in node:
223
+ 0 && (module.exports = {
224
+ EscrowEvmScheme,
225
+ registerEscrowEvmScheme
226
+ });
227
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/escrow/client/index.ts","../../../../src/escrow/shared/nonce.ts","../../../../src/escrow/shared/constants.ts","../../../../src/escrow/shared/utils.ts","../../../../src/escrow/client/scheme.ts","../../../../src/escrow/client/register.ts"],"sourcesContent":["export { EscrowEvmScheme } from \"./scheme\";\nexport { registerEscrowEvmScheme } from \"./register\";\nexport type { EvmClientConfig } from \"./register\";\n","/**\n * Nonce computation and ERC-3009 signing utilities\n * Adapted from @agentokratia/x402-escrow (MIT)\n */\n\nimport { encodeAbiParameters, getAddress, keccak256, toHex } from \"viem\";\nimport type { ClientEvmSigner } from \"@x402/evm\";\nimport { ZERO_ADDRESS, PAYMENT_INFO_COMPONENTS, RECEIVE_AUTHORIZATION_TYPES } from \"./constants\";\nimport type { EscrowExtra, EscrowPayload } from \"./types\";\n\n/**\n * PaymentInfo typehash - must match AuthCaptureEscrow.PAYMENT_INFO_TYPEHASH\n */\nconst PAYMENT_INFO_TYPEHASH = keccak256(\n new TextEncoder().encode(\n \"PaymentInfo(address operator,address payer,address receiver,address token,uint120 maxAmount,uint48 preApprovalExpiry,uint48 authorizationExpiry,uint48 refundExpiry,uint16 minFeeBps,uint16 maxFeeBps,address feeReceiver,uint256 salt)\",\n ),\n);\n\n/**\n * Compute escrow nonce for ERC-3009 authorization\n * Must match AuthCaptureEscrow.getHash() with payer=address(0)\n */\nexport function computeEscrowNonce(\n chainId: number,\n escrowAddress: `0x${string}`,\n paymentInfo: EscrowPayload[\"paymentInfo\"],\n): `0x${string}` {\n // Step 1: Encode paymentInfo with payer=0 (payer-agnostic)\n const paymentInfoEncoded = encodeAbiParameters(\n [\n { name: \"typehash\", type: \"bytes32\" },\n { name: \"operator\", type: \"address\" },\n { name: \"payer\", type: \"address\" },\n { name: \"receiver\", type: \"address\" },\n { name: \"token\", type: \"address\" },\n { name: \"maxAmount\", type: \"uint120\" },\n { name: \"preApprovalExpiry\", type: \"uint48\" },\n { name: \"authorizationExpiry\", type: \"uint48\" },\n { name: \"refundExpiry\", type: \"uint48\" },\n { name: \"minFeeBps\", type: \"uint16\" },\n { name: \"maxFeeBps\", type: \"uint16\" },\n { name: \"feeReceiver\", type: \"address\" },\n { name: \"salt\", type: \"uint256\" },\n ],\n [\n PAYMENT_INFO_TYPEHASH,\n paymentInfo.operator,\n ZERO_ADDRESS, // payer-agnostic\n paymentInfo.receiver,\n paymentInfo.token,\n BigInt(paymentInfo.maxAmount),\n paymentInfo.preApprovalExpiry,\n paymentInfo.authorizationExpiry,\n paymentInfo.refundExpiry,\n paymentInfo.minFeeBps,\n paymentInfo.maxFeeBps,\n paymentInfo.feeReceiver,\n BigInt(paymentInfo.salt),\n ],\n );\n const paymentInfoHash = keccak256(paymentInfoEncoded);\n\n // Step 2: Encode (chainId, escrow, paymentInfoHash) and hash\n const outerEncoded = encodeAbiParameters(\n [\n { name: \"chainId\", type: \"uint256\" },\n { name: \"escrow\", type: \"address\" },\n { name: \"paymentInfoHash\", type: \"bytes32\" },\n ],\n [BigInt(chainId), escrowAddress, paymentInfoHash],\n );\n\n return keccak256(outerEncoded);\n}\n\n/**\n * Sign ERC-3009 ReceiveWithAuthorization\n * Note: receiveWithAuthorization uses a different primary type than transferWithAuthorization\n */\nexport async function signERC3009(\n signer: ClientEvmSigner,\n authorization: EscrowPayload[\"authorization\"],\n extra: EscrowExtra,\n tokenAddress: `0x${string}`,\n chainId: number,\n): Promise<`0x${string}`> {\n // EIP-712 domain - name must match the token's EIP-712 domain\n // (e.g., \"USDC\" for Base USDC, not \"USD Coin\")\n const domain = {\n name: extra.name,\n version: extra.version,\n chainId,\n verifyingContract: getAddress(tokenAddress),\n };\n\n const message = {\n from: getAddress(authorization.from),\n to: getAddress(authorization.to),\n value: BigInt(authorization.value),\n validAfter: BigInt(authorization.validAfter),\n validBefore: BigInt(authorization.validBefore),\n nonce: authorization.nonce,\n };\n\n return signer.signTypedData({\n domain,\n types: RECEIVE_AUTHORIZATION_TYPES,\n primaryType: \"ReceiveWithAuthorization\",\n message,\n });\n}\n\n/**\n * Verify ERC-3009 signature (facilitator-side)\n * @param signer - The signer with verifyTypedData method\n * @param authorization - ERC-3009 authorization data\n * @param signature - The signature to verify\n * @param extra - Extra configuration including chainId\n * @param tokenAddress - The token contract address (verifyingContract for EIP-712)\n */\nexport async function verifyERC3009Signature(\n signer: {\n verifyTypedData: (args: {\n address: `0x${string}`;\n domain: Record<string, unknown>;\n types: Record<string, unknown>;\n primaryType: string;\n message: Record<string, unknown>;\n signature: `0x${string}`;\n }) => Promise<boolean>;\n },\n authorization: EscrowPayload[\"authorization\"],\n signature: `0x${string}`,\n extra: EscrowExtra & { chainId: number },\n tokenAddress: `0x${string}`,\n): Promise<boolean> {\n const domain = {\n name: extra.name,\n version: extra.version,\n chainId: extra.chainId,\n verifyingContract: getAddress(tokenAddress),\n };\n\n const message = {\n from: getAddress(authorization.from),\n to: getAddress(authorization.to),\n value: BigInt(authorization.value),\n validAfter: BigInt(authorization.validAfter),\n validBefore: BigInt(authorization.validBefore),\n nonce: authorization.nonce,\n };\n\n try {\n return await signer.verifyTypedData({\n address: getAddress(authorization.from),\n domain,\n types: RECEIVE_AUTHORIZATION_TYPES,\n primaryType: \"ReceiveWithAuthorization\",\n message,\n signature,\n });\n } catch {\n return false;\n }\n}\n\n/**\n * Generate random salt for paymentInfo\n */\nexport function generateSalt(): `0x${string}` {\n const bytes = new Uint8Array(32);\n crypto.getRandomValues(bytes);\n return toHex(bytes);\n}\n","export const ZERO_ADDRESS =\n \"0x0000000000000000000000000000000000000000\" as const;\nexport const MAX_UINT48 = 281474976710655;\nexport const MAX_UINT32 = 4294967295;\n\n// PaymentInfo struct for AuthCaptureEscrow (matches commerce-payments contract)\nexport const PAYMENT_INFO_COMPONENTS = [\n { name: \"operator\", type: \"address\" },\n { name: \"payer\", type: \"address\" },\n { name: \"receiver\", type: \"address\" },\n { name: \"token\", type: \"address\" },\n { name: \"maxAmount\", type: \"uint120\" },\n { name: \"preApprovalExpiry\", type: \"uint48\" },\n { name: \"authorizationExpiry\", type: \"uint48\" },\n { name: \"refundExpiry\", type: \"uint48\" },\n { name: \"minFeeBps\", type: \"uint16\" },\n { name: \"maxFeeBps\", type: \"uint16\" },\n { name: \"feeReceiver\", type: \"address\" },\n { name: \"salt\", type: \"uint256\" },\n] as const;\n\nexport const OPERATOR_ABI = [\n {\n name: \"authorize\",\n type: \"function\",\n stateMutability: \"nonpayable\",\n inputs: [\n {\n name: \"paymentInfo\",\n type: \"tuple\",\n components: PAYMENT_INFO_COMPONENTS,\n },\n { name: \"amount\", type: \"uint256\" },\n { name: \"tokenCollector\", type: \"address\" },\n { name: \"collectorData\", type: \"bytes\" },\n ],\n outputs: [],\n },\n] as const;\n\n// ERC-3009 TransferWithAuthorization type hash\nexport const TRANSFER_WITH_AUTHORIZATION_TYPEHASH =\n \"0x7c7c6cdb67a18743f49ec6fa9b35f50d52ed05cbed4cc592e13b44501c1a2267\" as const;\n\n// ERC-3009 ReceiveWithAuthorization EIP-712 types\nexport const RECEIVE_AUTHORIZATION_TYPES = {\n ReceiveWithAuthorization: [\n { name: \"from\", type: \"address\" },\n { name: \"to\", type: \"address\" },\n { name: \"value\", type: \"uint256\" },\n { name: \"validAfter\", type: \"uint256\" },\n { name: \"validBefore\", type: \"uint256\" },\n { name: \"nonce\", type: \"bytes32\" },\n ],\n} as const;\n\n// ERC-20 balanceOf ABI for balance checks\nexport const ERC20_BALANCE_OF_ABI = [\n {\n name: \"balanceOf\",\n type: \"function\",\n stateMutability: \"view\",\n inputs: [{ name: \"account\", type: \"address\" }],\n outputs: [{ name: \"balance\", type: \"uint256\" }],\n },\n] as const;\n","/**\n * Parse chainId from CAIP-2 network identifier\n * @param network - CAIP-2 network identifier (e.g., 'eip155:84532')\n * @returns The chain ID as a number\n */\nexport function parseChainId(network: string): number {\n const parts = network.split(\":\");\n if (parts.length !== 2 || parts[0] !== \"eip155\") {\n throw new Error(\n `Invalid network format: ${network}. Expected 'eip155:<chainId>'`,\n );\n }\n const chainId = parseInt(parts[1], 10);\n if (isNaN(chainId)) {\n throw new Error(`Invalid chainId in network: ${network}`);\n }\n return chainId;\n}\n","/**\n * Escrow Scheme - Client\n * Creates payment payloads for escrow payments.\n *\n * Implements x402's SchemeNetworkClient interface so it can be registered\n * on an x402Client via client.register('eip155:84532', new EscrowEvmScheme(signer)).\n */\n\nimport type {\n PaymentPayloadContext,\n PaymentPayloadResult,\n PaymentRequirements,\n SchemeNetworkClient,\n} from \"@x402/core/types\";\nimport type { ClientEvmSigner } from \"@x402/evm\";\nimport {\n computeEscrowNonce,\n signERC3009,\n generateSalt,\n} from \"../shared/nonce\";\nimport { MAX_UINT48 } from \"../shared/constants\";\nimport type { EscrowExtra } from \"../shared/types\";\nimport { parseChainId } from \"../shared/utils\";\n\n/**\n * Escrow Client Scheme - implements x402's SchemeNetworkClient\n */\nexport class EscrowEvmScheme implements SchemeNetworkClient {\n readonly scheme = \"escrow\";\n\n constructor(private readonly signer: ClientEvmSigner) {}\n\n async createPaymentPayload(\n x402Version: number,\n requirements: PaymentRequirements,\n _context?: PaymentPayloadContext,\n ): Promise<PaymentPayloadResult> {\n if (x402Version !== 2) {\n throw new Error(\n `Unsupported x402Version: ${x402Version}. Only version 2 is supported.`,\n );\n }\n\n const extra = requirements.extra as unknown as EscrowExtra;\n\n // Validate required EIP-712 domain parameters (M3, M10)\n if (!extra.name) {\n throw new Error(\n `EIP-712 domain parameter 'name' is required in payment requirements for asset ${requirements.asset}`,\n );\n }\n if (!extra.version) {\n throw new Error(\n `EIP-712 domain parameter 'version' is required in payment requirements for asset ${requirements.asset}`,\n );\n }\n\n const {\n escrowAddress,\n operatorAddress,\n tokenCollector,\n minFeeBps = 0,\n maxFeeBps = 0,\n feeReceiver,\n preApprovalExpirySeconds,\n refundExpirySeconds,\n authorizationExpirySeconds,\n } = extra;\n\n const chainId = parseChainId(requirements.network);\n const maxAmount = requirements.amount;\n\n const paymentInfo = {\n operator: operatorAddress,\n receiver: requirements.payTo as `0x${string}`,\n token: requirements.asset as `0x${string}`,\n maxAmount,\n preApprovalExpiry: preApprovalExpirySeconds ?? MAX_UINT48,\n authorizationExpiry: authorizationExpirySeconds ?? MAX_UINT48,\n refundExpiry: refundExpirySeconds ?? MAX_UINT48,\n minFeeBps,\n maxFeeBps,\n feeReceiver: feeReceiver ?? operatorAddress,\n salt: generateSalt(),\n };\n\n const nonce = computeEscrowNonce(chainId, escrowAddress, paymentInfo);\n\n // ERC-3009 authorization - validBefore MUST match what contract passes to receiveWithAuthorization\n // The contract uses paymentInfo.preApprovalExpiry as validBefore\n const authorization = {\n from: this.signer.address,\n to: tokenCollector,\n value: maxAmount,\n validAfter: \"0\",\n validBefore: String(paymentInfo.preApprovalExpiry),\n nonce,\n };\n\n const signature = await signERC3009(\n this.signer,\n authorization,\n extra,\n requirements.asset as `0x${string}`,\n chainId,\n );\n\n return {\n x402Version,\n payload: { authorization, signature, paymentInfo },\n };\n }\n}\n","import type { Network } from \"@x402/core/types\";\nimport type { ClientEvmSigner } from \"@x402/evm\";\nimport { x402Client } from \"@x402/core/client\";\nimport { EscrowEvmScheme } from \"./scheme\";\n\nexport interface EvmClientConfig {\n signer: ClientEvmSigner;\n networks?: Network | Network[];\n}\n\n/**\n * Register escrow client scheme with x402Client\n *\n * @example\n * ```typescript\n * const client = new x402Client();\n * registerEscrowEvmScheme(client, { signer });\n * // or with specific networks:\n * registerEscrowEvmScheme(client, { signer, networks: \"eip155:84532\" });\n * ```\n */\nexport function registerEscrowEvmScheme(\n client: x402Client,\n config: EvmClientConfig,\n): x402Client {\n const scheme = new EscrowEvmScheme(config.signer);\n const networks = config.networks\n ? Array.isArray(config.networks)\n ? config.networks\n : [config.networks]\n : [\"eip155:*\" as Network];\n for (const network of networks) {\n client.register(network, scheme);\n }\n return client;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKA,kBAAkE;;;ACL3D,IAAM,eACX;AACK,IAAM,aAAa;AA2CnB,IAAM,8BAA8B;AAAA,EACzC,0BAA0B;AAAA,IACxB,EAAE,MAAM,QAAQ,MAAM,UAAU;AAAA,IAChC,EAAE,MAAM,MAAM,MAAM,UAAU;AAAA,IAC9B,EAAE,MAAM,SAAS,MAAM,UAAU;AAAA,IACjC,EAAE,MAAM,cAAc,MAAM,UAAU;AAAA,IACtC,EAAE,MAAM,eAAe,MAAM,UAAU;AAAA,IACvC,EAAE,MAAM,SAAS,MAAM,UAAU;AAAA,EACnC;AACF;;;ADzCA,IAAM,4BAAwB;AAAA,EAC5B,IAAI,YAAY,EAAE;AA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P,CAAC,OAAO,QAAQ,IAClB,CAAC,UAAqB;AAC1B,aAAW,WAAW,UAAU;AAC9B,WAAO,SAAS,SAAS,MAAM;AAAA,EACjC;AACA,SAAO;AACT;","names":[]}
@@ -0,0 +1,23 @@
1
+ export { EscrowEvmScheme } from '../../index.cjs';
2
+ import { Network } from '@x402/core/types';
3
+ import { ClientEvmSigner } from '@x402/evm';
4
+ import { x402Client } from '@x402/core/client';
5
+
6
+ interface EvmClientConfig {
7
+ signer: ClientEvmSigner;
8
+ networks?: Network | Network[];
9
+ }
10
+ /**
11
+ * Register escrow client scheme with x402Client
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const client = new x402Client();
16
+ * registerEscrowEvmScheme(client, { signer });
17
+ * // or with specific networks:
18
+ * registerEscrowEvmScheme(client, { signer, networks: "eip155:84532" });
19
+ * ```
20
+ */
21
+ declare function registerEscrowEvmScheme(client: x402Client, config: EvmClientConfig): x402Client;
22
+
23
+ export { type EvmClientConfig, registerEscrowEvmScheme };
@@ -0,0 +1,23 @@
1
+ export { E as EscrowEvmScheme } from '../../scheme-CNrmuyp3.js';
2
+ import { Network } from '@x402/core/types';
3
+ import { ClientEvmSigner } from '@x402/evm';
4
+ import { x402Client } from '@x402/core/client';
5
+
6
+ interface EvmClientConfig {
7
+ signer: ClientEvmSigner;
8
+ networks?: Network | Network[];
9
+ }
10
+ /**
11
+ * Register escrow client scheme with x402Client
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const client = new x402Client();
16
+ * registerEscrowEvmScheme(client, { signer });
17
+ * // or with specific networks:
18
+ * registerEscrowEvmScheme(client, { signer, networks: "eip155:84532" });
19
+ * ```
20
+ */
21
+ declare function registerEscrowEvmScheme(client: x402Client, config: EvmClientConfig): x402Client;
22
+
23
+ export { type EvmClientConfig, registerEscrowEvmScheme };
@@ -0,0 +1,223 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
+
22
+ // src/escrow/client/index.ts
23
+ var client_exports = {};
24
+ __export(client_exports, {
25
+ EscrowEvmScheme: () => EscrowEvmScheme,
26
+ registerEscrowEvmScheme: () => registerEscrowEvmScheme
27
+ });
28
+ module.exports = __toCommonJS(client_exports);
29
+
30
+ // src/escrow/shared/nonce.ts
31
+ var import_viem = require("viem");
32
+
33
+ // src/escrow/shared/constants.ts
34
+ var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
35
+ var MAX_UINT48 = 281474976710655;
36
+ var RECEIVE_AUTHORIZATION_TYPES = {
37
+ ReceiveWithAuthorization: [
38
+ { name: "from", type: "address" },
39
+ { name: "to", type: "address" },
40
+ { name: "value", type: "uint256" },
41
+ { name: "validAfter", type: "uint256" },
42
+ { name: "validBefore", type: "uint256" },
43
+ { name: "nonce", type: "bytes32" }
44
+ ]
45
+ };
46
+
47
+ // src/escrow/shared/nonce.ts
48
+ var PAYMENT_INFO_TYPEHASH = (0, import_viem.keccak256)(
49
+ new TextEncoder().encode(
50
+ "PaymentInfo(address operator,address payer,address receiver,address token,uint120 maxAmount,uint48 preApprovalExpiry,uint48 authorizationExpiry,uint48 refundExpiry,uint16 minFeeBps,uint16 maxFeeBps,address feeReceiver,uint256 salt)"
51
+ )
52
+ );
53
+ function computeEscrowNonce(chainId, escrowAddress, paymentInfo) {
54
+ const paymentInfoEncoded = (0, import_viem.encodeAbiParameters)(
55
+ [
56
+ { name: "typehash", type: "bytes32" },
57
+ { name: "operator", type: "address" },
58
+ { name: "payer", type: "address" },
59
+ { name: "receiver", type: "address" },
60
+ { name: "token", type: "address" },
61
+ { name: "maxAmount", type: "uint120" },
62
+ { name: "preApprovalExpiry", type: "uint48" },
63
+ { name: "authorizationExpiry", type: "uint48" },
64
+ { name: "refundExpiry", type: "uint48" },
65
+ { name: "minFeeBps", type: "uint16" },
66
+ { name: "maxFeeBps", type: "uint16" },
67
+ { name: "feeReceiver", type: "address" },
68
+ { name: "salt", type: "uint256" }
69
+ ],
70
+ [
71
+ PAYMENT_INFO_TYPEHASH,
72
+ paymentInfo.operator,
73
+ ZERO_ADDRESS,
74
+ // payer-agnostic
75
+ paymentInfo.receiver,
76
+ paymentInfo.token,
77
+ BigInt(paymentInfo.maxAmount),
78
+ paymentInfo.preApprovalExpiry,
79
+ paymentInfo.authorizationExpiry,
80
+ paymentInfo.refundExpiry,
81
+ paymentInfo.minFeeBps,
82
+ paymentInfo.maxFeeBps,
83
+ paymentInfo.feeReceiver,
84
+ BigInt(paymentInfo.salt)
85
+ ]
86
+ );
87
+ const paymentInfoHash = (0, import_viem.keccak256)(paymentInfoEncoded);
88
+ const outerEncoded = (0, import_viem.encodeAbiParameters)(
89
+ [
90
+ { name: "chainId", type: "uint256" },
91
+ { name: "escrow", type: "address" },
92
+ { name: "paymentInfoHash", type: "bytes32" }
93
+ ],
94
+ [BigInt(chainId), escrowAddress, paymentInfoHash]
95
+ );
96
+ return (0, import_viem.keccak256)(outerEncoded);
97
+ }
98
+ async function signERC3009(signer, authorization, extra, tokenAddress, chainId) {
99
+ const domain = {
100
+ name: extra.name,
101
+ version: extra.version,
102
+ chainId,
103
+ verifyingContract: (0, import_viem.getAddress)(tokenAddress)
104
+ };
105
+ const message = {
106
+ from: (0, import_viem.getAddress)(authorization.from),
107
+ to: (0, import_viem.getAddress)(authorization.to),
108
+ value: BigInt(authorization.value),
109
+ validAfter: BigInt(authorization.validAfter),
110
+ validBefore: BigInt(authorization.validBefore),
111
+ nonce: authorization.nonce
112
+ };
113
+ return signer.signTypedData({
114
+ domain,
115
+ types: RECEIVE_AUTHORIZATION_TYPES,
116
+ primaryType: "ReceiveWithAuthorization",
117
+ message
118
+ });
119
+ }
120
+ function generateSalt() {
121
+ const bytes = new Uint8Array(32);
122
+ crypto.getRandomValues(bytes);
123
+ return (0, import_viem.toHex)(bytes);
124
+ }
125
+
126
+ // src/escrow/shared/utils.ts
127
+ function parseChainId(network) {
128
+ const parts = network.split(":");
129
+ if (parts.length !== 2 || parts[0] !== "eip155") {
130
+ throw new Error(`Invalid network format: ${network}. Expected 'eip155:<chainId>'`);
131
+ }
132
+ const chainId = parseInt(parts[1], 10);
133
+ if (isNaN(chainId)) {
134
+ throw new Error(`Invalid chainId in network: ${network}`);
135
+ }
136
+ return chainId;
137
+ }
138
+
139
+ // src/escrow/client/scheme.ts
140
+ var EscrowEvmScheme = class {
141
+ constructor(signer) {
142
+ this.signer = signer;
143
+ __publicField(this, "scheme", "escrow");
144
+ }
145
+ async createPaymentPayload(x402Version, requirements, _context) {
146
+ if (x402Version !== 2) {
147
+ throw new Error(`Unsupported x402Version: ${x402Version}. Only version 2 is supported.`);
148
+ }
149
+ const extra = requirements.extra;
150
+ if (!extra.name) {
151
+ throw new Error(
152
+ `EIP-712 domain parameter 'name' is required in payment requirements for asset ${requirements.asset}`
153
+ );
154
+ }
155
+ if (!extra.version) {
156
+ throw new Error(
157
+ `EIP-712 domain parameter 'version' is required in payment requirements for asset ${requirements.asset}`
158
+ );
159
+ }
160
+ const {
161
+ escrowAddress,
162
+ operatorAddress,
163
+ tokenCollector,
164
+ minFeeBps = 0,
165
+ maxFeeBps = 0,
166
+ feeReceiver,
167
+ preApprovalExpirySeconds,
168
+ refundExpirySeconds,
169
+ authorizationExpirySeconds
170
+ } = extra;
171
+ const chainId = parseChainId(requirements.network);
172
+ const maxAmount = requirements.amount;
173
+ const paymentInfo = {
174
+ operator: operatorAddress,
175
+ receiver: requirements.payTo,
176
+ token: requirements.asset,
177
+ maxAmount,
178
+ preApprovalExpiry: preApprovalExpirySeconds ?? MAX_UINT48,
179
+ authorizationExpiry: authorizationExpirySeconds ?? MAX_UINT48,
180
+ refundExpiry: refundExpirySeconds ?? MAX_UINT48,
181
+ minFeeBps,
182
+ maxFeeBps,
183
+ feeReceiver: feeReceiver ?? operatorAddress,
184
+ salt: generateSalt()
185
+ };
186
+ const nonce = computeEscrowNonce(chainId, escrowAddress, paymentInfo);
187
+ const authorization = {
188
+ from: this.signer.address,
189
+ to: tokenCollector,
190
+ value: maxAmount,
191
+ validAfter: "0",
192
+ validBefore: String(paymentInfo.preApprovalExpiry),
193
+ nonce
194
+ };
195
+ const signature = await signERC3009(
196
+ this.signer,
197
+ authorization,
198
+ extra,
199
+ requirements.asset,
200
+ chainId
201
+ );
202
+ return {
203
+ x402Version,
204
+ payload: { authorization, signature, paymentInfo }
205
+ };
206
+ }
207
+ };
208
+
209
+ // src/escrow/client/register.ts
210
+ function registerEscrowEvmScheme(client, config) {
211
+ const scheme = new EscrowEvmScheme(config.signer);
212
+ const networks = config.networks ? Array.isArray(config.networks) ? config.networks : [config.networks] : ["eip155:*"];
213
+ for (const network of networks) {
214
+ client.register(network, scheme);
215
+ }
216
+ return client;
217
+ }
218
+ // Annotate the CommonJS export names for ESM import in node:
219
+ 0 && (module.exports = {
220
+ EscrowEvmScheme,
221
+ registerEscrowEvmScheme
222
+ });
223
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/escrow/client/index.ts","../../../../src/escrow/shared/nonce.ts","../../../../src/escrow/shared/constants.ts","../../../../src/escrow/shared/utils.ts","../../../../src/escrow/client/scheme.ts","../../../../src/escrow/client/register.ts"],"sourcesContent":["export { EscrowEvmScheme } from './scheme'\nexport { registerEscrowEvmScheme } from './register'\nexport type { EvmClientConfig } from './register'\n","/**\n * Nonce computation and ERC-3009 signing utilities\n * Adapted from @agentokratia/x402-escrow (MIT)\n */\n\nimport { encodeAbiParameters, getAddress, keccak256, toHex } from 'viem'\nimport type { ClientEvmSigner } from '@x402/evm'\nimport { ZERO_ADDRESS, RECEIVE_AUTHORIZATION_TYPES } from './constants'\nimport type { EscrowExtra, EscrowPayload } from './types'\n\n/**\n * PaymentInfo typehash - must match AuthCaptureEscrow.PAYMENT_INFO_TYPEHASH\n */\nconst PAYMENT_INFO_TYPEHASH = keccak256(\n new TextEncoder().encode(\n 'PaymentInfo(address operator,address payer,address receiver,address token,uint120 maxAmount,uint48 preApprovalExpiry,uint48 authorizationExpiry,uint48 refundExpiry,uint16 minFeeBps,uint16 maxFeeBps,address feeReceiver,uint256 salt)',\n ),\n)\n\n/**\n * Compute escrow nonce for ERC-3009 authorization\n * Must match AuthCaptureEscrow.getHash() with payer=address(0)\n */\nexport function computeEscrowNonce(\n chainId: number,\n escrowAddress: `0x${string}`,\n paymentInfo: EscrowPayload['paymentInfo'],\n): `0x${string}` {\n // Step 1: Encode paymentInfo with payer=0 (payer-agnostic)\n const paymentInfoEncoded = encodeAbiParameters(\n [\n { name: 'typehash', type: 'bytes32' },\n { name: 'operator', type: 'address' },\n { name: 'payer', type: 'address' },\n { name: 'receiver', type: 'address' },\n { name: 'token', type: 'address' },\n { name: 'maxAmount', type: 'uint120' },\n { name: 'preApprovalExpiry', type: 'uint48' },\n { name: 'authorizationExpiry', type: 'uint48' },\n { name: 'refundExpiry', type: 'uint48' },\n { name: 'minFeeBps', type: 'uint16' },\n { name: 'maxFeeBps', type: 'uint16' },\n { name: 'feeReceiver', type: 'address' },\n { name: 'salt', type: 'uint256' },\n ],\n [\n PAYMENT_INFO_TYPEHASH,\n paymentInfo.operator,\n ZERO_ADDRESS, // payer-agnostic\n paymentInfo.receiver,\n paymentInfo.token,\n BigInt(paymentInfo.maxAmount),\n paymentInfo.preApprovalExpiry,\n paymentInfo.authorizationExpiry,\n paymentInfo.refundExpiry,\n paymentInfo.minFeeBps,\n paymentInfo.maxFeeBps,\n paymentInfo.feeReceiver,\n BigInt(paymentInfo.salt),\n ],\n )\n const paymentInfoHash = keccak256(paymentInfoEncoded)\n\n // Step 2: Encode (chainId, escrow, paymentInfoHash) and hash\n const outerEncoded = encodeAbiParameters(\n [\n { name: 'chainId', type: 'uint256' },\n { name: 'escrow', type: 'address' },\n { name: 'paymentInfoHash', type: 'bytes32' },\n ],\n [BigInt(chainId), escrowAddress, paymentInfoHash],\n )\n\n return keccak256(outerEncoded)\n}\n\n/**\n * Sign ERC-3009 ReceiveWithAuthorization\n * Note: receiveWithAuthorization uses a different primary type than transferWithAuthorization\n */\nexport async function signERC3009(\n signer: ClientEvmSigner,\n authorization: EscrowPayload['authorization'],\n extra: EscrowExtra,\n tokenAddress: `0x${string}`,\n chainId: number,\n): Promise<`0x${string}`> {\n // EIP-712 domain - name must match the token's EIP-712 domain\n // (e.g., \"USDC\" for Base USDC, not \"USD Coin\")\n const domain = {\n name: extra.name,\n version: extra.version,\n chainId,\n verifyingContract: getAddress(tokenAddress),\n }\n\n const message = {\n from: getAddress(authorization.from),\n to: getAddress(authorization.to),\n value: BigInt(authorization.value),\n validAfter: BigInt(authorization.validAfter),\n validBefore: BigInt(authorization.validBefore),\n nonce: authorization.nonce,\n }\n\n return signer.signTypedData({\n domain,\n types: RECEIVE_AUTHORIZATION_TYPES,\n primaryType: 'ReceiveWithAuthorization',\n message,\n })\n}\n\n/**\n * Verify ERC-3009 signature (facilitator-side)\n * @param signer - The signer with verifyTypedData method\n * @param authorization - ERC-3009 authorization data\n * @param signature - The signature to verify\n * @param extra - Extra configuration including chainId\n * @param tokenAddress - The token contract address (verifyingContract for EIP-712)\n */\nexport async function verifyERC3009Signature(\n signer: {\n verifyTypedData: (_args: {\n address: `0x${string}`\n domain: Record<string, unknown>\n types: Record<string, unknown>\n primaryType: string\n message: Record<string, unknown>\n signature: `0x${string}`\n }) => Promise<boolean>\n },\n authorization: EscrowPayload['authorization'],\n signature: `0x${string}`,\n extra: EscrowExtra & { chainId: number },\n tokenAddress: `0x${string}`,\n): Promise<boolean> {\n const domain = {\n name: extra.name,\n version: extra.version,\n chainId: extra.chainId,\n verifyingContract: getAddress(tokenAddress),\n }\n\n const message = {\n from: getAddress(authorization.from),\n to: getAddress(authorization.to),\n value: BigInt(authorization.value),\n validAfter: BigInt(authorization.validAfter),\n validBefore: BigInt(authorization.validBefore),\n nonce: authorization.nonce,\n }\n\n try {\n return await signer.verifyTypedData({\n address: getAddress(authorization.from),\n domain,\n types: RECEIVE_AUTHORIZATION_TYPES,\n primaryType: 'ReceiveWithAuthorization',\n message,\n signature,\n })\n } catch {\n return false\n }\n}\n\n/**\n * Generate random salt for paymentInfo\n */\nexport function generateSalt(): `0x${string}` {\n const bytes = new Uint8Array(32)\n crypto.getRandomValues(bytes)\n return toHex(bytes)\n}\n","export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' as const\nexport const MAX_UINT48 = 281474976710655\nexport const MAX_UINT32 = 4294967295\n\n// PaymentInfo struct for AuthCaptureEscrow (matches commerce-payments contract)\nexport const PAYMENT_INFO_COMPONENTS = [\n { name: 'operator', type: 'address' },\n { name: 'payer', type: 'address' },\n { name: 'receiver', type: 'address' },\n { name: 'token', type: 'address' },\n { name: 'maxAmount', type: 'uint120' },\n { name: 'preApprovalExpiry', type: 'uint48' },\n { name: 'authorizationExpiry', type: 'uint48' },\n { name: 'refundExpiry', type: 'uint48' },\n { name: 'minFeeBps', type: 'uint16' },\n { name: 'maxFeeBps', type: 'uint16' },\n { name: 'feeReceiver', type: 'address' },\n { name: 'salt', type: 'uint256' },\n] as const\n\nexport const OPERATOR_ABI = [\n {\n name: 'authorize',\n type: 'function',\n stateMutability: 'nonpayable',\n inputs: [\n {\n name: 'paymentInfo',\n type: 'tuple',\n components: PAYMENT_INFO_COMPONENTS,\n },\n { name: 'amount', type: 'uint256' },\n { name: 'tokenCollector', type: 'address' },\n { name: 'collectorData', type: 'bytes' },\n ],\n outputs: [],\n },\n] as const\n\n// ERC-3009 TransferWithAuthorization type hash\nexport const TRANSFER_WITH_AUTHORIZATION_TYPEHASH =\n '0x7c7c6cdb67a18743f49ec6fa9b35f50d52ed05cbed4cc592e13b44501c1a2267' as const\n\n// ERC-3009 ReceiveWithAuthorization EIP-712 types\nexport const RECEIVE_AUTHORIZATION_TYPES = {\n ReceiveWithAuthorization: [\n { name: 'from', type: 'address' },\n { name: 'to', type: 'address' },\n { name: 'value', type: 'uint256' },\n { name: 'validAfter', type: 'uint256' },\n { name: 'validBefore', type: 'uint256' },\n { name: 'nonce', type: 'bytes32' },\n ],\n} as const\n\n// ERC-20 balanceOf ABI for balance checks\nexport const ERC20_BALANCE_OF_ABI = [\n {\n name: 'balanceOf',\n type: 'function',\n stateMutability: 'view',\n inputs: [{ name: 'account', type: 'address' }],\n outputs: [{ name: 'balance', type: 'uint256' }],\n },\n] as const\n","/**\n * Parse chainId from CAIP-2 network identifier\n * @param network - CAIP-2 network identifier (e.g., 'eip155:84532')\n * @returns The chain ID as a number\n */\nexport function parseChainId(network: string): number {\n const parts = network.split(':')\n if (parts.length !== 2 || parts[0] !== 'eip155') {\n throw new Error(`Invalid network format: ${network}. Expected 'eip155:<chainId>'`)\n }\n const chainId = parseInt(parts[1], 10)\n if (isNaN(chainId)) {\n throw new Error(`Invalid chainId in network: ${network}`)\n }\n return chainId\n}\n","/**\n * Escrow Scheme - Client\n * Creates payment payloads for escrow payments.\n *\n * Implements x402's SchemeNetworkClient interface so it can be registered\n * on an x402Client via client.register('eip155:84532', new EscrowEvmScheme(signer)).\n */\n\nimport type {\n PaymentPayloadContext,\n PaymentPayloadResult,\n PaymentRequirements,\n SchemeNetworkClient,\n} from '@x402/core/types'\nimport type { ClientEvmSigner } from '@x402/evm'\nimport { computeEscrowNonce, signERC3009, generateSalt } from '../shared/nonce'\nimport { MAX_UINT48 } from '../shared/constants'\nimport type { EscrowExtra } from '../shared/types'\nimport { parseChainId } from '../shared/utils'\n\n/**\n * Escrow Client Scheme - implements x402's SchemeNetworkClient\n */\nexport class EscrowEvmScheme implements SchemeNetworkClient {\n readonly scheme = 'escrow'\n\n constructor(private readonly signer: ClientEvmSigner) {}\n\n async createPaymentPayload(\n x402Version: number,\n requirements: PaymentRequirements,\n _context?: PaymentPayloadContext,\n ): Promise<PaymentPayloadResult> {\n if (x402Version !== 2) {\n throw new Error(`Unsupported x402Version: ${x402Version}. Only version 2 is supported.`)\n }\n\n const extra = requirements.extra as unknown as EscrowExtra\n\n // Validate required EIP-712 domain parameters (M3, M10)\n if (!extra.name) {\n throw new Error(\n `EIP-712 domain parameter 'name' is required in payment requirements for asset ${requirements.asset}`,\n )\n }\n if (!extra.version) {\n throw new Error(\n `EIP-712 domain parameter 'version' is required in payment requirements for asset ${requirements.asset}`,\n )\n }\n\n const {\n escrowAddress,\n operatorAddress,\n tokenCollector,\n minFeeBps = 0,\n maxFeeBps = 0,\n feeReceiver,\n preApprovalExpirySeconds,\n refundExpirySeconds,\n authorizationExpirySeconds,\n } = extra\n\n const chainId = parseChainId(requirements.network)\n const maxAmount = requirements.amount\n\n const paymentInfo = {\n operator: operatorAddress,\n receiver: requirements.payTo as `0x${string}`,\n token: requirements.asset as `0x${string}`,\n maxAmount,\n preApprovalExpiry: preApprovalExpirySeconds ?? MAX_UINT48,\n authorizationExpiry: authorizationExpirySeconds ?? MAX_UINT48,\n refundExpiry: refundExpirySeconds ?? MAX_UINT48,\n minFeeBps,\n maxFeeBps,\n feeReceiver: feeReceiver ?? operatorAddress,\n salt: generateSalt(),\n }\n\n const nonce = computeEscrowNonce(chainId, escrowAddress, paymentInfo)\n\n // ERC-3009 authorization - validBefore MUST match what contract passes to receiveWithAuthorization\n // The contract uses paymentInfo.preApprovalExpiry as validBefore\n const authorization = {\n from: this.signer.address,\n to: tokenCollector,\n value: maxAmount,\n validAfter: '0',\n validBefore: String(paymentInfo.preApprovalExpiry),\n nonce,\n }\n\n const signature = await signERC3009(\n this.signer,\n authorization,\n extra,\n requirements.asset as `0x${string}`,\n chainId,\n )\n\n return {\n x402Version,\n payload: { authorization, signature, paymentInfo },\n }\n }\n}\n","import type { Network } from '@x402/core/types'\nimport type { ClientEvmSigner } from '@x402/evm'\nimport { x402Client } from '@x402/core/client'\nimport { EscrowEvmScheme } from './scheme'\n\nexport interface EvmClientConfig {\n signer: ClientEvmSigner\n networks?: Network | Network[]\n}\n\n/**\n * Register escrow client scheme with x402Client\n *\n * @example\n * ```typescript\n * const client = new x402Client();\n * registerEscrowEvmScheme(client, { signer });\n * // or with specific networks:\n * registerEscrowEvmScheme(client, { signer, networks: \"eip155:84532\" });\n * ```\n */\nexport function registerEscrowEvmScheme(client: x402Client, config: EvmClientConfig): x402Client {\n const scheme = new EscrowEvmScheme(config.signer)\n const networks = config.networks\n ? Array.isArray(config.networks)\n ? config.networks\n : [config.networks]\n : ['eip155:*' as Network]\n for (const network of networks) {\n client.register(network, scheme)\n }\n return client\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKA,kBAAkE;;;ACL3D,IAAM,eAAe;AACrB,IAAM,aAAa;AA2CnB,IAAM,8BAA8B;AAAA,EACzC,0BAA0B;AAAA,IACxB,EAAE,MAAM,QAAQ,MAAM,UAAU;AAAA,IAChC,EAAE,MAAM,MAAM,MAAM,UAAU;AAAA,IAC9B,EAAE,MAAM,SAAS,MAAM,UAAU;AAAA,IACjC,EAAE,MAAM,cAAc,MAAM,UAAU;AAAA,IACtC,EAAE,MAAM,eAAe,MAAM,UAAU;AAAA,IACvC,EAAE,MAAM,SAAS,MAAM,UAAU;AAAA,EACnC;AACF;;;ADxCA,IAAM,4BAAwB;AAAA,EAC5B,IAAI,YAAY,E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