@bankofai/x402-evm 1.0.0-beta.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 (176) hide show
  1. package/README.md +172 -0
  2. package/dist/cjs/auth-capture/client/index.d.ts +44 -0
  3. package/dist/cjs/auth-capture/client/index.js +298 -0
  4. package/dist/cjs/auth-capture/client/index.js.map +1 -0
  5. package/dist/cjs/batch-settlement/client/file-storage.d.ts +47 -0
  6. package/dist/cjs/batch-settlement/client/file-storage.js +116 -0
  7. package/dist/cjs/batch-settlement/client/file-storage.js.map +1 -0
  8. package/dist/cjs/batch-settlement/client/index.d.ts +111 -0
  9. package/dist/cjs/batch-settlement/client/index.js +1565 -0
  10. package/dist/cjs/batch-settlement/client/index.js.map +1 -0
  11. package/dist/cjs/batch-settlement/facilitator/index.d.ts +72 -0
  12. package/dist/cjs/batch-settlement/facilitator/index.js +2102 -0
  13. package/dist/cjs/batch-settlement/facilitator/index.js.map +1 -0
  14. package/dist/cjs/batch-settlement/server/file-storage.d.ts +53 -0
  15. package/dist/cjs/batch-settlement/server/file-storage.js +181 -0
  16. package/dist/cjs/batch-settlement/server/file-storage.js.map +1 -0
  17. package/dist/cjs/batch-settlement/server/index.d.ts +491 -0
  18. package/dist/cjs/batch-settlement/server/index.js +1978 -0
  19. package/dist/cjs/batch-settlement/server/index.js.map +1 -0
  20. package/dist/cjs/batch-settlement/server/redis-storage.d.ts +87 -0
  21. package/dist/cjs/batch-settlement/server/redis-storage.js +181 -0
  22. package/dist/cjs/batch-settlement/server/redis-storage.js.map +1 -0
  23. package/dist/cjs/client/agent-wallet.d.ts +69 -0
  24. package/dist/cjs/client/agent-wallet.js +84 -0
  25. package/dist/cjs/client/agent-wallet.js.map +1 -0
  26. package/dist/cjs/exact/client/index.d.ts +63 -0
  27. package/dist/cjs/exact/client/index.js +739 -0
  28. package/dist/cjs/exact/client/index.js.map +1 -0
  29. package/dist/cjs/exact/facilitator/index.d.ts +141 -0
  30. package/dist/cjs/exact/facilitator/index.js +1989 -0
  31. package/dist/cjs/exact/facilitator/index.js.map +1 -0
  32. package/dist/cjs/exact/server/index.d.ts +118 -0
  33. package/dist/cjs/exact/server/index.js +326 -0
  34. package/dist/cjs/exact/server/index.js.map +1 -0
  35. package/dist/cjs/exact/v1/client/index.d.ts +38 -0
  36. package/dist/cjs/exact/v1/client/index.js +193 -0
  37. package/dist/cjs/exact/v1/client/index.js.map +1 -0
  38. package/dist/cjs/exact/v1/facilitator/index.d.ts +84 -0
  39. package/dist/cjs/exact/v1/facilitator/index.js +739 -0
  40. package/dist/cjs/exact/v1/facilitator/index.js.map +1 -0
  41. package/dist/cjs/facilitator/agent-wallet.d.ts +109 -0
  42. package/dist/cjs/facilitator/agent-wallet.js +105 -0
  43. package/dist/cjs/facilitator/agent-wallet.js.map +1 -0
  44. package/dist/cjs/index.d.ts +338 -0
  45. package/dist/cjs/index.js +2860 -0
  46. package/dist/cjs/index.js.map +1 -0
  47. package/dist/cjs/permit2-DK5A8alk.d.ts +729 -0
  48. package/dist/cjs/permit2-DhJRUcgY.d.ts +729 -0
  49. package/dist/cjs/rpc-DULZzRne.d.ts +13 -0
  50. package/dist/cjs/scheme-7ehldYoO.d.ts +307 -0
  51. package/dist/cjs/scheme-BjBJzHF7.d.ts +307 -0
  52. package/dist/cjs/scheme-DWgpkDgz.d.ts +47 -0
  53. package/dist/cjs/signer-BFelv8DL.d.ts +170 -0
  54. package/dist/cjs/storage-6W5MO46W.d.ts +50 -0
  55. package/dist/cjs/storage-CHNote8s.d.ts +81 -0
  56. package/dist/cjs/storage-DjCv5IPh.d.ts +81 -0
  57. package/dist/cjs/types-CKd3Xoi1.d.ts +180 -0
  58. package/dist/cjs/types-DIt9uAUy.d.ts +180 -0
  59. package/dist/cjs/upto/client/index.d.ts +34 -0
  60. package/dist/cjs/upto/client/index.js +509 -0
  61. package/dist/cjs/upto/client/index.js.map +1 -0
  62. package/dist/cjs/upto/facilitator/index.d.ts +54 -0
  63. package/dist/cjs/upto/facilitator/index.js +1313 -0
  64. package/dist/cjs/upto/facilitator/index.js.map +1 -0
  65. package/dist/cjs/upto/server/index.d.ts +69 -0
  66. package/dist/cjs/upto/server/index.js +296 -0
  67. package/dist/cjs/upto/server/index.js.map +1 -0
  68. package/dist/cjs/v1/index.d.ts +40 -0
  69. package/dist/cjs/v1/index.js +199 -0
  70. package/dist/cjs/v1/index.js.map +1 -0
  71. package/dist/esm/auth-capture/client/index.d.mts +44 -0
  72. package/dist/esm/auth-capture/client/index.mjs +8 -0
  73. package/dist/esm/auth-capture/client/index.mjs.map +1 -0
  74. package/dist/esm/batch-settlement/client/file-storage.d.mts +47 -0
  75. package/dist/esm/batch-settlement/client/file-storage.mjs +63 -0
  76. package/dist/esm/batch-settlement/client/file-storage.mjs.map +1 -0
  77. package/dist/esm/batch-settlement/client/index.d.mts +111 -0
  78. package/dist/esm/batch-settlement/client/index.mjs +58 -0
  79. package/dist/esm/batch-settlement/client/index.mjs.map +1 -0
  80. package/dist/esm/batch-settlement/facilitator/index.d.mts +72 -0
  81. package/dist/esm/batch-settlement/facilitator/index.mjs +1252 -0
  82. package/dist/esm/batch-settlement/facilitator/index.mjs.map +1 -0
  83. package/dist/esm/batch-settlement/server/file-storage.d.mts +53 -0
  84. package/dist/esm/batch-settlement/server/file-storage.mjs +128 -0
  85. package/dist/esm/batch-settlement/server/file-storage.mjs.map +1 -0
  86. package/dist/esm/batch-settlement/server/index.d.mts +491 -0
  87. package/dist/esm/batch-settlement/server/index.mjs +1640 -0
  88. package/dist/esm/batch-settlement/server/index.mjs.map +1 -0
  89. package/dist/esm/batch-settlement/server/redis-storage.d.mts +87 -0
  90. package/dist/esm/batch-settlement/server/redis-storage.mjs +156 -0
  91. package/dist/esm/batch-settlement/server/redis-storage.mjs.map +1 -0
  92. package/dist/esm/chunk-2EUQTNJO.mjs +38 -0
  93. package/dist/esm/chunk-2EUQTNJO.mjs.map +1 -0
  94. package/dist/esm/chunk-3WZF6722.mjs +36 -0
  95. package/dist/esm/chunk-3WZF6722.mjs.map +1 -0
  96. package/dist/esm/chunk-E4Z7PNXC.mjs +275 -0
  97. package/dist/esm/chunk-E4Z7PNXC.mjs.map +1 -0
  98. package/dist/esm/chunk-GQVMVP4N.mjs +911 -0
  99. package/dist/esm/chunk-GQVMVP4N.mjs.map +1 -0
  100. package/dist/esm/chunk-H2EYJIZL.mjs +489 -0
  101. package/dist/esm/chunk-H2EYJIZL.mjs.map +1 -0
  102. package/dist/esm/chunk-H3KPLYGI.mjs +152 -0
  103. package/dist/esm/chunk-H3KPLYGI.mjs.map +1 -0
  104. package/dist/esm/chunk-HYABYUBD.mjs +432 -0
  105. package/dist/esm/chunk-HYABYUBD.mjs.map +1 -0
  106. package/dist/esm/chunk-I2DVUHM5.mjs +123 -0
  107. package/dist/esm/chunk-I2DVUHM5.mjs.map +1 -0
  108. package/dist/esm/chunk-JK7SLLF7.mjs +34 -0
  109. package/dist/esm/chunk-JK7SLLF7.mjs.map +1 -0
  110. package/dist/esm/chunk-JNT7C46S.mjs +352 -0
  111. package/dist/esm/chunk-JNT7C46S.mjs.map +1 -0
  112. package/dist/esm/chunk-MACPBXCT.mjs +415 -0
  113. package/dist/esm/chunk-MACPBXCT.mjs.map +1 -0
  114. package/dist/esm/chunk-P3QOX3QZ.mjs +113 -0
  115. package/dist/esm/chunk-P3QOX3QZ.mjs.map +1 -0
  116. package/dist/esm/chunk-QVATVA3J.mjs +47 -0
  117. package/dist/esm/chunk-QVATVA3J.mjs.map +1 -0
  118. package/dist/esm/chunk-SHJFA25H.mjs +159 -0
  119. package/dist/esm/chunk-SHJFA25H.mjs.map +1 -0
  120. package/dist/esm/chunk-TW7Z65AO.mjs +34 -0
  121. package/dist/esm/chunk-TW7Z65AO.mjs.map +1 -0
  122. package/dist/esm/chunk-U4HCGTLU.mjs +35 -0
  123. package/dist/esm/chunk-U4HCGTLU.mjs.map +1 -0
  124. package/dist/esm/chunk-VS3RYAYE.mjs +80 -0
  125. package/dist/esm/chunk-VS3RYAYE.mjs.map +1 -0
  126. package/dist/esm/chunk-W6ON4LG2.mjs +39 -0
  127. package/dist/esm/chunk-W6ON4LG2.mjs.map +1 -0
  128. package/dist/esm/chunk-XG2JLZVJ.mjs +627 -0
  129. package/dist/esm/chunk-XG2JLZVJ.mjs.map +1 -0
  130. package/dist/esm/chunk-ZCJRY5LQ.mjs +162 -0
  131. package/dist/esm/chunk-ZCJRY5LQ.mjs.map +1 -0
  132. package/dist/esm/client/agent-wallet.d.mts +69 -0
  133. package/dist/esm/client/agent-wallet.mjs +36 -0
  134. package/dist/esm/client/agent-wallet.mjs.map +1 -0
  135. package/dist/esm/exact/client/index.d.mts +63 -0
  136. package/dist/esm/exact/client/index.mjs +25 -0
  137. package/dist/esm/exact/client/index.mjs.map +1 -0
  138. package/dist/esm/exact/facilitator/index.d.mts +141 -0
  139. package/dist/esm/exact/facilitator/index.mjs +694 -0
  140. package/dist/esm/exact/facilitator/index.mjs.map +1 -0
  141. package/dist/esm/exact/server/index.d.mts +118 -0
  142. package/dist/esm/exact/server/index.mjs +153 -0
  143. package/dist/esm/exact/server/index.mjs.map +1 -0
  144. package/dist/esm/exact/v1/client/index.d.mts +38 -0
  145. package/dist/esm/exact/v1/client/index.mjs +12 -0
  146. package/dist/esm/exact/v1/client/index.mjs.map +1 -0
  147. package/dist/esm/exact/v1/facilitator/index.d.mts +84 -0
  148. package/dist/esm/exact/v1/facilitator/index.mjs +12 -0
  149. package/dist/esm/exact/v1/facilitator/index.mjs.map +1 -0
  150. package/dist/esm/facilitator/agent-wallet.d.mts +109 -0
  151. package/dist/esm/facilitator/agent-wallet.mjs +74 -0
  152. package/dist/esm/facilitator/agent-wallet.mjs.map +1 -0
  153. package/dist/esm/index.d.mts +338 -0
  154. package/dist/esm/index.mjs +144 -0
  155. package/dist/esm/index.mjs.map +1 -0
  156. package/dist/esm/permit2-DhJRUcgY.d.mts +729 -0
  157. package/dist/esm/rpc-DULZzRne.d.mts +13 -0
  158. package/dist/esm/scheme-CkNhpXrG.d.mts +307 -0
  159. package/dist/esm/scheme-D8ZbykGV.d.mts +47 -0
  160. package/dist/esm/signer-BFelv8DL.d.mts +170 -0
  161. package/dist/esm/storage-6W5MO46W.d.mts +50 -0
  162. package/dist/esm/storage-BEzTEiUr.d.mts +81 -0
  163. package/dist/esm/types-DIt9uAUy.d.mts +180 -0
  164. package/dist/esm/upto/client/index.d.mts +34 -0
  165. package/dist/esm/upto/client/index.mjs +22 -0
  166. package/dist/esm/upto/client/index.mjs.map +1 -0
  167. package/dist/esm/upto/facilitator/index.d.mts +54 -0
  168. package/dist/esm/upto/facilitator/index.mjs +507 -0
  169. package/dist/esm/upto/facilitator/index.mjs.map +1 -0
  170. package/dist/esm/upto/server/index.d.mts +69 -0
  171. package/dist/esm/upto/server/index.mjs +124 -0
  172. package/dist/esm/upto/server/index.mjs.map +1 -0
  173. package/dist/esm/v1/index.d.mts +40 -0
  174. package/dist/esm/v1/index.mjs +18 -0
  175. package/dist/esm/v1/index.mjs.map +1 -0
  176. package/package.json +250 -0
