@voyage_ai/v402-web-ts 1.0.2 → 1.0.5
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/dist/index.d.mts +5 -13
- package/dist/index.d.ts +5 -13
- package/dist/index.js +84 -127
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +84 -125
- package/dist/index.mjs.map +1 -1
- package/dist/react/{chunk-WDPIFLXY.mjs → chunk-OZVQNPH3.mjs} +4 -3
- package/dist/react/chunk-OZVQNPH3.mjs.map +1 -0
- package/dist/react/index.js +71 -70
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +71 -71
- package/dist/react/index.mjs.map +1 -1
- package/dist/react/{wallet-discovery-RN3DPV6V.mjs → wallet-discovery-CSCYXTOV.mjs} +2 -2
- package/package.json +1 -1
- package/dist/react/chunk-WDPIFLXY.mjs.map +0 -1
- /package/dist/react/{wallet-discovery-RN3DPV6V.mjs.map → wallet-discovery-CSCYXTOV.mjs.map} +0 -0
package/dist/index.d.mts
CHANGED
|
@@ -103,7 +103,7 @@ interface CreateSvmPaymentHeaderParams {
|
|
|
103
103
|
/**
|
|
104
104
|
* EVM network enum (common networks)
|
|
105
105
|
*/
|
|
106
|
-
declare const EvmNetworkSchema: z.ZodEnum<["ethereum", "sepolia", "base", "base-sepolia", "polygon", "arbitrum", "
|
|
106
|
+
declare const EvmNetworkSchema: z.ZodEnum<["ethereum", "sepolia", "base", "base-sepolia", "polygon", "arbitrum", "xlayer", "xlayer-testnet"]>;
|
|
107
107
|
type EvmNetwork = z.infer<typeof EvmNetworkSchema>;
|
|
108
108
|
/**
|
|
109
109
|
* EVM payment payload schema (conforms to x402 spec)
|
|
@@ -111,7 +111,7 @@ type EvmNetwork = z.infer<typeof EvmNetworkSchema>;
|
|
|
111
111
|
declare const EvmPaymentPayloadSchema: z.ZodObject<{
|
|
112
112
|
x402Version: z.ZodLiteral<1>;
|
|
113
113
|
scheme: z.ZodLiteral<"exact">;
|
|
114
|
-
network: z.ZodEnum<["ethereum", "sepolia", "base", "base-sepolia", "polygon", "arbitrum", "
|
|
114
|
+
network: z.ZodEnum<["ethereum", "sepolia", "base", "base-sepolia", "polygon", "arbitrum", "xlayer", "xlayer-testnet"]>;
|
|
115
115
|
payload: z.ZodObject<{
|
|
116
116
|
signature: z.ZodString;
|
|
117
117
|
authorization: z.ZodObject<{
|
|
@@ -160,7 +160,7 @@ declare const EvmPaymentPayloadSchema: z.ZodObject<{
|
|
|
160
160
|
}, "strip", z.ZodTypeAny, {
|
|
161
161
|
x402Version: 1;
|
|
162
162
|
scheme: "exact";
|
|
163
|
-
network: "ethereum" | "sepolia" | "base" | "base-sepolia" | "polygon" | "arbitrum" | "
|
|
163
|
+
network: "ethereum" | "sepolia" | "base" | "base-sepolia" | "polygon" | "arbitrum" | "xlayer" | "xlayer-testnet";
|
|
164
164
|
payload: {
|
|
165
165
|
signature: string;
|
|
166
166
|
authorization: {
|
|
@@ -175,7 +175,7 @@ declare const EvmPaymentPayloadSchema: z.ZodObject<{
|
|
|
175
175
|
}, {
|
|
176
176
|
x402Version: 1;
|
|
177
177
|
scheme: "exact";
|
|
178
|
-
network: "ethereum" | "sepolia" | "base" | "base-sepolia" | "polygon" | "arbitrum" | "
|
|
178
|
+
network: "ethereum" | "sepolia" | "base" | "base-sepolia" | "polygon" | "arbitrum" | "xlayer" | "xlayer-testnet";
|
|
179
179
|
payload: {
|
|
180
180
|
signature: string;
|
|
181
181
|
authorization: {
|
|
@@ -219,14 +219,6 @@ interface EvmNetworkConfig {
|
|
|
219
219
|
decimals: number;
|
|
220
220
|
};
|
|
221
221
|
}
|
|
222
|
-
/**
|
|
223
|
-
* Common EVM network configurations
|
|
224
|
-
*/
|
|
225
|
-
declare const EVM_NETWORK_CONFIGS: Record<string, EvmNetworkConfig>;
|
|
226
|
-
/**
|
|
227
|
-
* Get chain ID from network name
|
|
228
|
-
*/
|
|
229
|
-
declare function getChainId(network: string): number;
|
|
230
222
|
|
|
231
223
|
/**
|
|
232
224
|
* SVM (Solana) Payment Header Builder
|
|
@@ -535,4 +527,4 @@ declare function fromAtomicUnits(atomicUnits: bigint | number, decimals: number)
|
|
|
535
527
|
*/
|
|
536
528
|
declare function is402Response(response: any): boolean;
|
|
537
529
|
|
|
538
|
-
export { type CreateEvmPaymentHeaderParams, type CreateSvmPaymentHeaderParams,
|
|
530
|
+
export { type CreateEvmPaymentHeaderParams, type CreateSvmPaymentHeaderParams, type EvmClientConfig, type EvmNetwork, type EvmNetworkConfig, EvmNetworkSchema, type EvmPaymentPayload, EvmPaymentPayloadSchema, type EvmWalletAdapter, NetworkType, type SolanaNetwork, SolanaNetworkSchema, type SolanaPaymentPayload, SolanaPaymentPayloadSchema, type SvmClientConfig, type WalletAdapter, createEvmPaymentFetch, createEvmPaymentHeader, createSvmPaymentFetch, createSvmPaymentHeader, formatAddress, fromAtomicUnits, getChainIdFromNetwork, getDefaultSolanaRpcUrl, getNetworkDisplayName, getNetworkType, getWalletDisplayName, getWalletInstallUrl, getWalletProvider, handleEvmPayment, handleSvmPayment, is402Response, isEvmAddress, isEvmNetwork, isSolanaAddress, isSolanaNetwork, isWalletInstalled, makePayment, toAtomicUnits };
|
package/dist/index.d.ts
CHANGED
|
@@ -103,7 +103,7 @@ interface CreateSvmPaymentHeaderParams {
|
|
|
103
103
|
/**
|
|
104
104
|
* EVM network enum (common networks)
|
|
105
105
|
*/
|
|
106
|
-
declare const EvmNetworkSchema: z.ZodEnum<["ethereum", "sepolia", "base", "base-sepolia", "polygon", "arbitrum", "
|
|
106
|
+
declare const EvmNetworkSchema: z.ZodEnum<["ethereum", "sepolia", "base", "base-sepolia", "polygon", "arbitrum", "xlayer", "xlayer-testnet"]>;
|
|
107
107
|
type EvmNetwork = z.infer<typeof EvmNetworkSchema>;
|
|
108
108
|
/**
|
|
109
109
|
* EVM payment payload schema (conforms to x402 spec)
|
|
@@ -111,7 +111,7 @@ type EvmNetwork = z.infer<typeof EvmNetworkSchema>;
|
|
|
111
111
|
declare const EvmPaymentPayloadSchema: z.ZodObject<{
|
|
112
112
|
x402Version: z.ZodLiteral<1>;
|
|
113
113
|
scheme: z.ZodLiteral<"exact">;
|
|
114
|
-
network: z.ZodEnum<["ethereum", "sepolia", "base", "base-sepolia", "polygon", "arbitrum", "
|
|
114
|
+
network: z.ZodEnum<["ethereum", "sepolia", "base", "base-sepolia", "polygon", "arbitrum", "xlayer", "xlayer-testnet"]>;
|
|
115
115
|
payload: z.ZodObject<{
|
|
116
116
|
signature: z.ZodString;
|
|
117
117
|
authorization: z.ZodObject<{
|
|
@@ -160,7 +160,7 @@ declare const EvmPaymentPayloadSchema: z.ZodObject<{
|
|
|
160
160
|
}, "strip", z.ZodTypeAny, {
|
|
161
161
|
x402Version: 1;
|
|
162
162
|
scheme: "exact";
|
|
163
|
-
network: "ethereum" | "sepolia" | "base" | "base-sepolia" | "polygon" | "arbitrum" | "
|
|
163
|
+
network: "ethereum" | "sepolia" | "base" | "base-sepolia" | "polygon" | "arbitrum" | "xlayer" | "xlayer-testnet";
|
|
164
164
|
payload: {
|
|
165
165
|
signature: string;
|
|
166
166
|
authorization: {
|
|
@@ -175,7 +175,7 @@ declare const EvmPaymentPayloadSchema: z.ZodObject<{
|
|
|
175
175
|
}, {
|
|
176
176
|
x402Version: 1;
|
|
177
177
|
scheme: "exact";
|
|
178
|
-
network: "ethereum" | "sepolia" | "base" | "base-sepolia" | "polygon" | "arbitrum" | "
|
|
178
|
+
network: "ethereum" | "sepolia" | "base" | "base-sepolia" | "polygon" | "arbitrum" | "xlayer" | "xlayer-testnet";
|
|
179
179
|
payload: {
|
|
180
180
|
signature: string;
|
|
181
181
|
authorization: {
|
|
@@ -219,14 +219,6 @@ interface EvmNetworkConfig {
|
|
|
219
219
|
decimals: number;
|
|
220
220
|
};
|
|
221
221
|
}
|
|
222
|
-
/**
|
|
223
|
-
* Common EVM network configurations
|
|
224
|
-
*/
|
|
225
|
-
declare const EVM_NETWORK_CONFIGS: Record<string, EvmNetworkConfig>;
|
|
226
|
-
/**
|
|
227
|
-
* Get chain ID from network name
|
|
228
|
-
*/
|
|
229
|
-
declare function getChainId(network: string): number;
|
|
230
222
|
|
|
231
223
|
/**
|
|
232
224
|
* SVM (Solana) Payment Header Builder
|
|
@@ -535,4 +527,4 @@ declare function fromAtomicUnits(atomicUnits: bigint | number, decimals: number)
|
|
|
535
527
|
*/
|
|
536
528
|
declare function is402Response(response: any): boolean;
|
|
537
529
|
|
|
538
|
-
export { type CreateEvmPaymentHeaderParams, type CreateSvmPaymentHeaderParams,
|
|
530
|
+
export { type CreateEvmPaymentHeaderParams, type CreateSvmPaymentHeaderParams, type EvmClientConfig, type EvmNetwork, type EvmNetworkConfig, EvmNetworkSchema, type EvmPaymentPayload, EvmPaymentPayloadSchema, type EvmWalletAdapter, NetworkType, type SolanaNetwork, SolanaNetworkSchema, type SolanaPaymentPayload, SolanaPaymentPayloadSchema, type SvmClientConfig, type WalletAdapter, createEvmPaymentFetch, createEvmPaymentHeader, createSvmPaymentFetch, createSvmPaymentHeader, formatAddress, fromAtomicUnits, getChainIdFromNetwork, getDefaultSolanaRpcUrl, getNetworkDisplayName, getNetworkType, getWalletDisplayName, getWalletInstallUrl, getWalletProvider, handleEvmPayment, handleSvmPayment, is402Response, isEvmAddress, isEvmNetwork, isSolanaAddress, isSolanaNetwork, isWalletInstalled, makePayment, toAtomicUnits };
|
package/dist/index.js
CHANGED
|
@@ -25,7 +25,7 @@ var PROD_BACK_URL;
|
|
|
25
25
|
var init_common = __esm({
|
|
26
26
|
"src/types/common.ts"() {
|
|
27
27
|
"use strict";
|
|
28
|
-
PROD_BACK_URL = true ? "
|
|
28
|
+
PROD_BACK_URL = true ? "http://localhost:3000/api/pay" : "https://v402pay.onvoyage.ai/api/pay";
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
31
|
|
|
@@ -52,19 +52,7 @@ var init_svm = __esm({
|
|
|
52
52
|
});
|
|
53
53
|
|
|
54
54
|
// src/types/evm.ts
|
|
55
|
-
|
|
56
|
-
const chainIdMap = {
|
|
57
|
-
"ethereum": 1,
|
|
58
|
-
"sepolia": 11155111,
|
|
59
|
-
"base": 8453,
|
|
60
|
-
"base-sepolia": 84532,
|
|
61
|
-
"polygon": 137,
|
|
62
|
-
"arbitrum": 42161,
|
|
63
|
-
"optimism": 10
|
|
64
|
-
};
|
|
65
|
-
return chainIdMap[network.toLowerCase()] || 1;
|
|
66
|
-
}
|
|
67
|
-
var import_zod2, import_types2, EvmNetworkSchema, EvmPaymentPayloadSchema, EVM_NETWORK_CONFIGS;
|
|
55
|
+
var import_zod2, import_types2, EvmNetworkSchema, EvmPaymentPayloadSchema;
|
|
68
56
|
var init_evm = __esm({
|
|
69
57
|
"src/types/evm.ts"() {
|
|
70
58
|
"use strict";
|
|
@@ -77,7 +65,8 @@ var init_evm = __esm({
|
|
|
77
65
|
"base-sepolia",
|
|
78
66
|
"polygon",
|
|
79
67
|
"arbitrum",
|
|
80
|
-
"
|
|
68
|
+
"xlayer",
|
|
69
|
+
"xlayer-testnet"
|
|
81
70
|
]);
|
|
82
71
|
EvmPaymentPayloadSchema = import_zod2.z.object({
|
|
83
72
|
x402Version: import_zod2.z.literal(1),
|
|
@@ -85,32 +74,6 @@ var init_evm = __esm({
|
|
|
85
74
|
network: EvmNetworkSchema,
|
|
86
75
|
payload: import_types2.ExactEvmPayloadSchema
|
|
87
76
|
});
|
|
88
|
-
EVM_NETWORK_CONFIGS = {
|
|
89
|
-
"ethereum": {
|
|
90
|
-
chainId: "0x1",
|
|
91
|
-
chainName: "Ethereum Mainnet",
|
|
92
|
-
rpcUrls: ["https://eth.llamarpc.com"],
|
|
93
|
-
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 }
|
|
94
|
-
},
|
|
95
|
-
"sepolia": {
|
|
96
|
-
chainId: "0xaa36a7",
|
|
97
|
-
chainName: "Sepolia",
|
|
98
|
-
rpcUrls: ["https://sepolia.infura.io/v3/"],
|
|
99
|
-
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 }
|
|
100
|
-
},
|
|
101
|
-
"base": {
|
|
102
|
-
chainId: "0x2105",
|
|
103
|
-
chainName: "Base",
|
|
104
|
-
rpcUrls: ["https://mainnet.base.org"],
|
|
105
|
-
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 }
|
|
106
|
-
},
|
|
107
|
-
"base-sepolia": {
|
|
108
|
-
chainId: "0x14a34",
|
|
109
|
-
chainName: "Base Sepolia",
|
|
110
|
-
rpcUrls: ["https://sepolia.base.org"],
|
|
111
|
-
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 }
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
77
|
}
|
|
115
78
|
});
|
|
116
79
|
|
|
@@ -234,7 +197,6 @@ var init_wallet = __esm({
|
|
|
234
197
|
// src/index.ts
|
|
235
198
|
var index_exports = {};
|
|
236
199
|
__export(index_exports, {
|
|
237
|
-
EVM_NETWORK_CONFIGS: () => EVM_NETWORK_CONFIGS,
|
|
238
200
|
EvmNetworkSchema: () => EvmNetworkSchema,
|
|
239
201
|
EvmPaymentPayloadSchema: () => EvmPaymentPayloadSchema,
|
|
240
202
|
SolanaNetworkSchema: () => SolanaNetworkSchema,
|
|
@@ -245,7 +207,6 @@ __export(index_exports, {
|
|
|
245
207
|
createSvmPaymentHeader: () => createSvmPaymentHeader,
|
|
246
208
|
formatAddress: () => formatAddress,
|
|
247
209
|
fromAtomicUnits: () => fromAtomicUnits,
|
|
248
|
-
getChainId: () => getChainId,
|
|
249
210
|
getChainIdFromNetwork: () => getChainIdFromNetwork,
|
|
250
211
|
getDefaultSolanaRpcUrl: () => getDefaultSolanaRpcUrl,
|
|
251
212
|
getNetworkDisplayName: () => getNetworkDisplayName,
|
|
@@ -463,6 +424,17 @@ if (typeof window !== "undefined") {
|
|
|
463
424
|
|
|
464
425
|
// src/services/evm/payment-header.ts
|
|
465
426
|
var import_ethers = require("ethers");
|
|
427
|
+
var NETWORK_NAMES = {
|
|
428
|
+
1: "Ethereum Mainnet",
|
|
429
|
+
11155111: "Sepolia Testnet",
|
|
430
|
+
8453: "Base Mainnet",
|
|
431
|
+
84532: "Base Sepolia Testnet",
|
|
432
|
+
137: "Polygon Mainnet",
|
|
433
|
+
42161: "Arbitrum One",
|
|
434
|
+
10: "Optimism Mainnet",
|
|
435
|
+
196: "XLayer Mainnet",
|
|
436
|
+
1952: "XLayer Testnet"
|
|
437
|
+
};
|
|
466
438
|
async function createEvmPaymentHeader(params) {
|
|
467
439
|
const { wallet, paymentRequirements, x402Version, chainId } = params;
|
|
468
440
|
if (!paymentRequirements?.payTo) {
|
|
@@ -476,17 +448,8 @@ async function createEvmPaymentHeader(params) {
|
|
|
476
448
|
const currentChainIdHex = await wallet.getChainId();
|
|
477
449
|
const currentChainId = parseInt(currentChainIdHex, 16);
|
|
478
450
|
if (currentChainId !== chainId) {
|
|
479
|
-
const
|
|
480
|
-
|
|
481
|
-
11155111: "Sepolia Testnet",
|
|
482
|
-
8453: "Base Mainnet",
|
|
483
|
-
84532: "Base Sepolia Testnet",
|
|
484
|
-
137: "Polygon Mainnet",
|
|
485
|
-
42161: "Arbitrum One",
|
|
486
|
-
10: "Optimism Mainnet"
|
|
487
|
-
};
|
|
488
|
-
const currentNetworkName = networkNames[currentChainId] || `Chain ${currentChainId}`;
|
|
489
|
-
const targetNetworkName = networkNames[chainId] || `Chain ${chainId}`;
|
|
451
|
+
const currentNetworkName = NETWORK_NAMES[currentChainId] || `Chain ${currentChainId}`;
|
|
452
|
+
const targetNetworkName = NETWORK_NAMES[chainId] || `Chain ${chainId}`;
|
|
490
453
|
throw new Error(
|
|
491
454
|
`Network mismatch: Your wallet is connected to ${currentNetworkName}, but payment requires ${targetNetworkName}. Please switch your wallet to the correct network.`
|
|
492
455
|
);
|
|
@@ -565,7 +528,9 @@ function getChainIdFromNetwork(network) {
|
|
|
565
528
|
"base-sepolia": 84532,
|
|
566
529
|
"polygon": 137,
|
|
567
530
|
"arbitrum": 42161,
|
|
568
|
-
"optimism": 10
|
|
531
|
+
"optimism": 10,
|
|
532
|
+
"xlayer": 196,
|
|
533
|
+
"xlayer-testnet": 1952
|
|
569
534
|
};
|
|
570
535
|
const chainId = chainIdMap[network.toLowerCase()];
|
|
571
536
|
if (!chainId) {
|
|
@@ -576,15 +541,6 @@ function getChainIdFromNetwork(network) {
|
|
|
576
541
|
|
|
577
542
|
// src/services/evm/payment-handler.ts
|
|
578
543
|
init_types();
|
|
579
|
-
var NETWORK_NAMES = {
|
|
580
|
-
1: "Ethereum Mainnet",
|
|
581
|
-
11155111: "Sepolia Testnet",
|
|
582
|
-
8453: "Base Mainnet",
|
|
583
|
-
84532: "Base Sepolia Testnet",
|
|
584
|
-
137: "Polygon Mainnet",
|
|
585
|
-
42161: "Arbitrum One",
|
|
586
|
-
10: "Optimism Mainnet"
|
|
587
|
-
};
|
|
588
544
|
async function handleEvmPayment(endpoint, config, requestInit) {
|
|
589
545
|
const { wallet, network, maxPaymentAmount } = config;
|
|
590
546
|
const initialResponse = await fetch(endpoint, {
|
|
@@ -723,6 +679,68 @@ function createEvmPaymentFetch(config) {
|
|
|
723
679
|
// src/utils/payment-helpers.ts
|
|
724
680
|
var import_ethers2 = require("ethers");
|
|
725
681
|
init_common();
|
|
682
|
+
|
|
683
|
+
// src/utils/network.ts
|
|
684
|
+
var NETWORK_TYPE_MAP = {
|
|
685
|
+
// EVM chains
|
|
686
|
+
"ethereum": "evm" /* EVM */,
|
|
687
|
+
"eth": "evm" /* EVM */,
|
|
688
|
+
"base": "evm" /* EVM */,
|
|
689
|
+
"base-sepolia": "evm" /* EVM */,
|
|
690
|
+
"polygon": "evm" /* EVM */,
|
|
691
|
+
"arbitrum": "evm" /* EVM */,
|
|
692
|
+
"optimism": "evm" /* EVM */,
|
|
693
|
+
"bsc": "evm" /* EVM */,
|
|
694
|
+
"sepolia": "evm" /* EVM */,
|
|
695
|
+
"goerli": "evm" /* EVM */,
|
|
696
|
+
"xlayer": "evm" /* EVM */,
|
|
697
|
+
"xlayer-testnet": "evm" /* EVM */,
|
|
698
|
+
// Solana/SVM
|
|
699
|
+
"solana": "solana" /* SOLANA */,
|
|
700
|
+
"solana-devnet": "solana" /* SOLANA */,
|
|
701
|
+
"solana-testnet": "solana" /* SOLANA */,
|
|
702
|
+
"solana-mainnet": "solana" /* SOLANA */,
|
|
703
|
+
"svm": "svm" /* SVM */
|
|
704
|
+
};
|
|
705
|
+
function getNetworkType(network) {
|
|
706
|
+
const normalizedNetwork = network.toLowerCase().trim();
|
|
707
|
+
return NETWORK_TYPE_MAP[normalizedNetwork] || "unknown" /* UNKNOWN */;
|
|
708
|
+
}
|
|
709
|
+
function isEvmNetwork(network) {
|
|
710
|
+
return getNetworkType(network) === "evm" /* EVM */;
|
|
711
|
+
}
|
|
712
|
+
function isSolanaNetwork(network) {
|
|
713
|
+
const type = getNetworkType(network);
|
|
714
|
+
return type === "solana" /* SOLANA */ || type === "svm" /* SVM */;
|
|
715
|
+
}
|
|
716
|
+
function isSolanaAddress(address) {
|
|
717
|
+
if (address.startsWith("0x")) {
|
|
718
|
+
return false;
|
|
719
|
+
}
|
|
720
|
+
const base58Regex = /^[1-9A-HJ-NP-Za-km-z]+$/;
|
|
721
|
+
return base58Regex.test(address) && address.length >= 32 && address.length <= 44;
|
|
722
|
+
}
|
|
723
|
+
function isEvmAddress(address) {
|
|
724
|
+
return /^0x[a-fA-F0-9]{40}$/.test(address);
|
|
725
|
+
}
|
|
726
|
+
function getNetworkDisplayName(network) {
|
|
727
|
+
const displayNames = {
|
|
728
|
+
"evm": "EVM",
|
|
729
|
+
"ethereum": "Ethereum",
|
|
730
|
+
"sepolia": "Sepolia Testnet",
|
|
731
|
+
"base": "Base",
|
|
732
|
+
"base-sepolia": "Base Sepolia",
|
|
733
|
+
"polygon": "Polygon",
|
|
734
|
+
"arbitrum": "Arbitrum",
|
|
735
|
+
"optimism": "Optimism",
|
|
736
|
+
"solana": "Solana",
|
|
737
|
+
"solana-devnet": "Solana Devnet",
|
|
738
|
+
"solana-mainnet": "Solana Mainnet"
|
|
739
|
+
};
|
|
740
|
+
return displayNames[network.toLowerCase()] || network;
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
// src/utils/payment-helpers.ts
|
|
726
744
|
async function makePayment(networkType, merchantId, endpoint = PROD_BACK_URL, additionalParams, expectedAddress) {
|
|
727
745
|
const fullEndpoint = `${endpoint}/${merchantId}`;
|
|
728
746
|
let response;
|
|
@@ -795,64 +813,6 @@ async function makePayment(networkType, merchantId, endpoint = PROD_BACK_URL, ad
|
|
|
795
813
|
return response;
|
|
796
814
|
}
|
|
797
815
|
|
|
798
|
-
// src/utils/network.ts
|
|
799
|
-
var NETWORK_TYPE_MAP = {
|
|
800
|
-
// EVM chains
|
|
801
|
-
"ethereum": "evm" /* EVM */,
|
|
802
|
-
"eth": "evm" /* EVM */,
|
|
803
|
-
"base": "evm" /* EVM */,
|
|
804
|
-
"base-sepolia": "evm" /* EVM */,
|
|
805
|
-
"polygon": "evm" /* EVM */,
|
|
806
|
-
"arbitrum": "evm" /* EVM */,
|
|
807
|
-
"optimism": "evm" /* EVM */,
|
|
808
|
-
"bsc": "evm" /* EVM */,
|
|
809
|
-
"sepolia": "evm" /* EVM */,
|
|
810
|
-
"goerli": "evm" /* EVM */,
|
|
811
|
-
// Solana/SVM
|
|
812
|
-
"solana": "solana" /* SOLANA */,
|
|
813
|
-
"solana-devnet": "solana" /* SOLANA */,
|
|
814
|
-
"solana-testnet": "solana" /* SOLANA */,
|
|
815
|
-
"solana-mainnet": "solana" /* SOLANA */,
|
|
816
|
-
"svm": "svm" /* SVM */
|
|
817
|
-
};
|
|
818
|
-
function getNetworkType(network) {
|
|
819
|
-
const normalizedNetwork = network.toLowerCase().trim();
|
|
820
|
-
return NETWORK_TYPE_MAP[normalizedNetwork] || "unknown" /* UNKNOWN */;
|
|
821
|
-
}
|
|
822
|
-
function isEvmNetwork(network) {
|
|
823
|
-
return getNetworkType(network) === "evm" /* EVM */;
|
|
824
|
-
}
|
|
825
|
-
function isSolanaNetwork(network) {
|
|
826
|
-
const type = getNetworkType(network);
|
|
827
|
-
return type === "solana" /* SOLANA */ || type === "svm" /* SVM */;
|
|
828
|
-
}
|
|
829
|
-
function isSolanaAddress(address) {
|
|
830
|
-
if (address.startsWith("0x")) {
|
|
831
|
-
return false;
|
|
832
|
-
}
|
|
833
|
-
const base58Regex = /^[1-9A-HJ-NP-Za-km-z]+$/;
|
|
834
|
-
return base58Regex.test(address) && address.length >= 32 && address.length <= 44;
|
|
835
|
-
}
|
|
836
|
-
function isEvmAddress(address) {
|
|
837
|
-
return /^0x[a-fA-F0-9]{40}$/.test(address);
|
|
838
|
-
}
|
|
839
|
-
function getNetworkDisplayName(network) {
|
|
840
|
-
const displayNames = {
|
|
841
|
-
"evm": "EVM",
|
|
842
|
-
"ethereum": "Ethereum",
|
|
843
|
-
"sepolia": "Sepolia Testnet",
|
|
844
|
-
"base": "Base",
|
|
845
|
-
"base-sepolia": "Base Sepolia",
|
|
846
|
-
"polygon": "Polygon",
|
|
847
|
-
"arbitrum": "Arbitrum",
|
|
848
|
-
"optimism": "Optimism",
|
|
849
|
-
"solana": "Solana",
|
|
850
|
-
"solana-devnet": "Solana Devnet",
|
|
851
|
-
"solana-mainnet": "Solana Mainnet"
|
|
852
|
-
};
|
|
853
|
-
return displayNames[network.toLowerCase()] || network;
|
|
854
|
-
}
|
|
855
|
-
|
|
856
816
|
// src/utils/helpers.ts
|
|
857
817
|
function toAtomicUnits(amount, decimals) {
|
|
858
818
|
return BigInt(Math.floor(amount * Math.pow(10, decimals)));
|
|
@@ -878,6 +838,7 @@ var PAYMENT_ERROR_MESSAGES = {
|
|
|
878
838
|
"network_mismatch": "Payment network does not match",
|
|
879
839
|
"invalid_payment": "Invalid payment data",
|
|
880
840
|
"verification_failed": "Payment verification failed",
|
|
841
|
+
"invalid_network": "The selected network is not supported by the payment server. Please try a different network.",
|
|
881
842
|
"invalid_exact_svm_payload_transaction_simulation_failed": "Transaction simulation failed due to insufficient balance. Please check your wallet balance carefully and ensure you have enough funds to cover the payment and transaction fees."
|
|
882
843
|
};
|
|
883
844
|
function parsePaymentError(error) {
|
|
@@ -1053,9 +1014,7 @@ async function createSvmPaymentHeader(params) {
|
|
|
1053
1014
|
);
|
|
1054
1015
|
const sourceAtaInfo = await connection.getAccountInfo(sourceAta);
|
|
1055
1016
|
if (!sourceAtaInfo) {
|
|
1056
|
-
throw new Error(
|
|
1057
|
-
`User does not have an Associated Token Account for ${paymentRequirements.asset}. Please create one first or ensure you have the required token.`
|
|
1058
|
-
);
|
|
1017
|
+
throw new Error("You don't have enough balance to complete this payment.");
|
|
1059
1018
|
}
|
|
1060
1019
|
const destAtaInfo = await connection.getAccountInfo(destinationAta);
|
|
1061
1020
|
if (!destAtaInfo) {
|
|
@@ -1215,7 +1174,6 @@ function createSvmPaymentFetch(config) {
|
|
|
1215
1174
|
}
|
|
1216
1175
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1217
1176
|
0 && (module.exports = {
|
|
1218
|
-
EVM_NETWORK_CONFIGS,
|
|
1219
1177
|
EvmNetworkSchema,
|
|
1220
1178
|
EvmPaymentPayloadSchema,
|
|
1221
1179
|
SolanaNetworkSchema,
|
|
@@ -1226,7 +1184,6 @@ function createSvmPaymentFetch(config) {
|
|
|
1226
1184
|
createSvmPaymentHeader,
|
|
1227
1185
|
formatAddress,
|
|
1228
1186
|
fromAtomicUnits,
|
|
1229
|
-
getChainId,
|
|
1230
1187
|
getChainIdFromNetwork,
|
|
1231
1188
|
getDefaultSolanaRpcUrl,
|
|
1232
1189
|
getNetworkDisplayName,
|