@x402r/evm 0.0.2 → 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 (89) hide show
  1. package/README.md +20 -16
  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 +17 -13
  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/{escrow → cjs/escrow}/server/index.d.ts +15 -9
  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} +7 -6
  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 -161
  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 -388
  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 -261
  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 -40
  67. package/dist/escrow/client/index.d.ts.map +0 -1
  68. package/dist/escrow/client/index.js +0 -104
  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 -300
  72. package/dist/escrow/facilitator/index.js.map +0 -1
  73. package/dist/escrow/server/index.d.ts.map +0 -1
  74. package/dist/escrow/server/index.js +0 -214
  75. package/dist/escrow/server/index.js.map +0 -1
  76. package/dist/shared/constants.d.ts +0 -112
  77. package/dist/shared/constants.d.ts.map +0 -1
  78. package/dist/shared/constants.js +0 -51
  79. package/dist/shared/constants.js.map +0 -1
  80. package/dist/shared/nonce.d.ts +0 -41
  81. package/dist/shared/nonce.d.ts.map +0 -1
  82. package/dist/shared/nonce.js +0 -154
  83. package/dist/shared/nonce.js.map +0 -1
  84. package/dist/shared/types.d.ts.map +0 -1
  85. package/dist/shared/types.js +0 -21
  86. package/dist/shared/types.js.map +0 -1
  87. package/src/shared/constants.ts +0 -58
  88. package/src/shared/nonce.ts +0 -203
  89. package/src/shared/types.ts +0 -69
@@ -0,0 +1,78 @@
1
+ import { SchemeNetworkServer, MoneyParser, Price, Network, AssetAmount, PaymentRequirements } from '@x402/core/types';
2
+ import { x402ResourceServer } from '@x402/core/server';
3
+
4
+ /**
5
+ * Escrow Scheme - Server
6
+ * Handles price parsing and requirement enhancement for resource servers.
7
+ *
8
+ * Implements x402's SchemeNetworkServer interface so it can be registered
9
+ * on an x402ResourceServer via server.register('eip155:84532', new EscrowServerScheme()).
10
+ */
11
+
12
+ /**
13
+ * Server scheme - handles price parsing and requirement enhancement.
14
+ * Implements x402's SchemeNetworkServer interface.
15
+ */
16
+ declare class EscrowServerScheme implements SchemeNetworkServer {
17
+ readonly scheme = "escrow";
18
+ private moneyParsers;
19
+ /**
20
+ * Register a custom money parser in the parser chain.
21
+ * Multiple parsers can be registered — they will be tried in registration order.
22
+ * Each parser receives a decimal amount (e.g., 1.50 for $1.50).
23
+ * If a parser returns null, the next parser in the chain will be tried.
24
+ * The default parser (USDC) is always the final fallback.
25
+ *
26
+ * @param parser - Custom function to convert amount to AssetAmount (or null to skip)
27
+ * @returns The server instance for chaining
28
+ */
29
+ registerMoneyParser(parser: MoneyParser): EscrowServerScheme;
30
+ /**
31
+ * Parse a price into an x402 AssetAmount.
32
+ *
33
+ * Accepts x402's Price type:
34
+ * - string: "$0.01", "0.01", "10000"
35
+ * - number: 0.01
36
+ * - AssetAmount: { asset: "0x...", amount: "10000" }
37
+ */
38
+ parsePrice(price: Price, network: Network): Promise<AssetAmount>;
39
+ /**
40
+ * Parse Money (string | number) to a decimal number.
41
+ */
42
+ private parseMoneyToDecimal;
43
+ /**
44
+ * Default money conversion — converts decimal amount to the default stablecoin on the network.
45
+ */
46
+ private defaultMoneyConversion;
47
+ /**
48
+ * Enhance payment requirements with facilitator's extra fields.
49
+ *
50
+ * Merges supportedKind.extra (from facilitator's /supported endpoint) into
51
+ * the requirements, so escrow addresses flow from facilitator → merchant
52
+ * requirements automatically.
53
+ */
54
+ enhancePaymentRequirements(requirements: PaymentRequirements, supportedKind: {
55
+ x402Version: number;
56
+ scheme: string;
57
+ network: Network;
58
+ extra?: Record<string, unknown>;
59
+ }, _facilitatorExtensions: string[]): Promise<PaymentRequirements>;
60
+ }
61
+
62
+ interface EvmResourceServerConfig {
63
+ networks?: Network | Network[];
64
+ }
65
+ /**
66
+ * Register escrow server scheme with x402ResourceServer
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * const server = new x402ResourceServer(facilitatorConfig);
71
+ * registerEscrowEvmScheme(server);
72
+ * // or with specific networks:
73
+ * registerEscrowEvmScheme(server, { networks: "eip155:84532" });
74
+ * ```
75
+ */
76
+ declare function registerEscrowEvmScheme(server: x402ResourceServer, config?: EvmResourceServerConfig): x402ResourceServer;
77
+
78
+ export { EscrowServerScheme, type EvmResourceServerConfig, registerEscrowEvmScheme };
@@ -1,3 +1,6 @@
1
+ import { SchemeNetworkServer, MoneyParser, Price, Network, AssetAmount, PaymentRequirements } from '@x402/core/types';
2
+ import { x402ResourceServer } from '@x402/core/server';
3
+
1
4
  /**
2
5
  * Escrow Scheme - Server
3
6
  * Handles price parsing and requirement enhancement for resource servers.
@@ -5,13 +8,12 @@
5
8
  * Implements x402's SchemeNetworkServer interface so it can be registered
6
9
  * on an x402ResourceServer via server.register('eip155:84532', new EscrowServerScheme()).
7
10
  */