@@ -0,0 +1,296 @@
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/upto/server/index.ts
21
+ var server_exports = {};
22
+ __export(server_exports, {
23
+ UptoEvmScheme: () => UptoEvmScheme
24
+ });
25
+ module.exports = __toCommonJS(server_exports);
26
+
27
+ // src/upto/server/scheme.ts
28
+ var import_utils = require("@bankofai/x402-core/utils");
29
+ var import_viem = require("viem");
30
+
31
+ // src/shared/defaultAssets.ts
32
+ var DEFAULT_STABLECOINS = {
33
+ "eip155:8453": {
34
+ address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
35
+ name: "USD Coin",
36
+ version: "2",
37
+ decimals: 6
38
+ },
39
+ // Base mainnet USDC
40
+ "eip155:84532": {
41
+ address: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
42
+ name: "USDC",
43
+ version: "2",
44
+ decimals: 6
45
+ },
46
+ // Base Sepolia USDC
47
+ "eip155:4326": {
48
+ address: "0xFAfDdbb3FC7688494971a79cc65DCa3EF82079E7",
49
+ name: "MegaUSD",
50
+ version: "1",
51
+ decimals: 18,
52
+ assetTransferMethod: "permit2",
53
+ supportsEip2612: true
54
+ },
55
+ // MegaETH mainnet MegaUSD (no EIP-3009, supports EIP-2612)
56
+ "eip155:143": {
57
+ address: "0x754704Bc059F8C67012fEd69BC8A327a5aafb603",
58
+ name: "USD Coin",
59
+ version: "2",
60
+ decimals: 6
61
+ },
62
+ // Monad mainnet USDC
63
+ "eip155:988": {
64
+ address: "0x779Ded0c9e1022225f8E0630b35a9b54bE713736",
65
+ name: "USDT0",
66
+ version: "1",
67
+ decimals: 6
68
+ },
69
+ // Stable mainnet USDT0
70
+ "eip155:2201": {
71
+ address: "0x78Cf24370174180738C5B8E352B6D14c83a6c9A9",
72
+ name: "USDT0",
73
+ version: "1",
74
+ decimals: 6
75
+ },
76
+ // Stable testnet USDT0
77
+ "eip155:137": {
78
+ address: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
79
+ name: "USD Coin",
80
+ version: "2",
81
+ decimals: 6
82
+ },
83
+ // Polygon mainnet USDC
84
+ "eip155:42161": {
85
+ address: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
86
+ name: "USD Coin",
87
+ version: "2",
88
+ decimals: 6
89
+ },
90
+ // Arbitrum One USDC
91
+ "eip155:421614": {
92
+ address: "0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d",
93
+ name: "USD Coin",
94
+ version: "2",
95
+ decimals: 6
96
+ },
97
+ // Arbitrum Sepolia USDC
98
+ "eip155:31612": {
99
+ address: "0xdD468A1DDc392dcdbEf6db6e34E89AA338F9F186",
100
+ name: "Mezo USD",
101
+ version: "1",
102
+ decimals: 18,
103
+ assetTransferMethod: "permit2",
104
+ supportsEip2612: true
105
+ },
106
+ // Mezo mainnet mUSD (no EIP-3009, supports EIP-2612)
107
+ "eip155:31611": {
108
+ address: "0x118917a40FAF1CD7a13dB0Ef56C86De7973Ac503",
109
+ name: "Mezo USD",
110
+ version: "1",
111
+ decimals: 18,
112
+ assetTransferMethod: "permit2",
113
+ supportsEip2612: true
114
+ },
115
+ // Mezo Testnet mUSD (no EIP-3009, supports EIP-2612)
116
+ "eip155:723487": {
117
+ address: "0x33ad9e4BD16B69B5BFdED37D8B5D9fF9aba014Fb",
118
+ name: "Stable Coin",
119
+ version: "1",
120
+ decimals: 6,
121
+ assetTransferMethod: "permit2",
122
+ supportsEip2612: true
123
+ },
124
+ // Radius Network SBC (no EIP-3009, supports EIP-2612)
125
+ "eip155:72344": {
126
+ address: "0x33ad9e4BD16B69B5BFdED37D8B5D9fF9aba014Fb",
127
+ name: "Stable Coin",
128
+ version: "1",
129
+ decimals: 6,
130
+ assetTransferMethod: "permit2",
131
+ supportsEip2612: true
132
+ },
133
+ // Radius Testnet SBC (no EIP-3009, supports EIP-2612)
134
+ "eip155:36900": {
135
+ address: "0x9cb8142aEBBcdc60AF7c97Af897A67A8f3CA71C2",
136
+ name: "USDC.e",
137
+ version: "2",
138
+ decimals: 6
139
+ },
140
+ // ADI Chain USDC.e (EIP-3009 supported)
141
+ "eip155:190415": {
142
+ address: "0x401eCb1D350407f13ba348573E5630B83638E30D",
143
+ name: "Bridged USDC",
144
+ version: "2",
145
+ decimals: 6
146
+ },
147
+ // HPP mainnet USDC.e
148
+ "eip155:181228": {
149
+ address: "0x401eCb1D350407f13ba348573E5630B83638E30D",
150
+ name: "Bridged USDC",
151
+ version: "2",
152
+ decimals: 6
153
+ },
154
+ // HPP Sepolia USDC.e
155
+ "eip155:50": {
156
+ address: "0xfA2958CB79b0491CC627c1557F441eF849Ca8eb1",
157
+ name: "USDC",
158
+ version: "2",
159
+ decimals: 6
160
+ },
161
+ // XDC Network mainnet USDC (Bridged USDC Standard, EIP-3009 supported)
162
+ "eip155:51": {
163
+ address: "0xb5AB69F7bBada22B28e79C8FFAECe55eF1c771D4",
164
+ name: "USDC",
165
+ version: "2",
166
+ decimals: 6
167
+ }
168
+ // XDC Apothem testnet USDC (Bridged USDC Standard, EIP-3009 supported)
169
+ };
170
+ function getDefaultAsset(network) {
171
+ const info = DEFAULT_STABLECOINS[network];
172
+ if (!info) {
173
+ throw new Error(`No default asset configured for network ${network}`);
174
+ }
175
+ return info;
176
+ }
177
+
178
+ // src/upto/server/scheme.ts
179
+ var UptoEvmScheme = class {
180
+ constructor() {
181
+ this.scheme = "upto";
182
+ this.moneyParsers = [];
183
+ }
184
+ /**
185
+ * Registers a custom money parser for converting prices to asset amounts.
186
+ *
187
+ * @param parser - The money parser function to register
188
+ * @returns This instance for chaining
189
+ */
190
+ registerMoneyParser(parser) {
191
+ this.moneyParsers.push(parser);
192
+ return this;
193
+ }
194
+ /**
195
+ * Returns the decimal precision of the default stablecoin for the given network.
196
+ * Implements the optional AssetDecimalsProvider interface used by resolveSettlementOverrideAmount.
197
+ *
198
+ * @param _asset - The asset symbol (unused; defaults to the network's default stablecoin)
199
+ * @param network - The network to look up the default asset for
200
+ * @returns The number of decimal places for the asset
201
+ */
202
+ getAssetDecimals(_asset, network) {
203
+ try {
204
+ return getDefaultAsset(network).decimals;
205
+ } catch {
206
+ return 6;
207
+ }
208
+ }
209
+ /**
210
+ * Parses a price into an asset amount for the given network.
211
+ *
212
+ * @param price - The price to parse (string, number, or AssetAmount)
213
+ * @param network - The target network
214
+ * @returns Promise resolving to an asset amount
215
+ */
216
+ async parsePrice(price, network) {
217
+ if (typeof price === "object" && price !== null && "amount" in price) {
218
+ if (!price.asset) {
219
+ throw new Error(`Asset address must be specified for AssetAmount on network ${network}`);
220
+ }
221
+ return {
222
+ amount: price.amount,
223
+ asset: price.asset,
224
+ extra: price.extra || {}
225
+ };
226
+ }
227
+ const amount = this.parseMoneyToDecimal(price);
228
+ for (const parser of this.moneyParsers) {
229
+ const result = await parser(amount, network);
230
+ if (result !== null) {
231
+ return result;
232
+ }
233
+ }
234
+ return this.defaultMoneyConversion(amount, network);
235
+ }
236
+ /**
237
+ * Enhances payment requirements with upto-specific metadata.
238
+ *
239
+ * @param paymentRequirements - The base payment requirements
240
+ * @param supportedKind - The supported scheme/network kind
241
+ * @param supportedKind.x402Version - The x402 protocol version
242
+ * @param supportedKind.scheme - The payment scheme name
243
+ * @param supportedKind.network - The target network
244
+ * @param supportedKind.extra - Optional extra metadata
245
+ * @param extensionKeys - Extension keys to include
246
+ * @returns Promise resolving to enhanced payment requirements
247
+ */
248
+ enhancePaymentRequirements(paymentRequirements, supportedKind, extensionKeys) {
249
+ void extensionKeys;
250
+ return Promise.resolve({
251
+ ...paymentRequirements,
252
+ extra: {
253
+ ...paymentRequirements.extra,
254
+ assetTransferMethod: "permit2",
255
+ ...supportedKind.extra?.facilitatorAddress ? { facilitatorAddress: (0, import_viem.getAddress)(supportedKind.extra.facilitatorAddress) } : {}
256
+ }
257
+ });
258
+ }
259
+ /**
260
+ * Parses a money string or number into a decimal value.
261
+ *
262
+ * @param money - The money value to parse
263
+ * @returns The parsed decimal amount
264
+ */
265
+ parseMoneyToDecimal(money) {
266
+ if (typeof money === "number") {
267
+ return money;
268
+ }
269
+ return (0, import_utils.parseMoneyString)(money);
270
+ }
271
+ /**
272
+ * Converts a numeric dollar amount to an AssetAmount using the default token for the network.
273
+ *
274
+ * @param amount - The dollar amount as a number
275
+ * @param network - The target network
276
+ * @returns The converted asset amount with token metadata
277
+ */
278
+ defaultMoneyConversion(amount, network) {
279
+ const assetInfo = getDefaultAsset(network);
280
+ const tokenAmount = (0, import_utils.convertToTokenAmount)((0, import_utils.numberToDecimalString)(amount), assetInfo.decimals);
281
+ return {
282
+ amount: tokenAmount,
283
+ asset: assetInfo.address,
284
+ extra: {
285
+ name: assetInfo.name,
286
+ version: assetInfo.version,
287
+ assetTransferMethod: "permit2"
288
+ }
289
+ };
290
+ }
291
+ };
292
+ // Annotate the CommonJS export names for ESM import in node:
293
+ 0 && (module.exports = {
294
+ UptoEvmScheme
295
+ });
296
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/upto/server/index.ts","../../../../src/upto/server/scheme.ts","../../../../src/shared/defaultAssets.ts"],"sourcesContent":["// Note: No register.ts helper — V1 backward compatibility is not needed for upto.\n// Use direct class instantiation: server.register(\"eip155:*\", new UptoEvmScheme())\nexport { UptoEvmScheme } from \"./scheme\";\n","import {\n AssetAmount,\n Network,\n PaymentRequirements,\n Price,\n SchemeNetworkServer,\n MoneyParser,\n} from \"@bankofai/x402-core/types\";\nimport { convertToTokenAmount, numberToDecimalString, parseMoneyString } from \"@bankofai/x402-core/utils\";\nimport { getAddress } from \"viem\";\nimport { getDefaultAsset } from \"../../shared/defaultAssets\";\n\n/**\n * EVM server implementation for the Upto payment scheme.\n * Handles price parsing, payment requirements enhancement, and default asset resolution.\n */\nexport class UptoEvmScheme implements SchemeNetworkServer {\n readonly scheme = \"upto\";\n private moneyParsers: MoneyParser[] = [];\n\n /**\n * Registers a custom money parser for converting prices to asset amounts.\n *\n * @param parser - The money parser function to register\n * @returns This instance for chaining\n */\n registerMoneyParser(parser: MoneyParser): UptoEvmScheme {\n this.moneyParsers.push(parser);\n return this;\n }\n\n /**\n * Returns the decimal precision of the default stablecoin for the given network.\n * Implements the optional AssetDecimalsProvider interface used by resolveSettlementOverrideAmount.\n *\n * @param _asset - The asset symbol (unused; defaults to the network's default stablecoin)\n * @param network - The network to look up the default asset for\n * @returns The number of decimal places for the asset\n */\n getAssetDecimals(_asset: string, network: Network): number {\n try {\n return getDefaultAsset(network).decimals;\n } catch {\n return 6;\n }\n }\n\n /**\n * Parses a price into an asset amount for the given network.\n *\n * @param price - The price to parse (string, number, or AssetAmount)\n * @param network - The target network\n * @returns Promise resolving to an asset amount\n */\n async parsePrice(price: Price, network: Network): Promise<AssetAmount> {\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 const amount = this.parseMoneyToDecimal(price);\n\n for (const parser of this.moneyParsers) {\n const result = await parser(amount, network);\n if (result !== null) {\n return result;\n }\n }\n\n return this.defaultMoneyConversion(amount, network);\n }\n\n /**\n * Enhances payment requirements with upto-specific metadata.\n *\n * @param paymentRequirements - The base payment requirements\n * @param supportedKind - The supported scheme/network kind\n * @param supportedKind.x402Version - The x402 protocol version\n * @param supportedKind.scheme - The payment scheme name\n * @param supportedKind.network - The target network\n * @param supportedKind.extra - Optional extra metadata\n * @param extensionKeys - Extension keys to include\n * @returns Promise resolving to enhanced payment requirements\n */\n enhancePaymentRequirements(\n paymentRequirements: PaymentRequirements,\n supportedKind: {\n x402Version: number;\n scheme: string;\n network: Network;\n extra?: Record<string, unknown>;\n },\n extensionKeys: string[],\n ): Promise<PaymentRequirements> {\n void extensionKeys;\n return Promise.resolve({\n ...paymentRequirements,\n extra: {\n ...paymentRequirements.extra,\n assetTransferMethod: \"permit2\",\n ...(supportedKind.extra?.facilitatorAddress\n ? { facilitatorAddress: getAddress(supportedKind.extra.facilitatorAddress as string) }\n : {}),\n },\n });\n }\n\n /**\n * Parses a money string or number into a decimal value.\n *\n * @param money - The money value to parse\n * @returns The parsed decimal amount\n */\n private parseMoneyToDecimal(money: string | number): number {\n if (typeof money === \"number\") {\n return money;\n }\n\n return parseMoneyString(money);\n }\n\n /**\n * Converts a numeric dollar amount to an AssetAmount using the default token for the network.\n *\n * @param amount - The dollar amount as a number\n * @param network - The target network\n * @returns The converted asset amount with token metadata\n */\n private defaultMoneyConversion(amount: number, network: Network): AssetAmount {\n const assetInfo = getDefaultAsset(network);\n const tokenAmount = convertToTokenAmount(numberToDecimalString(amount), assetInfo.decimals);\n\n return {\n amount: tokenAmount,\n asset: assetInfo.address,\n extra: {\n name: assetInfo.name,\n version: assetInfo.version,\n assetTransferMethod: \"permit2\",\n },\n };\n }\n}\n","import type { Network } from \"@bankofai/x402-core/types\";\n\n/**\n * Base stablecoin asset configuration shared across all EVM payment schemes.\n * Contains the core fields needed to identify and convert tokens.\n */\nexport type DefaultAssetInfo = {\n /** Token contract address */\n address: string;\n /** EIP-712 domain name (must match the token's domain separator) */\n name: string;\n /** EIP-712 domain version (must match the token's domain separator) */\n version: string;\n /** Token decimal places (typically 6 for USDC) */\n decimals: number;\n};\n\n/**\n * Extended asset configuration for the exact scheme.\n * Includes transfer method hints that control client-side behaviour.\n */\nexport type ExactDefaultAssetInfo = DefaultAssetInfo & {\n /**\n * Transfer method override: `\"permit2\"` for tokens that don't support EIP-3009.\n * Omit for EIP-3009 tokens (default behaviour).\n */\n assetTransferMethod?: string;\n /**\n * Set to `true` for permit2 tokens that implement EIP-2612 `permit()`.\n * Controls whether name/version are included in `extra` so the client can\n * sign a gasless EIP-2612 permit for Permit2 approval.\n */\n supportsEip2612?: boolean;\n};\n\n/**\n * Default stablecoins indexed by CAIP-2 network identifier.\n *\n * Each network has the right to determine its own default stablecoin that can\n * be expressed as a USD string by calling servers. See DEFAULT_ASSET.md in\n * exact/server/ for how to add new chains.\n */\nexport const DEFAULT_STABLECOINS: Record<string, ExactDefaultAssetInfo> = {\n \"eip155:8453\": {\n address: \"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Base mainnet USDC\n \"eip155:84532\": {\n address: \"0x036CbD53842c5426634e7929541eC2318f3dCF7e\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // Base Sepolia USDC\n \"eip155:4326\": {\n address: \"0xFAfDdbb3FC7688494971a79cc65DCa3EF82079E7\",\n name: \"MegaUSD\",\n version: \"1\",\n decimals: 18,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // MegaETH mainnet MegaUSD (no EIP-3009, supports EIP-2612)\n \"eip155:143\": {\n address: \"0x754704Bc059F8C67012fEd69BC8A327a5aafb603\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Monad mainnet USDC\n \"eip155:988\": {\n address: \"0x779Ded0c9e1022225f8E0630b35a9b54bE713736\",\n name: \"USDT0\",\n version: \"1\",\n decimals: 6,\n }, // Stable mainnet USDT0\n \"eip155:2201\": {\n address: \"0x78Cf24370174180738C5B8E352B6D14c83a6c9A9\",\n name: \"USDT0\",\n version: \"1\",\n decimals: 6,\n }, // Stable testnet USDT0\n \"eip155:137\": {\n address: \"0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Polygon mainnet USDC\n \"eip155:42161\": {\n address: \"0xaf88d065e77c8cC2239327C5EDb3A432268e5831\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Arbitrum One USDC\n \"eip155:421614\": {\n address: \"0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d\",\n name: \"USD Coin\",\n version: \"2\",\n decimals: 6,\n }, // Arbitrum Sepolia USDC\n \"eip155:31612\": {\n address: \"0xdD468A1DDc392dcdbEf6db6e34E89AA338F9F186\",\n name: \"Mezo USD\",\n version: \"1\",\n decimals: 18,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // Mezo mainnet mUSD (no EIP-3009, supports EIP-2612)\n \"eip155:31611\": {\n address: \"0x118917a40FAF1CD7a13dB0Ef56C86De7973Ac503\",\n name: \"Mezo USD\",\n version: \"1\",\n decimals: 18,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // Mezo Testnet mUSD (no EIP-3009, supports EIP-2612)\n \"eip155:723487\": {\n address: \"0x33ad9e4BD16B69B5BFdED37D8B5D9fF9aba014Fb\",\n name: \"Stable Coin\",\n version: \"1\",\n decimals: 6,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // Radius Network SBC (no EIP-3009, supports EIP-2612)\n \"eip155:72344\": {\n address: \"0x33ad9e4BD16B69B5BFdED37D8B5D9fF9aba014Fb\",\n name: \"Stable Coin\",\n version: \"1\",\n decimals: 6,\n assetTransferMethod: \"permit2\",\n supportsEip2612: true,\n }, // Radius Testnet SBC (no EIP-3009, supports EIP-2612)\n \"eip155:36900\": {\n address: \"0x9cb8142aEBBcdc60AF7c97Af897A67A8f3CA71C2\",\n name: \"USDC.e\",\n version: \"2\",\n decimals: 6,\n }, // ADI Chain USDC.e (EIP-3009 supported)\n \"eip155:190415\": {\n address: \"0x401eCb1D350407f13ba348573E5630B83638E30D\",\n name: \"Bridged USDC\",\n version: \"2\",\n decimals: 6,\n }, // HPP mainnet USDC.e\n \"eip155:181228\": {\n address: \"0x401eCb1D350407f13ba348573E5630B83638E30D\",\n name: \"Bridged USDC\",\n version: \"2\",\n decimals: 6,\n }, // HPP Sepolia USDC.e\n \"eip155:50\": {\n address: \"0xfA2958CB79b0491CC627c1557F441eF849Ca8eb1\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // XDC Network mainnet USDC (Bridged USDC Standard, EIP-3009 supported)\n \"eip155:51\": {\n address: \"0xb5AB69F7bBada22B28e79C8FFAECe55eF1c771D4\",\n name: \"USDC\",\n version: \"2\",\n decimals: 6,\n }, // XDC Apothem testnet USDC (Bridged USDC Standard, EIP-3009 supported)\n};\n\n/**\n * Look up the default stablecoin for a network.\n *\n * @param network - CAIP-2 network identifier (e.g. \"eip155:8453\")\n * @returns The default asset info\n * @throws If no default asset is configured for the network\n */\nexport function getDefaultAsset(network: Network): ExactDefaultAssetInfo {\n const info = DEFAULT_STABLECOINS[network];\n if (!info) {\n throw new Error(`No default asset configured for network ${network}`);\n }\n return info;\n}\n"],"mappings":"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","names":[]}
@@ -0,0 +1,40 @@
1
+ export { ExactEvmSchemeV1 } from '../exact/v1/client/index.js';
2
+ import '@bankofai/x402-core/types';
3
+ import '../signer-BFelv8DL.js';
4
+ import 'viem';
5
+
6
+ declare const EVM_NETWORK_CHAIN_ID_MAP: {
7
+ readonly ethereum: 1;
8
+ readonly sepolia: 11155111;
9
+ readonly abstract: 2741;
10
+ readonly "abstract-testnet": 11124;
11
+ readonly "base-sepolia": 84532;
12
+ readonly base: 8453;
13
+ readonly "avalanche-fuji": 43113;
14
+ readonly avalanche: 43114;
15
+ readonly iotex: 4689;
16
+ readonly sei: 1329;
17
+ readonly "sei-testnet": 1328;
18
+ readonly polygon: 137;
19
+ readonly "polygon-amoy": 80002;
20
+ readonly peaq: 3338;
21
+ readonly story: 1514;
22
+ readonly educhain: 41923;
23
+ readonly "skale-base-sepolia": 324705682;
24
+ readonly megaeth: 4326;
25
+ readonly monad: 143;
26
+ readonly stable: 988;
27
+ readonly "stable-testnet": 2201;
28
+ };
29
+ type EvmNetworkV1 = keyof typeof EVM_NETWORK_CHAIN_ID_MAP;
30
+ declare const NETWORKS: string[];
31
+ /**
32
+ * Extract chain ID from a v1 legacy network name.
33
+ *
34
+ * @param network - The v1 network name (e.g., "base-sepolia", "polygon")
35
+ * @returns The numeric chain ID
36
+ * @throws Error if the network name is not a known v1 network
37
+ */
38
+ declare function getEvmChainIdV1(network: string): number;
39
+
40
+ export { EVM_NETWORK_CHAIN_ID_MAP, type EvmNetworkV1, NETWORKS, getEvmChainIdV1 };
@@ -0,0 +1,199 @@
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/v1/index.ts
21
+ var v1_exports = {};
22
+ __export(v1_exports, {
23
+ EVM_NETWORK_CHAIN_ID_MAP: () => EVM_NETWORK_CHAIN_ID_MAP,
24
+ ExactEvmSchemeV1: () => ExactEvmSchemeV1,
25
+ NETWORKS: () => NETWORKS,
26
+ getEvmChainIdV1: () => getEvmChainIdV1
27
+ });
28
+ module.exports = __toCommonJS(v1_exports);
29
+
30
+ // src/exact/v1/client/scheme.ts
31
+ var import_viem2 = require("viem");
32
+
33
+ // src/constants.ts
34
+ var authorizationTypes = {
35
+ TransferWithAuthorization: [
36
+ { name: "from", type: "address" },
37
+ { name: "to", type: "address" },
38
+ { name: "value", type: "uint256" },
39
+ { name: "validAfter", type: "uint256" },
40
+ { name: "validBefore", type: "uint256" },
41
+ { name: "nonce", type: "bytes32" }
42
+ ]
43
+ };
44
+
45
+ // src/utils.ts
46
+ var import_viem = require("viem");
47
+ function getCrypto() {
48
+ const cryptoObj = globalThis.crypto;
49
+ if (!cryptoObj) {
50
+ throw new Error("Crypto API not available");
51
+ }
52
+ return cryptoObj;
53
+ }
54
+ function createNonce() {
55
+ return (0, import_viem.toHex)(getCrypto().getRandomValues(new Uint8Array(32)));
56
+ }
57
+
58
+ // src/exact/v1/client/scheme.ts
59
+ var ExactEvmSchemeV1 = class {
60
+ /**
61
+ * Creates a new ExactEvmClientV1 instance.
62
+ *
63
+ * @param signer - The EVM signer for client operations
64
+ */
65
+ constructor(signer) {
66
+ this.signer = signer;
67
+ this.scheme = "exact";
68
+ }
69
+ /**
70
+ * Creates a payment payload for the Exact scheme (V1).
71
+ *
72
+ * @param x402Version - The x402 protocol version
73
+ * @param paymentRequirements - The payment requirements
74
+ * @returns Promise resolving to a payment payload
75
+ */
76
+ async createPaymentPayload(x402Version, paymentRequirements) {
77
+ const selectedV1 = paymentRequirements;
78
+ const nonce = createNonce();
79
+ const now = Math.floor(Date.now() / 1e3);
80
+ const authorization = {
81
+ from: this.signer.address,
82
+ to: (0, import_viem2.getAddress)(selectedV1.payTo),
83
+ value: selectedV1.maxAmountRequired,
84
+ validAfter: (now - 600).toString(),
85
+ // 10 minutes before
86
+ validBefore: (now + selectedV1.maxTimeoutSeconds).toString(),
87
+ nonce
88
+ };
89
+ const signature = await this.signAuthorization(authorization, selectedV1);
90
+ const payload = {
91
+ authorization,
92
+ signature
93
+ };
94
+ return {
95
+ x402Version,
96
+ scheme: selectedV1.scheme,
97
+ network: selectedV1.network,
98
+ payload
99
+ };
100
+ }
101
+ /**
102
+ * Sign the EIP-3009 authorization using EIP-712
103
+ *
104
+ * @param authorization - The authorization to sign
105
+ * @param requirements - The payment requirements
106
+ * @returns Promise resolving to the signature
107
+ */
108
+ async signAuthorization(authorization, requirements) {
109
+ const chainId = getEvmChainIdV1(requirements.network);
110
+ if (!requirements.extra?.name || !requirements.extra?.version) {
111
+ throw new Error(
112
+ `EIP-712 domain parameters (name, version) are required in payment requirements for asset ${requirements.asset}`
113
+ );
114
+ }
115
+ const { name, version } = requirements.extra;
116
+ const domain = {
117
+ name,
118
+ version,
119
+ chainId,
120
+ verifyingContract: (0, import_viem2.getAddress)(requirements.asset)
121
+ };
122
+ const message = {
123
+ from: (0, import_viem2.getAddress)(authorization.from),
124
+ to: (0, import_viem2.getAddress)(authorization.to),
125
+ value: BigInt(authorization.value),
126
+ validAfter: BigInt(authorization.validAfter),
127
+ validBefore: BigInt(authorization.validBefore),
128
+ nonce: authorization.nonce
129
+ };
130
+ return await this.signer.signTypedData({
131
+ domain,
132
+ types: authorizationTypes,
133
+ primaryType: "TransferWithAuthorization",
134
+ message
135
+ });
136
+ }
137
+ };
138
+
139
+ // src/shared/extensions/gasSponsoring.ts
140
+ var import_viem6 = require("viem");
141
+
142
+ // src/exact/client/eip2612.ts
143
+ var import_viem3 = require("viem");
144
+
145
+ // src/exact/client/erc20approval.ts
146
+ var import_viem4 = require("viem");
147
+
148
+ // src/shared/rpc.ts
149
+ var import_viem5 = require("viem");
150
+
151
+ // src/exact/v1/facilitator/scheme.ts
152
+ var import_viem9 = require("viem");
153
+
154
+ // src/exact/facilitator/eip3009-utils.ts
155
+ var import_viem8 = require("viem");
156
+
157
+ // src/multicall.ts
158
+ var import_viem7 = require("viem");
159
+
160
+ // src/v1/index.ts
161
+ var EVM_NETWORK_CHAIN_ID_MAP = {
162
+ ethereum: 1,
163
+ sepolia: 11155111,
164
+ abstract: 2741,
165
+ "abstract-testnet": 11124,
166
+ "base-sepolia": 84532,
167
+ base: 8453,
168
+ "avalanche-fuji": 43113,
169
+ avalanche: 43114,
170
+ iotex: 4689,
171
+ sei: 1329,
172
+ "sei-testnet": 1328,
173
+ polygon: 137,
174
+ "polygon-amoy": 80002,
175
+ peaq: 3338,
176
+ story: 1514,
177
+ educhain: 41923,
178
+ "skale-base-sepolia": 324705682,
179
+ megaeth: 4326,
180
+ monad: 143,
181
+ stable: 988,
182
+ "stable-testnet": 2201
183
+ };
184
+ var NETWORKS = Object.keys(EVM_NETWORK_CHAIN_ID_MAP);
185
+ function getEvmChainIdV1(network) {
186
+ const chainId = EVM_NETWORK_CHAIN_ID_MAP[network];
187
+ if (!chainId) {
188
+ throw new Error(`Unsupported v1 network: ${network}`);
189
+ }
190
+ return chainId;
191
+ }
192
+ // Annotate the CommonJS export names for ESM import in node:
193
+ 0 && (module.exports = {
194
+ EVM_NETWORK_CHAIN_ID_MAP,
195
+ ExactEvmSchemeV1,
196
+ NETWORKS,
197
+ getEvmChainIdV1
198
+ });
199
+ //# sourceMappingURL=index.js.map