uvd-x402-sdk 2.1.0 → 2.2.1

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 (54) hide show
  1. package/README.md +280 -15
  2. package/dist/adapters/index.d.mts +1 -1
  3. package/dist/adapters/index.d.ts +1 -1
  4. package/dist/adapters/index.js +138 -0
  5. package/dist/adapters/index.js.map +1 -1
  6. package/dist/adapters/index.mjs +138 -0
  7. package/dist/adapters/index.mjs.map +1 -1
  8. package/dist/{index-MTBgC_SL.d.mts → index-BG738nMY.d.mts} +43 -4
  9. package/dist/{index-MTBgC_SL.d.ts → index-BG738nMY.d.ts} +43 -4
  10. package/dist/{index-Db8dWNam.d.ts → index-I60aHxwu.d.mts} +33 -2
  11. package/dist/{index-D0N_SYpK.d.mts → index-OZTSi1rJ.d.ts} +33 -2
  12. package/dist/index.d.mts +2 -2
  13. package/dist/index.d.ts +2 -2
  14. package/dist/index.js +180 -0
  15. package/dist/index.js.map +1 -1
  16. package/dist/index.mjs +177 -1
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/providers/evm/index.d.mts +19 -3
  19. package/dist/providers/evm/index.d.ts +19 -3
  20. package/dist/providers/evm/index.js +198 -12
  21. package/dist/providers/evm/index.js.map +1 -1
  22. package/dist/providers/evm/index.mjs +198 -12
  23. package/dist/providers/evm/index.mjs.map +1 -1
  24. package/dist/providers/near/index.d.mts +1 -1
  25. package/dist/providers/near/index.d.ts +1 -1
  26. package/dist/providers/near/index.js.map +1 -1
  27. package/dist/providers/near/index.mjs.map +1 -1
  28. package/dist/providers/solana/index.d.mts +1 -1
  29. package/dist/providers/solana/index.d.ts +1 -1
  30. package/dist/providers/solana/index.js +138 -0
  31. package/dist/providers/solana/index.js.map +1 -1
  32. package/dist/providers/solana/index.mjs +138 -0
  33. package/dist/providers/solana/index.mjs.map +1 -1
  34. package/dist/providers/stellar/index.d.mts +1 -1
  35. package/dist/providers/stellar/index.d.ts +1 -1
  36. package/dist/providers/stellar/index.js.map +1 -1
  37. package/dist/providers/stellar/index.mjs.map +1 -1
  38. package/dist/react/index.d.mts +3 -3
  39. package/dist/react/index.d.ts +3 -3
  40. package/dist/react/index.js +138 -0
  41. package/dist/react/index.js.map +1 -1
  42. package/dist/react/index.mjs +138 -0
  43. package/dist/react/index.mjs.map +1 -1
  44. package/dist/utils/index.d.mts +1 -1
  45. package/dist/utils/index.d.ts +1 -1
  46. package/dist/utils/index.js +138 -0
  47. package/dist/utils/index.js.map +1 -1
  48. package/dist/utils/index.mjs +138 -0
  49. package/dist/utils/index.mjs.map +1 -1
  50. package/package.json +5 -2
  51. package/src/chains/index.ts +225 -1
  52. package/src/index.ts +9 -0
  53. package/src/providers/evm/index.ts +64 -16
  54. package/src/types/index.ts +44 -3
@@ -69,6 +69,20 @@ var SUPPORTED_CHAINS = {
69
69
  name: "USD Coin",
70
70
  version: "2"
71
71
  },