8
- import type { AssetAmount, MoneyParser, Network, PaymentRequirements, Price, SchemeNetworkServer } from "@x402/core/types";
9
- import { x402ResourceServer } from "@x402/core/server";
11
+
10
12
  /**
11
13
  * Server scheme - handles price parsing and requirement enhancement.
12
14
  * Implements x402's SchemeNetworkServer interface.
13
15
  */
14
- export declare class EscrowServerScheme implements SchemeNetworkServer {
16
+ declare class EscrowServerScheme implements SchemeNetworkServer {
15
17
  readonly scheme = "escrow";
16
18
  private moneyParsers;
17
19
  /**
@@ -56,17 +58,21 @@ export declare class EscrowServerScheme implements SchemeNetworkServer {
56
58
  extra?: Record<string, unknown>;
57
59
  }, _facilitatorExtensions: string[]): Promise<PaymentRequirements>;
58
60
  }
61
+
62
+ interface EvmResourceServerConfig {
63
+ networks?: Network | Network[];
64
+ }
59
65
  /**
60
66
  * Register escrow server scheme with x402ResourceServer
61
67
  *
62
68
  * @example
63
69
  * ```typescript
64
70
  * const server = new x402ResourceServer(facilitatorConfig);
65
- * registerEscrowServerScheme(server, { networks: "eip155:84532" });
71
+ * registerEscrowEvmScheme(server);
72
+ * // or with specific networks:
73
+ * registerEscrowEvmScheme(server, { networks: "eip155:84532" });
66
74
  * ```
67
75
  */
68
- export declare function registerEscrowServerScheme(server: x402ResourceServer, config: {
69
- networks: Network | Network[];
70
- }): x402ResourceServer;
71
- export type { EscrowExtra, EscrowPayload } from "../../shared/types.js";
72
- //# sourceMappingURL=index.d.ts.map
76
+ declare function registerEscrowEvmScheme(server: x402ResourceServer, config?: EvmResourceServerConfig): x402ResourceServer;
77
+
78
+ export { EscrowServerScheme, type EvmResourceServerConfig, registerEscrowEvmScheme };
@@ -0,0 +1,217 @@
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/server/index.ts
23
+ var server_exports = {};
24
+ __export(server_exports, {
25
+ EscrowServerScheme: () => EscrowServerScheme,
26
+ registerEscrowEvmScheme: () => registerEscrowEvmScheme
27
+ });
28
+ module.exports = __toCommonJS(server_exports);
29
+
30
+ // src/escrow/server/scheme.ts
31
+ var ASSET_INFO = {
32
+ // Base Sepolia
33
+ "eip155:84532": {
34
+ address: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
35
+ name: "USDC",
36
+ version: "2",
37
+ decimals: 6
38
+ },
39
+ // Base mainnet
40
+ "eip155:8453": {
41
+ address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
42
+ name: "USD Coin",
43
+ version: "2",
44
+ decimals: 6
45
+ },
46
+ // Ethereum Sepolia
47
+ "eip155:11155111": {
48
+ address: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238",
49
+ name: "USDC",
50
+ version: "2",
51
+ decimals: 6
52
+ },
53
+ // Ethereum mainnet
54
+ "eip155:1": {
55
+ address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
56
+ name: "USD Coin",
57
+ version: "2",
58
+ decimals: 6
59
+ },
60
+ // Polygon
61
+ "eip155:137": {
62
+ address: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
63
+ name: "USD Coin",
64
+ version: "2",
65
+ decimals: 6
66
+ },
67
+ // Arbitrum
68
+ "eip155:42161": {
69
+ address: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
70
+ name: "USD Coin",
71
+ version: "2",
72
+ decimals: 6
73
+ },
74
+ // Celo
75
+ "eip155:42220": {
76
+ address: "0xcebA9300f2b948710d2653dD7B07f33A8B32118C",
77
+ name: "USD Coin",
78
+ version: "2",
79
+ decimals: 6
80
+ },
81
+ // Monad
82
+ "eip155:143": {
83
+ address: "0x754704Bc059F8C67012fEd69BC8A327a5aafb603",
84
+ name: "USDC",
85
+ version: "2",
86
+ decimals: 6
87
+ },
88
+ // Avalanche
89
+ "eip155:43114": {
90
+ address: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
91
+ name: "USD Coin",
92
+ version: "2",
93
+ decimals: 6
94
+ }
95
+ };
96
+ function convertToTokenAmount(decimalAmount, decimals) {
97
+ const amount = parseFloat(decimalAmount);
98
+ if (isNaN(amount)) {
99
+ throw new Error(`Invalid amount: ${decimalAmount}`);
100
+ }
101
+ const [intPart, decPart = ""] = String(amount).split(".");
102
+ const paddedDec = decPart.padEnd(decimals, "0").slice(0, decimals);
103
+ const tokenAmount = (intPart + paddedDec).replace(/^0+/, "") || "0";
104
+ return tokenAmount;
105
+ }
106
+ var EscrowServerScheme = class {
107
+ constructor() {
108
+ __publicField(this, "scheme", "escrow");
109
+ __publicField(this, "moneyParsers", []);
110
+ }
111
+ /**
112
+ * Register a custom money parser in the parser chain.
113
+ * Multiple parsers can be registered — they will be tried in registration order.
114
+ * Each parser receives a decimal amount (e.g., 1.50 for $1.50).
115
+ * If a parser returns null, the next parser in the chain will be tried.
116
+ * The default parser (USDC) is always the final fallback.
117
+ *
118
+ * @param parser - Custom function to convert amount to AssetAmount (or null to skip)
119
+ * @returns The server instance for chaining
120
+ */
121
+ registerMoneyParser(parser) {
122
+ this.moneyParsers.push(parser);
123
+ return this;
124
+ }
125
+ /**
126
+ * Parse a price into an x402 AssetAmount.
127
+ *
128
+ * Accepts x402's Price type:
129
+ * - string: "$0.01", "0.01", "10000"
130
+ * - number: 0.01
131
+ * - AssetAmount: { asset: "0x...", amount: "10000" }
132
+ */
133
+ async parsePrice(price, network) {
134
+ if (typeof price === "object" && price !== null && "amount" in price) {
135
+ if (!price.asset) {
136
+ throw new Error(`Asset address must be specified for AssetAmount on network ${network}`);
137
+ }
138
+ return {
139
+ amount: price.amount,
140
+ asset: price.asset,
141
+ extra: price.extra || {}
142
+ };
143
+ }
144
+ const numericAmount = this.parseMoneyToDecimal(price);
145
+ for (const parser of this.moneyParsers) {
146
+ const result = await parser(numericAmount, network);
147
+ if (result !== null) {
148
+ return result;
149
+ }
150
+ }
151
+ return this.defaultMoneyConversion(numericAmount, network);
152
+ }
153
+ /**
154
+ * Parse Money (string | number) to a decimal number.
155
+ */
156
+ parseMoneyToDecimal(money) {
157
+ if (typeof money === "number") {
158
+ return money;
159
+ }
160
+ const cleaned = String(money).replace(/[$,]/g, "").trim();
161
+ const amount = parseFloat(cleaned);
162
+ if (isNaN(amount)) {
163
+ throw new Error(`Cannot parse price: ${money}`);
164
+ }
165
+ return amount;
166
+ }
167
+ /**
168
+ * Default money conversion — converts decimal amount to the default stablecoin on the network.
169
+ */
170
+ defaultMoneyConversion(amount, network) {
171
+ const assetInfo = ASSET_INFO[network];
172
+ if (!assetInfo) {
173
+ throw new Error(`No USDC address configured for network: ${network}`);
174
+ }
175
+ const tokenAmount = convertToTokenAmount(String(amount), assetInfo.decimals);
176
+ return {
177
+ asset: assetInfo.address,
178
+ amount: tokenAmount,
179
+ extra: {
180
+ name: assetInfo.name,
181
+ version: assetInfo.version
182
+ }
183
+ };
184
+ }
185
+ /**
186
+ * Enhance payment requirements with facilitator's extra fields.
187
+ *
188
+ * Merges supportedKind.extra (from facilitator's /supported endpoint) into
189
+ * the requirements, so escrow addresses flow from facilitator → merchant
190
+ * requirements automatically.
191
+ */
192
+ async enhancePaymentRequirements(requirements, supportedKind, _facilitatorExtensions) {
193
+ return {
194
+ ...requirements,
195
+ extra: {
196
+ ...supportedKind.extra,
197
+ ...requirements.extra
198
+ }
199
+ };
200
+ }
201
+ };
202
+
203
+ // src/escrow/server/register.ts
204
+ function registerEscrowEvmScheme(server, config = {}) {
205
+ const scheme = new EscrowServerScheme();
206
+ const networks = config.networks ? Array.isArray(config.networks) ? config.networks : [config.networks] : ["eip155:*"];
207
+ for (const network of networks) {
208
+ server.register(network, scheme);
209
+ }
210
+ return server;
211
+ }
212
+ // Annotate the CommonJS export names for ESM import in node:
213
+ 0 && (module.exports = {
214
+ EscrowServerScheme,
215
+ registerEscrowEvmScheme
216
+ });
217
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/escrow/server/index.ts","../../../../src/escrow/server/scheme.ts","../../../../src/escrow/server/register.ts"],"sourcesContent":["export { EscrowServerScheme } from './scheme'\nexport { registerEscrowEvmScheme } from './register'\nexport type { EvmResourceServerConfig } from './register'\n","/**\n * Escrow Scheme - Server\n * Handles price parsing and requirement enhancement for resource servers.\n *\n * Implements x402's SchemeNetworkServer interface so it can be registered\n * on an x402ResourceServer via server.register('eip155:84532', new EscrowServerScheme()).\n */\n\nimport type {\n AssetAmount,\n MoneyParser,\n Network,\n PaymentRequirements,\n Price,\n SchemeNetworkServer,\n} from '@x402/core/types'\n\n/**\n * Asset info including EIP-712 domain parameters per network\n */\nconst ASSET_INFO: Record<\n string,\n { address: string; name: string; version: string; decimals: number }\n> = {\n // Base Sepolia\n 'eip155:84532': {\n address: '0x036CbD53842c5426634e7929541eC2318f3dCF7e',\n name: 'USDC',\n version: '2',\n decimals: 6,\n },\n // Base mainnet\n 'eip155:8453': {\n address: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',\n name: 'USD Coin',\n version: '2',\n decimals: 6,\n },\n // Ethereum Sepolia\n 'eip155:11155111': {\n address: '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238',\n name: 'USDC',\n version: '2',\n decimals: 6,\n },\n // Ethereum mainnet\n 'eip155:1': {\n address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',\n name: 'USD Coin',\n version: '2',\n decimals: 6,\n },\n // Polygon\n 'eip155:137': {\n address: '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359',\n name: 'USD Coin',\n version: '2',\n decimals: 6,\n },\n // Arbitrum\n 'eip155:42161': {\n address: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',\n name: 'USD Coin',\n version: '2',\n decimals: 6,\n },\n // Celo\n 'eip155:42220': {\n address: '0xcebA9300f2b948710d2653dD7B07f33A8B32118C',\n name: 'USD Coin',\n version: '2',\n decimals: 6,\n },\n // Monad\n 'eip155:143': {\n address: '0x754704Bc059F8C67012fEd69BC8A327a5aafb603',\n name: 'USDC',\n version: '2',\n decimals: 6,\n },\n // Avalanche\n 'eip155:43114': {\n address: '0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E',\n name: 'USD Coin',\n version: '2',\n decimals: 6,\n },\n}\n\n/**\n * Convert decimal amount to token units using string-based conversion\n * (e.g., 0.10 -> 100000 for 6-decimal tokens)\n * Avoids floating-point precision issues from BigInt(Math.round(...))\n */\nfunction convertToTokenAmount(decimalAmount: string, decimals: number): string {\n const amount = parseFloat(decimalAmount)\n if (isNaN(amount)) {\n throw new Error(`Invalid amount: ${decimalAmount}`)\n }\n const [intPart, decPart = ''] = String(amount).split('.')\n const paddedDec = decPart.padEnd(decimals, '0').slice(0, decimals)\n const tokenAmount = (intPart + paddedDec).replace(/^0+/, '') || '0'\n return tokenAmount\n}\n\n/**\n * Server scheme - handles price parsing and requirement enhancement.\n * Implements x402's SchemeNetworkServer interface.\n */\nexport class EscrowServerScheme implements SchemeNetworkServer {\n readonly scheme = 'escrow'\n private moneyParsers: MoneyParser[] = []\n\n /**\n * Register a custom money parser in the parser chain.\n * Multiple parsers can be registered — they will be tried in registration order.\n * Each parser receives a decimal amount (e.g., 1.50 for $1.50).\n * If a parser returns null, the next parser in the chain will be tried.\n * The default parser (USDC) is always the final fallback.\n *\n * @param parser - Custom function to convert amount to AssetAmount (or null to skip)\n * @returns The server instance for chaining\n */\n registerMoneyParser(parser: MoneyParser): EscrowServerScheme {\n this.moneyParsers.push(parser)\n return this\n }\n\n /**\n * Parse a price into an x402 AssetAmount.\n *\n * Accepts x402's Price type:\n * - string: \"$0.01\", \"0.01\", \"10000\"\n * - number: 0.01\n * - AssetAmount: { asset: \"0x...\", amount: \"10000\" }\n */\n async parsePrice(price: Price, network: Network): Promise<AssetAmount> {\n // If already an AssetAmount, pass through with validation\n if (typeof price === 'object' && price !== null && 'amount' in price) {\n if (!price.asset) {\n throw new Error(`Asset address must be specified for AssetAmount on network ${network}`)\n }\n return {\n amount: price.amount,\n asset: price.asset,\n extra: price.extra || {},\n }\n }\n\n // Parse Money to decimal number\n const numericAmount = this.parseMoneyToDecimal(price)\n\n // Try each custom money parser in order\n for (const parser of this.moneyParsers) {\n const result = await parser(numericAmount, network)\n if (result !== null) {\n return result\n }\n }\n\n // All custom parsers returned null (or none registered), use default conversion\n return this.defaultMoneyConversion(numericAmount, network)\n }\n\n /**\n * Parse Money (string | number) to a decimal number.\n */\n private parseMoneyToDecimal(money: string | number): number {\n if (typeof money === 'number') {\n return money\n }\n const cleaned = String(money).replace(/[$,]/g, '').trim()\n const amount = parseFloat(cleaned)\n if (isNaN(amount)) {\n throw new Error(`Cannot parse price: ${money}`)\n }\n return amount\n }\n\n /**\n * Default money conversion — converts decimal amount to the default stablecoin on the network.\n */\n private defaultMoneyConversion(amount: number, network: Network): AssetAmount {\n const assetInfo = ASSET_INFO[network]\n if (!assetInfo) {\n throw new Error(`No USDC address configured for network: ${network}`)\n }\n\n const tokenAmount = convertToTokenAmount(String(amount), assetInfo.decimals)\n\n return {\n asset: assetInfo.address,\n amount: tokenAmount,\n extra: {\n name: assetInfo.name,\n version: assetInfo.version,\n },\n }\n }\n\n /**\n * Enhance payment requirements with facilitator's extra fields.\n *\n * Merges supportedKind.extra (from facilitator's /supported endpoint) into\n * the requirements, so escrow addresses flow from facilitator → merchant\n * requirements automatically.\n */\n async enhancePaymentRequirements(\n requirements: PaymentRequirements,\n supportedKind: {\n x402Version: number\n scheme: string\n network: Network\n extra?: Record<string, unknown>\n },\n _facilitatorExtensions: string[],\n ): Promise<PaymentRequirements> {\n return {\n ...requirements,\n extra: {\n ...supportedKind.extra,\n ...requirements.extra,\n },\n }\n }\n}\n","import type { Network } from '@x402/core/types'\nimport { x402ResourceServer } from '@x402/core/server'\nimport { EscrowServerScheme } from './scheme'\n\nexport interface EvmResourceServerConfig {\n networks?: Network | Network[]\n}\n\n/**\n * Register escrow server scheme with x402ResourceServer\n *\n * @example\n * ```typescript\n * const server = new x402ResourceServer(facilitatorConfig);\n * registerEscrowEvmScheme(server);\n * // or with specific networks:\n * registerEscrowEvmScheme(server, { networks: \"eip155:84532\" });\n * ```\n */\nexport function registerEscrowEvmScheme(\n server: x402ResourceServer,\n config: EvmResourceServerConfig = {},\n): x402ResourceServer {\n const scheme = new EscrowServerScheme()\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 server.register(network, scheme)\n }\n return server\n}\n"],"mappings":"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","names":[]}
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  * Type guard for EscrowPayload
3
3
  */
4
- export declare function isEscrowPayload(value: unknown): value is EscrowPayload;
4
+ declare function isEscrowPayload(value: unknown): value is EscrowPayload;
5
5
  /**
6
6
  * Type guard for EscrowExtra
7
7
  */
8
- export declare function isEscrowExtra(value: unknown): value is EscrowExtra;
9
- export interface EscrowExtra {
8
+ declare function isEscrowExtra(value: unknown): value is EscrowExtra;
9
+ interface EscrowExtra {
10
10
  escrowAddress: `0x${string}`;
11
11
  operatorAddress: `0x${string}`;
12
12
  tokenCollector: `0x${string}`;
@@ -20,9 +20,9 @@ export interface EscrowExtra {
20
20
  maxFeeBps?: number;
21
21
  feeReceiver?: `0x${string}`;
22
22
  name: string;
23
- version?: string;
23
+ version: string;
24
24
  }
25
- export interface EscrowPayload {
25
+ interface EscrowPayload {
26
26
  authorization: {
27
27
  from: `0x${string}`;
28
28
  to: `0x${string}`;
@@ -46,4 +46,5 @@ export interface EscrowPayload {
46
46
  salt: `0x${string}`;
47
47
  };
48
48
  }
49
- //# sourceMappingURL=types.d.ts.map
49
+
50
+ export { type EscrowExtra, type EscrowPayload, isEscrowExtra, isEscrowPayload };
@@ -0,0 +1,40 @@
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 __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/escrow/types/index.ts
21
+ var types_exports = {};
22
+ __export(types_exports, {
23
+ isEscrowExtra: () => isEscrowExtra,
24
+ isEscrowPayload: () => isEscrowPayload
25
+ });
26
+ module.exports = __toCommonJS(types_exports);
27
+
28
+ // src/escrow/shared/types.ts
29
+ function isEscrowPayload(value) {
30
+ return typeof value === "object" && value !== null && "authorization" in value && "signature" in value && "paymentInfo" in value;
31
+ }
32
+ function isEscrowExtra(value) {
33
+ return typeof value === "object" && value !== null && "escrowAddress" in value && "operatorAddress" in value && "tokenCollector" in value;
34
+ }
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ isEscrowExtra,
38
+ isEscrowPayload
39
+ });
40
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/escrow/types/index.ts","../../../../src/escrow/shared/types.ts"],"sourcesContent":["export type { EscrowPayload, EscrowExtra } from '../shared/types.js'\nexport { isEscrowPayload, isEscrowExtra } from '../shared/types.js'\n","/**\n * Type guard for EscrowPayload\n */\nexport function isEscrowPayload(value: unknown): value is EscrowPayload {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'authorization' in value &&\n 'signature' in value &&\n 'paymentInfo' in value\n )\n}\n\n/**\n * Type guard for EscrowExtra\n */\nexport function isEscrowExtra(value: unknown): value is EscrowExtra {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'escrowAddress' in value &&\n 'operatorAddress' in value &&\n 'tokenCollector' in value\n )\n}\n\n// EscrowExtra - fields in PaymentRequirements.extra\nexport interface EscrowExtra {\n escrowAddress: `0x${string}`\n operatorAddress: `0x${string}`\n tokenCollector: `0x${string}`\n authorizeAddress?: `0x${string}`\n minDeposit?: string\n maxDeposit?: string\n preApprovalExpirySeconds?: number\n authorizationExpirySeconds?: number\n refundExpirySeconds?: number\n minFeeBps?: number\n maxFeeBps?: number\n feeReceiver?: `0x${string}`\n name: string // EIP-712 domain name (e.g., \"USDC\" for Base USDC)\n version: string // EIP-712 domain version (e.g., \"2\" for USDC)\n}\n\n// EscrowPayload - the payload field in PaymentPayload\nexport interface EscrowPayload {\n authorization: {\n from: `0x${string}`\n to: `0x${string}`\n value: string\n validAfter: string\n validBefore: string\n nonce: `0x${string}`\n }\n signature: `0x${string}`\n paymentInfo: {\n operator: `0x${string}`\n receiver: `0x${string}`\n token: `0x${string}`\n maxAmount: string\n preApprovalExpiry: number\n authorizationExpiry: number\n refundExpiry: number\n minFeeBps: number\n maxFeeBps: number\n feeReceiver: `0x${string}`\n salt: `0x${string}`\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,SAAS,gBAAgB,OAAwC;AACtE,SACE,OAAO,UAAU,YACjB,UAAU,QACV,mBAAmB,SACnB,eAAe,SACf,iBAAiB;AAErB;AAKO,SAAS,cAAc,OAAsC;AAClE,SACE,OAAO,UAAU,YACjB,UAAU,QACV,mBAAmB,SACnB,qBAAqB,SACrB,oBAAoB;AAExB;","names":[]}
@@ -0,0 +1,215 @@
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/index.ts
23
+ var escrow_exports = {};
24
+ __export(escrow_exports, {
25
+ EscrowEvmScheme: () => EscrowEvmScheme
26
+ });
27
+ module.exports = __toCommonJS(escrow_exports);
28
+
29
+ // src/escrow/shared/nonce.ts
30
+ var import_viem = require("viem");
31
+
32
+ // src/escrow/shared/constants.ts
33
+ var ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
34
+ var MAX_UINT48 = 281474976710655;
35
+ var RECEIVE_AUTHORIZATION_TYPES = {
36
+ ReceiveWithAuthorization: [
37
+ { name: "from", type: "address" },
38
+ { name: "to", type: "address" },
39
+ { name: "value", type: "uint256" },
40
+ { name: "validAfter", type: "uint256" },
41
+ { name: "validBefore", type: "uint256" },
42
+ { name: "nonce", type: "bytes32" }
43
+ ]
44
+ };
45
+
46
+ // src/escrow/shared/nonce.ts
47
+ var PAYMENT_INFO_TYPEHASH = (0, import_viem.keccak256)(
48
+ new TextEncoder().encode(
49
+ "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)"
50
+ )
51
+ );
52
+ function computeEscrowNonce(chainId, escrowAddress, paymentInfo) {
53
+ const paymentInfoEncoded = (0, import_viem.encodeAbiParameters)(
54
+ [
55
+ { name: "typehash", type: "bytes32" },
56
+ { name: "operator", type: "address" },
57
+ { name: "payer", type: "address" },
58
+ { name: "receiver", type: "address" },
59
+ { name: "token", type: "address" },
60
+ { name: "maxAmount", type: "uint120" },
61
+ { name: "preApprovalExpiry", type: "uint48" },
62
+ { name: "authorizationExpiry", type: "uint48" },
63
+ { name: "refundExpiry", type: "uint48" },
64
+ { name: "minFeeBps", type: "uint16" },
65
+ { name: "maxFeeBps", type: "uint16" },
66
+ { name: "feeReceiver", type: "address" },
67
+ { name: "salt", type: "uint256" }
68
+ ],
69
+ [
70
+ PAYMENT_INFO_TYPEHASH,
71
+ paymentInfo.operator,
72
+ ZERO_ADDRESS,
73
+ // payer-agnostic
74
+ paymentInfo.receiver,
75
+ paymentInfo.token,
76
+ BigInt(paymentInfo.maxAmount),
77
+ paymentInfo.preApprovalExpiry,
78
+ paymentInfo.authorizationExpiry,
79
+ paymentInfo.refundExpiry,
80
+ paymentInfo.minFeeBps,
81
+ paymentInfo.maxFeeBps,
82
+ paymentInfo.feeReceiver,
83
+ BigInt(paymentInfo.salt)
84
+ ]
85
+ );
86
+ const paymentInfoHash = (0, import_viem.keccak256)(paymentInfoEncoded);
87
+ const outerEncoded = (0, import_viem.encodeAbiParameters)(
88
+ [
89
+ { name: "chainId", type: "uint256" },
90
+ { name: "escrow", type: "address" },
91
+ { name: "paymentInfoHash", type: "bytes32" }
92
+ ],
93
+ [BigInt(chainId), escrowAddress, paymentInfoHash]
94
+ );
95
+ return (0, import_viem.keccak256)(outerEncoded);
96
+ }
97
+ async function signERC3009(signer, authorization, extra, tokenAddress, chainId) {
98
+ const domain = {
99
+ name: extra.name,
100
+ version: extra.version,
101
+ chainId,
102
+ verifyingContract: (0, import_viem.getAddress)(tokenAddress)
103
+ };
104
+ const message = {
105
+ from: (0, import_viem.getAddress)(authorization.from),
106
+ to: (0, import_viem.getAddress)(authorization.to),
107
+ value: BigInt(authorization.value),
108
+ validAfter: BigInt(authorization.validAfter),
109
+ validBefore: BigInt(authorization.validBefore),
110
+ nonce: authorization.nonce
111
+ };
112
+ return signer.signTypedData({
113
+ domain,
114
+ types: RECEIVE_AUTHORIZATION_TYPES,
115
+ primaryType: "ReceiveWithAuthorization",
116
+ message
117
+ });
118
+ }
119
+ function generateSalt() {
120
+ const bytes = new Uint8Array(32);
121
+ crypto.getRandomValues(bytes);
122
+ return (0, import_viem.toHex)(bytes);
123
+ }
124
+
125
+ // src/escrow/shared/utils.ts
126
+ function parseChainId(network) {
127
+ const parts = network.split(":");
128
+ if (parts.length !== 2 || parts[0] !== "eip155") {
129
+ throw new Error(
130
+ `Invalid network format: ${network}. Expected 'eip155:<chainId>'`
131
+ );
132
+ }
133
+ const chainId = parseInt(parts[1], 10);
134
+ if (isNaN(chainId)) {
135
+ throw new Error(`Invalid chainId in network: ${network}`);
136
+ }
137
+ return chainId;
138
+ }
139
+
140
+ // src/escrow/client/scheme.ts
141
+ var EscrowEvmScheme = class {
142
+ constructor(signer) {
143
+ this.signer = signer;
144
+ __publicField(this, "scheme", "escrow");
145
+ }
146
+ async createPaymentPayload(x402Version, requirements, _context) {
147
+ if (x402Version !== 2) {
148
+ throw new Error(
149
+ `Unsupported x402Version: ${x402Version}. Only version 2 is supported.`
150
+ );
151
+ }
152
+ const extra = requirements.extra;
153
+ if (!extra.name) {
154
+ throw new Error(
155
+ `EIP-712 domain parameter 'name' is required in payment requirements for asset ${requirements.asset}`
156
+ );
157
+ }
158
+ if (!extra.version) {
159
+ throw new Error(
160
+ `EIP-712 domain parameter 'version' is required in payment requirements for asset ${requirements.asset}`
161
+ );
162
+ }
163
+ const {
164
+ escrowAddress,
165
+ operatorAddress,
166
+ tokenCollector,
167
+ minFeeBps = 0,
168
+ maxFeeBps = 0,
169
+ feeReceiver,
170
+ preApprovalExpirySeconds,
171
+ refundExpirySeconds,
172
+ authorizationExpirySeconds
173
+ } = extra;
174
+ const chainId = parseChainId(requirements.network);
175
+ const maxAmount = requirements.amount;
176
+ const paymentInfo = {
177
+ operator: operatorAddress,
178
+ receiver: requirements.payTo,
179
+ token: requirements.asset,
180
+ maxAmount,
181
+ preApprovalExpiry: preApprovalExpirySeconds ?? MAX_UINT48,
182
+ authorizationExpiry: authorizationExpirySeconds ?? MAX_UINT48,
183
+ refundExpiry: refundExpirySeconds ?? MAX_UINT48,
184
+ minFeeBps,
185
+ maxFeeBps,
186
+ feeReceiver: feeReceiver ?? operatorAddress,
187
+ salt: generateSalt()
188
+ };
189
+ const nonce = computeEscrowNonce(chainId, escrowAddress, paymentInfo);
190
+ const authorization = {
191
+ from: this.signer.address,
192
+ to: tokenCollector,
193
+ value: maxAmount,
194
+ validAfter: "0",
195
+ validBefore: String(paymentInfo.preApprovalExpiry),
196
+ nonce
197
+ };
198
+ const signature = await signERC3009(
199
+ this.signer,
200
+ authorization,
201
+ extra,
202
+ requirements.asset,
203
+ chainId
204
+ );
205
+ return {
206
+ x402Version,
207
+ payload: { authorization, signature, paymentInfo }
208
+ };
209
+ }
210
+ };
211
+ // Annotate the CommonJS export names for ESM import in node:
212
+ 0 && (module.exports = {
213
+ EscrowEvmScheme
214
+ });
215
+ //# sourceMappingURL=index.cjs.map