@relai-fi/x402 0.5.18 → 0.5.20
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/client.cjs +224 -36
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js +224 -36
- package/dist/client.js.map +1 -1
- package/dist/index.cjs +112 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +112 -41
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +228 -38
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +228 -38
- package/dist/react/index.js.map +1 -1
- package/dist/server.cjs +14 -2
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +14 -2
- package/dist/server.js.map +1 -1
- package/dist/{types-CWtUxi3l.d.cts → types-BSCuAZJb.d.cts} +2 -1
- package/dist/{types-CWtUxi3l.d.ts → types-BSCuAZJb.d.ts} +2 -1
- package/dist/utils/index.cjs +5 -3
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.js +5 -3
- package/dist/utils/index.js.map +1 -1
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -23,7 +23,8 @@ var NETWORK_CAIP2 = {
|
|
|
23
23
|
"skale-base-sepolia": "eip155:324705682",
|
|
24
24
|
"skale-bite": "eip155:103698795",
|
|
25
25
|
"polygon": "eip155:137",
|
|
26
|
-
"ethereum": "eip155:1"
|
|
26
|
+
"ethereum": "eip155:1",
|
|
27
|
+
"telos": "eip155:40"
|
|
27
28
|
};
|
|
28
29
|
var CAIP2_TO_NETWORK = Object.fromEntries(
|
|
29
30
|
Object.entries(NETWORK_CAIP2).map(([k, v]) => [v, k])
|
|
@@ -35,7 +36,139 @@ var CHAIN_IDS = {
|
|
|
35
36
|
"skale-base-sepolia": 324705682,
|
|
36
37
|
"skale-bite": 103698795,
|
|
37
38
|
"polygon": 137,
|
|
38
|
-
"ethereum": 1
|
|
39
|
+
"ethereum": 1,
|
|
40
|
+
"telos": 40
|
|
41
|
+
};
|
|
42
|
+
var NETWORK_TOKENS = {
|
|
43
|
+
"solana": [
|
|
44
|
+
{
|
|
45
|
+
address: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
|
46
|
+
symbol: "USDC",
|
|
47
|
+
name: "USD Coin",
|
|
48
|
+
decimals: 6
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
"base": [
|
|
52
|
+
{ address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", symbol: "USDC", name: "USD Coin", decimals: 6, domainVersion: "2", isStableUsd: true }
|
|
53
|
+
],
|
|
54
|
+
"avalanche": [
|
|
55
|
+
{
|
|
56
|
+
address: "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E",
|
|
57
|
+
symbol: "USDC",
|
|
58
|
+
name: "USD Coin",
|
|
59
|
+
decimals: 6,
|
|
60
|
+
domainVersion: "2",
|
|
61
|
+
isStableUsd: true
|
|
62
|
+
}
|
|
63
|
+
],
|
|
64
|
+
"telos": [
|
|
65
|
+
{
|
|
66
|
+
address: "0x818ec0a7fe18ff94269904fced6ae3dae6d6dc0b",
|
|
67
|
+
symbol: "USDC",
|
|
68
|
+
name: "USD Coin",
|
|
69
|
+
decimals: 6,
|
|
70
|
+
isStableUsd: true,
|
|
71
|
+
standards: ["eip2612"]
|
|
72
|
+
}
|
|
73
|
+
],
|
|
74
|
+
"skale-base": [
|
|
75
|
+
{
|
|
76
|
+
address: "0x85889c8c714505E0c94b30fcfcF64fE3Ac8FCb20",
|
|
77
|
+
symbol: "USDC",
|
|
78
|
+
name: "Bridged USDC (SKALE Bridge)",
|
|
79
|
+
decimals: 6,
|
|
80
|
+
domainVersion: "2",
|
|
81
|
+
isStableUsd: true
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
address: "0x2bF5bF154b515EaA82C31a65ec11554fF5aF7fCA",
|
|
85
|
+
symbol: "USDT",
|
|
86
|
+
name: "Bridged USDT (SKALE Bridge)",
|
|
87
|
+
decimals: 6,
|
|
88
|
+
domainVersion: "1",
|
|
89
|
+
isStableUsd: true
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
address: "0x1aeeCFE5454c83B42D8A316246CAc9739E7f690e",
|
|
93
|
+
symbol: "WBTC",
|
|
94
|
+
name: "Wrapped Bitcoin",
|
|
95
|
+
decimals: 8,
|
|
96
|
+
domainVersion: "1",
|
|
97
|
+
isStableUsd: false
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
address: "0x7bD39ABBd0Dd13103542cAe3276C7fA332bCA486",
|
|
101
|
+
symbol: "WETH",
|
|
102
|
+
name: "Wrapped Ether",
|
|
103
|
+
decimals: 18,
|
|
104
|
+
domainVersion: "1",
|
|
105
|
+
isStableUsd: false
|
|
106
|
+
}
|
|
107
|
+
],
|
|
108
|
+
"skale-base-sepolia": [
|
|
109
|
+
{
|
|
110
|
+
address: "0x2e08028E3C4c2356572E096d8EF835cD5C6030bD",
|
|
111
|
+
symbol: "USDC",
|
|
112
|
+
name: "Bridged USDC (SKALE Bridge)",
|
|
113
|
+
decimals: 6,
|
|
114
|
+
domainVersion: "2",
|
|
115
|
+
isStableUsd: true
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
address: "0x3ca0a49f511c2c89c4dcbbf1731120d8919050bf",
|
|
119
|
+
symbol: "USDT",
|
|
120
|
+
name: "Bridged USDT (SKALE Bridge)",
|
|
121
|
+
decimals: 6,
|
|
122
|
+
domainVersion: "1",
|
|
123
|
+
isStableUsd: true
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
address: "0x4512eacd4186b025186e1cf6cc0d89497c530e87",
|
|
127
|
+
symbol: "WBTC",
|
|
128
|
+
name: "Wrapped Bitcoin",
|
|
129
|
+
decimals: 8,
|
|
130
|
+
domainVersion: "1",
|
|
131
|
+
isStableUsd: false
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
address: "0xf94056bd7f6965db3757e1b145f200b7346b4fc0",
|
|
135
|
+
symbol: "WETH",
|
|
136
|
+
name: "Wrapped Ether",
|
|
137
|
+
decimals: 18,
|
|
138
|
+
domainVersion: "1",
|
|
139
|
+
isStableUsd: false
|
|
140
|
+
}
|
|
141
|
+
],
|
|
142
|
+
"skale-bite": [
|
|
143
|
+
{
|
|
144
|
+
address: "0xc4083B1E81ceb461Ccef3FDa8A9F24F0d764B6D8",
|
|
145
|
+
symbol: "USDC",
|
|
146
|
+
name: "USDC",
|
|
147
|
+
decimals: 6,
|
|
148
|
+
domainVersion: "1",
|
|
149
|
+
isStableUsd: true
|
|
150
|
+
}
|
|
151
|
+
],
|
|
152
|
+
"polygon": [
|
|
153
|
+
{
|
|
154
|
+
address: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
|
|
155
|
+
symbol: "USDC",
|
|
156
|
+
name: "USD Coin",
|
|
157
|
+
decimals: 6,
|
|
158
|
+
domainVersion: "2",
|
|
159
|
+
isStableUsd: true
|
|
160
|
+
}
|
|
161
|
+
],
|
|
162
|
+
"ethereum": [
|
|
163
|
+
{
|
|
164
|
+
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
165
|
+
symbol: "USDC",
|
|
166
|
+
name: "USD Coin",
|
|
167
|
+
decimals: 6,
|
|
168
|
+
domainVersion: "2",
|
|
169
|
+
isStableUsd: true
|
|
170
|
+
}
|
|
171
|
+
]
|
|
39
172
|
};
|
|
40
173
|
var USDC_ADDRESSES = {
|
|
41
174
|
"solana": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
|
@@ -45,7 +178,8 @@ var USDC_ADDRESSES = {
|
|
|
45
178
|
"skale-base-sepolia": "0x2e08028E3C4c2356572E096d8EF835cD5C6030bD",
|
|
46
179
|
"skale-bite": "0xc4083B1E81ceb461Ccef3FDa8A9F24F0d764B6D8",
|
|
47
180
|
"polygon": "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
|
|
48
|
-
"ethereum": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
|
|
181
|
+
"ethereum": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
182
|
+
"telos": "0x818ec0a7fe18ff94269904fced6ae3dae6d6dc0b"
|
|
49
183
|
};
|
|
50
184
|
var SOLANA_MAINNET_NETWORK = NETWORK_CAIP2["solana"];
|
|
51
185
|
var BASE_MAINNET_NETWORK = NETWORK_CAIP2["base"];
|
|
@@ -59,13 +193,14 @@ var RELAI_NETWORKS = [
|
|
|
59
193
|
"skale-base-sepolia",
|
|
60
194
|
"skale-bite",
|
|
61
195
|
"polygon",
|
|
62
|
-
"ethereum"
|
|
196
|
+
"ethereum",
|
|
197
|
+
"telos"
|
|
63
198
|
];
|
|
64
199
|
function isSolana(network) {
|
|
65
200
|
return network === "solana" || network.startsWith("solana:");
|
|
66
201
|
}
|
|
67
202
|
function isEvm(network) {
|
|
68
|
-
return ["base", "avalanche", "skale-base", "skale-base-sepolia", "skale-bite", "polygon", "ethereum"].includes(network) || network.startsWith("eip155:");
|
|
203
|
+
return ["base", "avalanche", "skale-base", "skale-base-sepolia", "skale-bite", "polygon", "ethereum", "telos"].includes(network) || network.startsWith("eip155:");
|
|
69
204
|
}
|
|
70
205
|
function normalizeNetwork(network) {
|
|
71
206
|
if (RELAI_NETWORKS.includes(network)) return network;
|
|
@@ -89,7 +224,8 @@ var DEFAULT_EVM_RPC_URLS = {
|
|
|
89
224
|
"base": "https://mainnet.base.org",
|
|
90
225
|
"avalanche": "https://api.avax.network/ext/bc/C/rpc",
|
|
91
226
|
"polygon": "https://polygon-rpc.com",
|
|
92
|
-
"ethereum": "https://ethereum-rpc.publicnode.com"
|
|
227
|
+
"ethereum": "https://ethereum-rpc.publicnode.com",
|
|
228
|
+
"telos": "https://rpc.telos.net"
|
|
93
229
|
};
|
|
94
230
|
function createX402Client(config) {
|
|
95
231
|
const {
|
|
@@ -698,41 +834,93 @@ function createX402Client(config) {
|
|
|
698
834
|
chainId,
|
|
699
835
|
verifyingContract: useRelayer ? extra.relayerContract : accept.asset
|
|
700
836
|
};
|
|
701
|
-
const
|
|
702
|
-
const
|
|
703
|
-
const
|
|
704
|
-
const
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
837
|
+
const tokenNetworkKey = network || rawNetwork;
|
|
838
|
+
const networkTokens = NETWORK_TOKENS[tokenNetworkKey];
|
|
839
|
+
const assetLower = (accept.asset || "").toLowerCase();
|
|
840
|
+
const tokenInfo = networkTokens?.find((t) => t.address.toLowerCase() === assetLower) || networkTokens?.[0];
|
|
841
|
+
const tokenStandards = Array.isArray(tokenInfo?.standards) ? tokenInfo.standards : [];
|
|
842
|
+
const hasEip3009 = tokenStandards.some((s) => s.toLowerCase() === "eip3009");
|
|
843
|
+
const hasEip2612 = tokenStandards.some((s) => s.toLowerCase() === "eip2612");
|
|
844
|
+
const usePermit2612 = !hasEip3009 && hasEip2612;
|
|
845
|
+
let message;
|
|
846
|
+
let signature;
|
|
847
|
+
let authorizationScheme;
|
|
848
|
+
if (usePermit2612) {
|
|
849
|
+
const spender = extra.feePayer || accept.payTo;
|
|
850
|
+
const deadline = Math.floor(Date.now() / 1e3) + 3600;
|
|
851
|
+
let nonce = 0;
|
|
852
|
+
if (rpcUrl) {
|
|
853
|
+
try {
|
|
854
|
+
const paddedAddress = evmWallet.address.toLowerCase().replace("0x", "").padStart(64, "0");
|
|
855
|
+
const nonceHex = await evmRpcCall(rpcUrl, accept.asset, "0x7ecebe00" + paddedAddress);
|
|
856
|
+
nonce = nonceHex ? parseInt(nonceHex, 16) : 0;
|
|
857
|
+
} catch {
|
|
858
|
+
nonce = 0;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
const permitTypes = {
|
|
862
|
+
Permit: [
|
|
863
|
+
{ name: "owner", type: "address" },
|
|
864
|
+
{ name: "spender", type: "address" },
|
|
865
|
+
{ name: "value", type: "uint256" },
|
|
866
|
+
{ name: "nonce", type: "uint256" },
|
|
867
|
+
{ name: "deadline", type: "uint256" }
|
|
868
|
+
]
|
|
869
|
+
};
|
|
870
|
+
message = {
|
|
871
|
+
owner: evmWallet.address,
|
|
872
|
+
spender,
|
|
873
|
+
value: paymentAmount,
|
|
874
|
+
nonce: String(nonce),
|
|
875
|
+
deadline: String(deadline)
|
|
876
|
+
};
|
|
877
|
+
log("Signing EIP-2612 permit on chain", chainId);
|
|
878
|
+
signature = await evmWallet.signTypedData({
|
|
879
|
+
domain,
|
|
880
|
+
types: permitTypes,
|
|
881
|
+
message,
|
|
882
|
+
primaryType: "Permit"
|
|
883
|
+
});
|
|
884
|
+
authorizationScheme = "eip2612";
|
|
885
|
+
} else {
|
|
886
|
+
const validAfter = 0;
|
|
887
|
+
const validBefore = Math.floor(Date.now() / 1e3) + 3600;
|
|
888
|
+
const nonce = "0x" + [...crypto.getRandomValues(new Uint8Array(32))].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
889
|
+
const transferTypes = {
|
|
890
|
+
TransferWithAuthorization: [
|
|
891
|
+
{ name: "from", type: "address" },
|
|
892
|
+
{ name: "to", type: "address" },
|
|
893
|
+
{ name: "value", type: "uint256" },
|
|
894
|
+
{ name: "validAfter", type: "uint256" },
|
|
895
|
+
{ name: "validBefore", type: "uint256" },
|
|
896
|
+
{ name: "nonce", type: "bytes32" }
|
|
897
|
+
]
|
|
898
|
+
};
|
|
899
|
+
message = {
|
|
900
|
+
from: evmWallet.address,
|
|
901
|
+
to: accept.payTo,
|
|
902
|
+
value: paymentAmount,
|
|
903
|
+
validAfter: String(validAfter),
|
|
904
|
+
validBefore: String(validBefore),
|
|
905
|
+
nonce
|
|
906
|
+
};
|
|
907
|
+
log("Signing EIP-3009 transferWithAuthorization on chain", chainId);
|
|
908
|
+
signature = await evmWallet.signTypedData({
|
|
909
|
+
domain,
|
|
910
|
+
types: transferTypes,
|
|
911
|
+
message,
|
|
912
|
+
primaryType: "TransferWithAuthorization"
|
|
913
|
+
});
|
|
914
|
+
authorizationScheme = "eip3009";
|
|
915
|
+
}
|
|
729
916
|
const paymentPayload = {
|
|
730
917
|
x402Version: 2,
|
|
731
918
|
resource: requirements.resource || { url },
|
|
732
919
|
accepted: accept,
|
|
733
920
|
payload: {
|
|
734
921
|
authorization: message,
|
|
735
|
-
signature
|
|
922
|
+
signature,
|
|
923
|
+
authorizationScheme
|
|
736
924
|
},
|
|
737
925
|
facilitatorUrl
|
|
738
926
|
};
|
|
@@ -761,7 +949,7 @@ function createX402Client(config) {
|
|
|
761
949
|
const sourceAta = await getAssociatedTokenAddress(
|
|
762
950
|
mintPubkey,
|
|
763
951
|
userPubkey,
|
|
764
|
-
|
|
952
|
+
true,
|
|
765
953
|
programId
|
|
766
954
|
);
|
|
767
955
|
const destinationAta = await getAssociatedTokenAddress(
|