72
+ tokens: {
73
+ usdc: {
74
+ address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
75
+ decimals: 6,
76
+ name: "USD Coin",
77
+ version: "2"
78
+ },
79
+ eurc: {
80
+ address: "0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42",
81
+ decimals: 6,
82
+ name: "EURC",
83
+ version: "2"
84
+ }
85
+ },
72
86
  x402: {
73
87
  facilitatorUrl: DEFAULT_FACILITATOR_URL,
74
88
  enabled: true
@@ -93,6 +107,26 @@ var SUPPORTED_CHAINS = {
93
107
  name: "USD Coin",
94
108
  version: "2"
95
109
  },
110
+ tokens: {
111
+ usdc: {
112
+ address: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
113
+ decimals: 6,
114
+ name: "USD Coin",
115
+ version: "2"
116
+ },
117
+ eurc: {
118
+ address: "0xC891EB4cbdEFf6e073e859e987815Ed1505c2ACD",
119
+ decimals: 6,
120
+ name: "EURC",
121
+ version: "2"
122
+ },
123
+ ausd: {
124
+ address: "0x00000000eFE302BEAA2b3e6e1b18d08D69a9012a",
125
+ decimals: 6,
126
+ name: "Agora USD",
127
+ version: "1"
128
+ }
129
+ },
96
130
  x402: {
97
131
  facilitatorUrl: DEFAULT_FACILITATOR_URL,
98
132
  enabled: true
@@ -117,6 +151,32 @@ var SUPPORTED_CHAINS = {
117
151
  name: "USD Coin",
118
152
  version: "2"
119
153
  },
154
+ tokens: {
155
+ usdc: {
156
+ address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
157
+ decimals: 6,
158
+ name: "USD Coin",
159
+ version: "2"
160
+ },
161
+ eurc: {
162
+ address: "0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c",
163
+ decimals: 6,
164
+ name: "EURC",
165
+ version: "2"
166
+ },
167
+ ausd: {
168
+ address: "0x00000000eFE302BEAA2b3e6e1b18d08D69a9012a",
169
+ decimals: 6,
170
+ name: "Agora USD",
171
+ version: "1"
172
+ },
173
+ pyusd: {
174
+ address: "0x6c3ea9036406852006290770BEdFcAbA0e23A0e8",
175
+ decimals: 6,
176
+ name: "PayPal USD",
177
+ version: "1"
178
+ }
179
+ },
120
180
  x402: {
121
181
  facilitatorUrl: DEFAULT_FACILITATOR_URL,
122
182
  enabled: true
@@ -141,6 +201,20 @@ var SUPPORTED_CHAINS = {
141
201
  name: "USD Coin",
142
202
  version: "2"
143
203
  },
204
+ tokens: {
205
+ usdc: {
206
+ address: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
207
+ decimals: 6,
208
+ name: "USD Coin",
209
+ version: "2"
210
+ },
211
+ ausd: {
212
+ address: "0x00000000eFE302BEAA2b3e6e1b18d08D69a9012a",
213
+ decimals: 6,
214
+ name: "Agora USD",
215
+ version: "1"
216
+ }
217
+ },
144
218
  x402: {
145
219
  facilitatorUrl: DEFAULT_FACILITATOR_URL,
146
220
  enabled: true
@@ -165,6 +239,20 @@ var SUPPORTED_CHAINS = {
165
239
  name: "USD Coin",
166
240
  version: "2"
167
241
  },
242
+ tokens: {
243
+ usdc: {
244
+ address: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
245
+ decimals: 6,
246
+ name: "USD Coin",
247
+ version: "2"
248
+ },
249
+ ausd: {
250
+ address: "0x00000000eFE302BEAA2b3e6e1b18d08D69a9012a",
251
+ decimals: 6,
252
+ name: "Agora USD",
253
+ version: "1"
254
+ }
255
+ },
168
256
  x402: {
169
257
  facilitatorUrl: DEFAULT_FACILITATOR_URL,
170
258
  enabled: true
@@ -189,6 +277,14 @@ var SUPPORTED_CHAINS = {
189
277
  name: "USD Coin",
190
278
  version: "2"
191
279
  },
280
+ tokens: {
281
+ usdc: {
282
+ address: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
283
+ decimals: 6,
284
+ name: "USD Coin",
285
+ version: "2"
286
+ }
287
+ },
192
288
  x402: {
193
289
  facilitatorUrl: DEFAULT_FACILITATOR_URL,
194
290
  enabled: true
@@ -214,6 +310,15 @@ var SUPPORTED_CHAINS = {
214
310
  // Celo uses "USDC" not "USD Coin" for EIP-712
215
311
  version: "2"
216
312
  },
313
+ tokens: {
314
+ usdc: {
315
+ address: "0xcebA9300f2b948710d2653dD7B07f33A8B32118C",
316
+ decimals: 6,
317
+ name: "USDC",
318
+ // Celo uses "USDC" not "USD Coin" for EIP-712
319
+ version: "2"
320
+ }
321
+ },
217
322
  x402: {
218
323
  facilitatorUrl: DEFAULT_FACILITATOR_URL,
219
324
  enabled: true
@@ -239,6 +344,15 @@ var SUPPORTED_CHAINS = {
239
344
  // HyperEVM uses "USDC" not "USD Coin"
240
345
  version: "2"
241
346
  },
347
+ tokens: {
348
+ usdc: {
349
+ address: "0xb88339CB7199b77E23DB6E890353E22632Ba630f",
350
+ decimals: 6,
351
+ name: "USDC",
352
+ // HyperEVM uses "USDC" not "USD Coin"
353
+ version: "2"
354
+ }
355
+ },
242
356
  x402: {
243
357
  facilitatorUrl: DEFAULT_FACILITATOR_URL,
244
358
  enabled: true
@@ -264,6 +378,15 @@ var SUPPORTED_CHAINS = {
264
378
  // Unichain uses "USDC" not "USD Coin"
265
379
  version: "2"
266
380
  },
381
+ tokens: {
382
+ usdc: {
383
+ address: "0x078d782b760474a361dda0af3839290b0ef57ad6",
384
+ decimals: 6,
385
+ name: "USDC",
386
+ // Unichain uses "USDC" not "USD Coin"
387
+ version: "2"
388
+ }
389
+ },
267
390
  x402: {
268
391
  facilitatorUrl: DEFAULT_FACILITATOR_URL,
269
392
  enabled: true
@@ -289,6 +412,21 @@ var SUPPORTED_CHAINS = {
289
412
  // Monad uses "USDC" not "USD Coin"
290
413
  version: "2"
291
414
  },
415
+ tokens: {
416
+ usdc: {
417
+ address: "0x754704bc059f8c67012fed69bc8a327a5aafb603",
418
+ decimals: 6,
419
+ name: "USDC",
420
+ // Monad uses "USDC" not "USD Coin"
421
+ version: "2"
422
+ },
423
+ ausd: {
424
+ address: "0x00000000eFE302BEAA2b3e6e1b18d08D69a9012a",
425
+ decimals: 6,
426
+ name: "Agora USD",
427
+ version: "1"
428
+ }
429
+ },
292
430
  x402: {
293
431
  facilitatorUrl: DEFAULT_FACILITATOR_URL,
294
432
  enabled: true
@@ -418,6 +556,17 @@ function getChainById(chainId) {
418
556
  function getChainByName(name) {
419
557
  return SUPPORTED_CHAINS[name.toLowerCase()];
420
558
  }
559
+ function getTokenConfig(chainName, tokenType = "usdc") {
560
+ const chain = getChainByName(chainName);
561
+ if (!chain) return void 0;
562
+ if (chain.tokens && chain.tokens[tokenType]) {
563
+ return chain.tokens[tokenType];
564
+ }
565
+ if (tokenType === "usdc") {
566
+ return chain.usdc;
567
+ }
568
+ return void 0;
569
+ }
421
570
 
422
571
  // src/providers/evm/index.ts
423
572
  var EVMProvider = class {
@@ -549,18 +698,39 @@ var EVMProvider = class {
549
698
  return this.chainName;
550
699
  }
551
700
  /**
552
- * Get USDC balance
701
+ * Get token balance (defaults to USDC for backward compatibility)
702
+ *
703
+ * @param chainConfig - Chain configuration
704
+ * @param tokenType - Token type to check balance for (defaults to 'usdc')
705
+ * @returns Formatted balance string
553
706
  */
554
- async getBalance(chainConfig) {
707
+ async getBalance(chainConfig, tokenType = "usdc") {
555
708
  if (!this.address) {
556
709
  throw new X402Error("Wallet not connected", "WALLET_NOT_CONNECTED");
557
710
  }
558
- const publicProvider = new ethers.ethers.JsonRpcProvider(chainConfig.rpcUrl);
559
- const usdcAbi = ["function balanceOf(address owner) view returns (uint256)"];
560
- const usdcContract = new ethers.ethers.Contract(chainConfig.usdc.address, usdcAbi, publicProvider);
711
+ const tokenConfig = getTokenConfig(chainConfig.name, tokenType);
712
+ if (!tokenConfig) {
713
+ const fallbackConfig = chainConfig.usdc;
714
+ if (!fallbackConfig) {
715
+ throw new X402Error(`Token ${tokenType} not supported on ${chainConfig.name}`, "INVALID_CONFIG");
716
+ }
717
+ return this.getBalanceWithConfig(chainConfig.rpcUrl, fallbackConfig);
718
+ }
719
+ return this.getBalanceWithConfig(chainConfig.rpcUrl, tokenConfig);
720
+ }
721
+ /**
722
+ * Internal helper to get balance using a token config
723
+ */
724
+ async getBalanceWithConfig(rpcUrl, tokenConfig) {
725
+ if (!this.address) {
726
+ return "0.00";
727
+ }
728
+ const publicProvider = new ethers.ethers.JsonRpcProvider(rpcUrl);
729
+ const tokenAbi = ["function balanceOf(address owner) view returns (uint256)"];
730
+ const tokenContract = new ethers.ethers.Contract(tokenConfig.address, tokenAbi, publicProvider);
561
731
  try {
562
- const balance = await usdcContract.balanceOf(this.address);
563
- const formatted = ethers.ethers.formatUnits(balance, chainConfig.usdc.decimals);
732
+ const balance = await tokenContract.balanceOf(this.address);
733
+ const formatted = ethers.ethers.formatUnits(balance, tokenConfig.decimals);
564
734
  return parseFloat(formatted).toFixed(2);
565
735
  } catch {
566
736
  return "0.00";
@@ -568,11 +738,27 @@ var EVMProvider = class {
568
738
  }
569
739
  /**
570
740
  * Create EVM payment (EIP-712 TransferWithAuthorization)
741
+ *
742
+ * Supports multi-token payments. If paymentInfo.tokenType is specified,
743
+ * it will use the appropriate token configuration. Defaults to USDC
744
+ * for backward compatibility.
745
+ *
746
+ * @param paymentInfo - Payment details including amount and recipient
747
+ * @param chainConfig - Chain configuration
748
+ * @returns JSON-encoded payment payload
571
749
  */
572
750
  async signPayment(paymentInfo, chainConfig) {
573
751
  if (!this.signer || !this.address) {
574
752
  throw new X402Error("Wallet not connected", "WALLET_NOT_CONNECTED");
575
753
  }
754
+ const tokenType = paymentInfo.tokenType || "usdc";
755
+ const tokenConfig = getTokenConfig(chainConfig.name, tokenType);
756
+ if (!tokenConfig) {
757
+ throw new X402Error(
758
+ `Token ${tokenType} not supported on ${chainConfig.name}`,
759
+ "CHAIN_NOT_SUPPORTED"
760
+ );
761
+ }
576
762
  const recipient = paymentInfo.recipients?.evm || paymentInfo.recipient;
577
763
  const nonceBytes = new Uint8Array(32);
578
764
  if (typeof window !== "undefined" && window.crypto) {
@@ -587,10 +773,10 @@ var EVMProvider = class {
587
773
  const validityWindowSeconds = chainConfig.name === "base" ? 300 : 60;
588
774
  const validBefore = Math.floor(Date.now() / 1e3) + validityWindowSeconds;
589
775
  const domain = {
590
- name: chainConfig.usdc.name,
591
- version: chainConfig.usdc.version,
776
+ name: tokenConfig.name,
777
+ version: tokenConfig.version,
592
778
  chainId: chainConfig.chainId,
593
- verifyingContract: chainConfig.usdc.address
779
+ verifyingContract: tokenConfig.address
594
780
  };
595
781
  const types = {
596
782
  TransferWithAuthorization: [
@@ -602,7 +788,7 @@ var EVMProvider = class {
602
788
  { name: "nonce", type: "bytes32" }
603
789
  ]
604
790
  };
605
- const value = ethers.ethers.parseUnits(paymentInfo.amount, chainConfig.usdc.decimals);
791
+ const value = ethers.ethers.parseUnits(paymentInfo.amount, tokenConfig.decimals);
606
792
  const from = this.address;
607
793
  const to = ethers.ethers.getAddress(recipient);
608
794
  const message = {
@@ -638,7 +824,7 @@ var EVMProvider = class {
638
824
  r: sig.r,
639
825
  s: sig.s,
640
826
  chainId: chainConfig.chainId,
641
- token: chainConfig.usdc.address
827
+ token: tokenConfig.address
642
828
  };
643
829
  return JSON.stringify(payload);
644
830
  }