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.
- package/README.md +280 -15
- package/dist/adapters/index.d.mts +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/adapters/index.js +138 -0
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/index.mjs +138 -0
- package/dist/adapters/index.mjs.map +1 -1
- package/dist/{index-MTBgC_SL.d.mts → index-BG738nMY.d.mts} +43 -4
- package/dist/{index-MTBgC_SL.d.ts → index-BG738nMY.d.ts} +43 -4
- package/dist/{index-Db8dWNam.d.ts → index-I60aHxwu.d.mts} +33 -2
- package/dist/{index-D0N_SYpK.d.mts → index-OZTSi1rJ.d.ts} +33 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +180 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +177 -1
- package/dist/index.mjs.map +1 -1
- package/dist/providers/evm/index.d.mts +19 -3
- package/dist/providers/evm/index.d.ts +19 -3
- package/dist/providers/evm/index.js +198 -12
- package/dist/providers/evm/index.js.map +1 -1
- package/dist/providers/evm/index.mjs +198 -12
- package/dist/providers/evm/index.mjs.map +1 -1
- package/dist/providers/near/index.d.mts +1 -1
- package/dist/providers/near/index.d.ts +1 -1
- package/dist/providers/near/index.js.map +1 -1
- package/dist/providers/near/index.mjs.map +1 -1
- package/dist/providers/solana/index.d.mts +1 -1
- package/dist/providers/solana/index.d.ts +1 -1
- package/dist/providers/solana/index.js +138 -0
- package/dist/providers/solana/index.js.map +1 -1
- package/dist/providers/solana/index.mjs +138 -0
- package/dist/providers/solana/index.mjs.map +1 -1
- package/dist/providers/stellar/index.d.mts +1 -1
- package/dist/providers/stellar/index.d.ts +1 -1
- package/dist/providers/stellar/index.js.map +1 -1
- package/dist/providers/stellar/index.mjs.map +1 -1
- package/dist/react/index.d.mts +3 -3
- package/dist/react/index.d.ts +3 -3
- package/dist/react/index.js +138 -0
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +138 -0
- package/dist/react/index.mjs.map +1 -1
- package/dist/utils/index.d.mts +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +138 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +138 -0
- package/dist/utils/index.mjs.map +1 -1
- package/package.json +5 -2
- package/src/chains/index.ts +225 -1
- package/src/index.ts +9 -0
- package/src/providers/evm/index.ts +64 -16
- package/src/types/index.ts +44 -3
|
@@ -65,6 +65,20 @@ var SUPPORTED_CHAINS = {
|
|
|
65
65
|
name: "USD Coin",
|
|
66
66
|
version: "2"
|
|
67
67
|
},
|
|
68
|
+
tokens: {
|
|
69
|
+
usdc: {
|
|
70
|
+
address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
71
|
+
decimals: 6,
|
|
72
|
+
name: "USD Coin",
|
|
73
|
+
version: "2"
|
|
74
|
+
},
|
|
75
|
+
eurc: {
|
|
76
|
+
address: "0x60a3E35Cc302bFA44Cb288Bc5a4F316Fdb1adb42",
|
|
77
|
+
decimals: 6,
|
|
78
|
+
name: "EURC",
|
|
79
|
+
version: "2"
|
|
80
|
+
}
|
|
81
|
+
},
|
|
68
82
|
x402: {
|
|
69
83
|
facilitatorUrl: DEFAULT_FACILITATOR_URL,
|
|
70
84
|
enabled: true
|
|
@@ -89,6 +103,26 @@ var SUPPORTED_CHAINS = {
|
|
|
89
103
|
name: "USD Coin",
|
|
90
104
|
version: "2"
|
|
91
105
|
},
|
|
106
|
+
tokens: {
|
|
107
|
+
usdc: {
|
|
108
|
+
address: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
|
|
109
|
+
decimals: 6,
|
|
110
|
+
name: "USD Coin",
|
|
111
|
+
version: "2"
|
|
112
|
+
},
|
|
113
|
+
eurc: {
|
|
114
|
+
address: "0xC891EB4cbdEFf6e073e859e987815Ed1505c2ACD",
|
|
115
|
+
decimals: 6,
|
|
116
|
+
name: "EURC",
|
|
117
|
+
version: "2"
|
|
118
|
+
},
|
|
119
|
+
ausd: {
|
|
120
|
+
address: "0x00000000eFE302BEAA2b3e6e1b18d08D69a9012a",
|
|
121
|
+
decimals: 6,
|
|
122
|
+
name: "Agora USD",
|
|
123
|
+
version: "1"
|
|
124
|
+
}
|
|
125
|
+
},
|
|
92
126
|
x402: {
|
|
93
127
|
facilitatorUrl: DEFAULT_FACILITATOR_URL,
|
|
94
128
|
enabled: true
|
|
@@ -113,6 +147,32 @@ var SUPPORTED_CHAINS = {
|
|
|
113
147
|
name: "USD Coin",
|
|
114
148
|
version: "2"
|
|
115
149
|
},
|
|
150
|
+
tokens: {
|
|
151
|
+
usdc: {
|
|
152
|
+
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
153
|
+
decimals: 6,
|
|
154
|
+
name: "USD Coin",
|
|
155
|
+
version: "2"
|
|
156
|
+
},
|
|
157
|
+
eurc: {
|
|
158
|
+
address: "0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c",
|
|
159
|
+
decimals: 6,
|
|
160
|
+
name: "EURC",
|
|
161
|
+
version: "2"
|
|
162
|
+
},
|
|
163
|
+
ausd: {
|
|
164
|
+
address: "0x00000000eFE302BEAA2b3e6e1b18d08D69a9012a",
|
|
165
|
+
decimals: 6,
|
|
166
|
+
name: "Agora USD",
|
|
167
|
+
version: "1"
|
|
168
|
+
},
|
|
169
|
+
pyusd: {
|
|
170
|
+
address: "0x6c3ea9036406852006290770BEdFcAbA0e23A0e8",
|
|
171
|
+
decimals: 6,
|
|
172
|
+
name: "PayPal USD",
|
|
173
|
+
version: "1"
|
|
174
|
+
}
|
|
175
|
+
},
|
|
116
176
|
x402: {
|
|
117
177
|
facilitatorUrl: DEFAULT_FACILITATOR_URL,
|
|
118
178
|
enabled: true
|
|
@@ -137,6 +197,20 @@ var SUPPORTED_CHAINS = {
|
|
|
137
197
|
name: "USD Coin",
|
|
138
198
|
version: "2"
|
|
139
199
|
},
|
|
200
|
+
tokens: {
|
|
201
|
+
usdc: {
|
|
202
|
+
address: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
|
|
203
|
+
decimals: 6,
|
|
204
|
+
name: "USD Coin",
|
|
205
|
+
version: "2"
|
|
206
|
+
},
|
|
207
|
+
ausd: {
|
|
208
|
+
address: "0x00000000eFE302BEAA2b3e6e1b18d08D69a9012a",
|
|
209
|
+
decimals: 6,
|
|
210
|
+
name: "Agora USD",
|
|
211
|
+
version: "1"
|
|
212
|
+
}
|
|
213
|
+
},
|
|
140
214
|
x402: {
|
|
141
215
|
facilitatorUrl: DEFAULT_FACILITATOR_URL,
|
|
142
216
|
enabled: true
|
|
@@ -161,6 +235,20 @@ var SUPPORTED_CHAINS = {
|
|
|
161
235
|
name: "USD Coin",
|
|
162
236
|
version: "2"
|
|
163
237
|
},
|
|
238
|
+
tokens: {
|
|
239
|
+
usdc: {
|
|
240
|
+
address: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
241
|
+
decimals: 6,
|
|
242
|
+
name: "USD Coin",
|
|
243
|
+
version: "2"
|
|
244
|
+
},
|
|
245
|
+
ausd: {
|
|
246
|
+
address: "0x00000000eFE302BEAA2b3e6e1b18d08D69a9012a",
|
|
247
|
+
decimals: 6,
|
|
248
|
+
name: "Agora USD",
|
|
249
|
+
version: "1"
|
|
250
|
+
}
|
|
251
|
+
},
|
|
164
252
|
x402: {
|
|
165
253
|
facilitatorUrl: DEFAULT_FACILITATOR_URL,
|
|
166
254
|
enabled: true
|
|
@@ -185,6 +273,14 @@ var SUPPORTED_CHAINS = {
|
|
|
185
273
|
name: "USD Coin",
|
|
186
274
|
version: "2"
|
|
187
275
|
},
|
|
276
|
+
tokens: {
|
|
277
|
+
usdc: {
|
|
278
|
+
address: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
|
|
279
|
+
decimals: 6,
|
|
280
|
+
name: "USD Coin",
|
|
281
|
+
version: "2"
|
|
282
|
+
}
|
|
283
|
+
},
|
|
188
284
|
x402: {
|
|
189
285
|
facilitatorUrl: DEFAULT_FACILITATOR_URL,
|
|
190
286
|
enabled: true
|
|
@@ -210,6 +306,15 @@ var SUPPORTED_CHAINS = {
|
|
|
210
306
|
// Celo uses "USDC" not "USD Coin" for EIP-712
|
|
211
307
|
version: "2"
|
|
212
308
|
},
|
|
309
|
+
tokens: {
|
|
310
|
+
usdc: {
|
|
311
|
+
address: "0xcebA9300f2b948710d2653dD7B07f33A8B32118C",
|
|
312
|
+
decimals: 6,
|
|
313
|
+
name: "USDC",
|
|
314
|
+
// Celo uses "USDC" not "USD Coin" for EIP-712
|
|
315
|
+
version: "2"
|
|
316
|
+
}
|
|
317
|
+
},
|
|
213
318
|
x402: {
|
|
214
319
|
facilitatorUrl: DEFAULT_FACILITATOR_URL,
|
|
215
320
|
enabled: true
|
|
@@ -235,6 +340,15 @@ var SUPPORTED_CHAINS = {
|
|
|
235
340
|
// HyperEVM uses "USDC" not "USD Coin"
|
|
236
341
|
version: "2"
|
|
237
342
|
},
|
|
343
|
+
tokens: {
|
|
344
|
+
usdc: {
|
|
345
|
+
address: "0xb88339CB7199b77E23DB6E890353E22632Ba630f",
|
|
346
|
+
decimals: 6,
|
|
347
|
+
name: "USDC",
|
|
348
|
+
// HyperEVM uses "USDC" not "USD Coin"
|
|
349
|
+
version: "2"
|
|
350
|
+
}
|
|
351
|
+
},
|
|
238
352
|
x402: {
|
|
239
353
|
facilitatorUrl: DEFAULT_FACILITATOR_URL,
|
|
240
354
|
enabled: true
|
|
@@ -260,6 +374,15 @@ var SUPPORTED_CHAINS = {
|
|
|
260
374
|
// Unichain uses "USDC" not "USD Coin"
|
|
261
375
|
version: "2"
|
|
262
376
|
},
|
|
377
|
+
tokens: {
|
|
378
|
+
usdc: {
|
|
379
|
+
address: "0x078d782b760474a361dda0af3839290b0ef57ad6",
|
|
380
|
+
decimals: 6,
|
|
381
|
+
name: "USDC",
|
|
382
|
+
// Unichain uses "USDC" not "USD Coin"
|
|
383
|
+
version: "2"
|
|
384
|
+
}
|
|
385
|
+
},
|
|
263
386
|
x402: {
|
|
264
387
|
facilitatorUrl: DEFAULT_FACILITATOR_URL,
|
|
265
388
|
enabled: true
|
|
@@ -285,6 +408,21 @@ var SUPPORTED_CHAINS = {
|
|
|
285
408
|
// Monad uses "USDC" not "USD Coin"
|
|
286
409
|
version: "2"
|
|
287
410
|
},
|
|
411
|
+
tokens: {
|
|
412
|
+
usdc: {
|
|
413
|
+
address: "0x754704bc059f8c67012fed69bc8a327a5aafb603",
|
|
414
|
+
decimals: 6,
|
|
415
|
+
name: "USDC",
|
|
416
|
+
// Monad uses "USDC" not "USD Coin"
|
|
417
|
+
version: "2"
|
|
418
|
+
},
|
|
419
|
+
ausd: {
|
|
420
|
+
address: "0x00000000eFE302BEAA2b3e6e1b18d08D69a9012a",
|
|
421
|
+
decimals: 6,
|
|
422
|
+
name: "Agora USD",
|
|
423
|
+
version: "1"
|
|
424
|
+
}
|
|
425
|
+
},
|
|
288
426
|
x402: {
|
|
289
427
|
facilitatorUrl: DEFAULT_FACILITATOR_URL,
|
|
290
428
|
enabled: true
|
|
@@ -414,6 +552,17 @@ function getChainById(chainId) {
|
|
|
414
552
|
function getChainByName(name) {
|
|
415
553
|
return SUPPORTED_CHAINS[name.toLowerCase()];
|
|
416
554
|
}
|
|
555
|
+
function getTokenConfig(chainName, tokenType = "usdc") {
|
|
556
|
+
const chain = getChainByName(chainName);
|
|
557
|
+
if (!chain) return void 0;
|
|
558
|
+
if (chain.tokens && chain.tokens[tokenType]) {
|
|
559
|
+
return chain.tokens[tokenType];
|
|
560
|
+
}
|
|
561
|
+
if (tokenType === "usdc") {
|
|
562
|
+
return chain.usdc;
|
|
563
|
+
}
|
|
564
|
+
return void 0;
|
|
565
|
+
}
|
|
417
566
|
|
|
418
567
|
// src/providers/evm/index.ts
|
|
419
568
|
var EVMProvider = class {
|
|
@@ -545,18 +694,39 @@ var EVMProvider = class {
|
|
|
545
694
|
return this.chainName;
|
|
546
695
|
}
|
|
547
696
|
/**
|
|
548
|
-
* Get USDC
|
|
697
|
+
* Get token balance (defaults to USDC for backward compatibility)
|
|
698
|
+
*
|
|
699
|
+
* @param chainConfig - Chain configuration
|
|
700
|
+
* @param tokenType - Token type to check balance for (defaults to 'usdc')
|
|
701
|
+
* @returns Formatted balance string
|
|
549
702
|
*/
|
|
550
|
-
async getBalance(chainConfig) {
|
|
703
|
+
async getBalance(chainConfig, tokenType = "usdc") {
|
|
551
704
|
if (!this.address) {
|
|
552
705
|
throw new X402Error("Wallet not connected", "WALLET_NOT_CONNECTED");
|
|
553
706
|
}
|
|
554
|
-
const
|
|
555
|
-
|
|
556
|
-
|
|
707
|
+
const tokenConfig = getTokenConfig(chainConfig.name, tokenType);
|
|
708
|
+
if (!tokenConfig) {
|
|
709
|
+
const fallbackConfig = chainConfig.usdc;
|
|
710
|
+
if (!fallbackConfig) {
|
|
711
|
+
throw new X402Error(`Token ${tokenType} not supported on ${chainConfig.name}`, "INVALID_CONFIG");
|
|
712
|
+
}
|
|
713
|
+
return this.getBalanceWithConfig(chainConfig.rpcUrl, fallbackConfig);
|
|
714
|
+
}
|
|
715
|
+
return this.getBalanceWithConfig(chainConfig.rpcUrl, tokenConfig);
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* Internal helper to get balance using a token config
|
|
719
|
+
*/
|
|
720
|
+
async getBalanceWithConfig(rpcUrl, tokenConfig) {
|
|
721
|
+
if (!this.address) {
|
|
722
|
+
return "0.00";
|
|
723
|
+
}
|
|
724
|
+
const publicProvider = new ethers.JsonRpcProvider(rpcUrl);
|
|
725
|
+
const tokenAbi = ["function balanceOf(address owner) view returns (uint256)"];
|
|
726
|
+
const tokenContract = new ethers.Contract(tokenConfig.address, tokenAbi, publicProvider);
|
|
557
727
|
try {
|
|
558
|
-
const balance = await
|
|
559
|
-
const formatted = ethers.formatUnits(balance,
|
|
728
|
+
const balance = await tokenContract.balanceOf(this.address);
|
|
729
|
+
const formatted = ethers.formatUnits(balance, tokenConfig.decimals);
|
|
560
730
|
return parseFloat(formatted).toFixed(2);
|
|
561
731
|
} catch {
|
|
562
732
|
return "0.00";
|
|
@@ -564,11 +734,27 @@ var EVMProvider = class {
|
|
|
564
734
|
}
|
|
565
735
|
/**
|
|
566
736
|
* Create EVM payment (EIP-712 TransferWithAuthorization)
|
|
737
|
+
*
|
|
738
|
+
* Supports multi-token payments. If paymentInfo.tokenType is specified,
|
|
739
|
+
* it will use the appropriate token configuration. Defaults to USDC
|
|
740
|
+
* for backward compatibility.
|
|
741
|
+
*
|
|
742
|
+
* @param paymentInfo - Payment details including amount and recipient
|
|
743
|
+
* @param chainConfig - Chain configuration
|
|
744
|
+
* @returns JSON-encoded payment payload
|
|
567
745
|
*/
|
|
568
746
|
async signPayment(paymentInfo, chainConfig) {
|
|
569
747
|
if (!this.signer || !this.address) {
|
|
570
748
|
throw new X402Error("Wallet not connected", "WALLET_NOT_CONNECTED");
|
|
571
749
|
}
|
|
750
|
+
const tokenType = paymentInfo.tokenType || "usdc";
|
|
751
|
+
const tokenConfig = getTokenConfig(chainConfig.name, tokenType);
|
|
752
|
+
if (!tokenConfig) {
|
|
753
|
+
throw new X402Error(
|
|
754
|
+
`Token ${tokenType} not supported on ${chainConfig.name}`,
|
|
755
|
+
"CHAIN_NOT_SUPPORTED"
|
|
756
|
+
);
|
|
757
|
+
}
|
|
572
758
|
const recipient = paymentInfo.recipients?.evm || paymentInfo.recipient;
|
|
573
759
|
const nonceBytes = new Uint8Array(32);
|
|
574
760
|
if (typeof window !== "undefined" && window.crypto) {
|
|
@@ -583,10 +769,10 @@ var EVMProvider = class {
|
|
|
583
769
|
const validityWindowSeconds = chainConfig.name === "base" ? 300 : 60;
|
|
584
770
|
const validBefore = Math.floor(Date.now() / 1e3) + validityWindowSeconds;
|
|
585
771
|
const domain = {
|
|
586
|
-
name:
|
|
587
|
-
version:
|
|
772
|
+
name: tokenConfig.name,
|
|
773
|
+
version: tokenConfig.version,
|
|
588
774
|
chainId: chainConfig.chainId,
|
|
589
|
-
verifyingContract:
|
|
775
|
+
verifyingContract: tokenConfig.address
|
|
590
776
|
};
|
|
591
777
|
const types = {
|
|
592
778
|
TransferWithAuthorization: [
|
|
@@ -598,7 +784,7 @@ var EVMProvider = class {
|
|
|
598
784
|
{ name: "nonce", type: "bytes32" }
|
|
599
785
|
]
|
|
600
786
|
};
|
|
601
|
-
const value = ethers.parseUnits(paymentInfo.amount,
|
|
787
|
+
const value = ethers.parseUnits(paymentInfo.amount, tokenConfig.decimals);
|
|
602
788
|
const from = this.address;
|
|
603
789
|
const to = ethers.getAddress(recipient);
|
|
604
790
|
const message = {
|
|
@@ -634,7 +820,7 @@ var EVMProvider = class {
|
|
|
634
820
|
r: sig.r,
|
|
635
821
|
s: sig.s,
|
|
636
822
|
chainId: chainConfig.chainId,
|
|
637
|
-
token:
|
|
823
|
+
token: tokenConfig.address
|
|
638
824
|
};
|
|
639
825
|
return JSON.stringify(payload);
|
|
640
826
|
}
|