@swapkit/wallets 3.0.0-beta.9 → 4.0.0-beta.38
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/chunk-0qaxr89s.js +3 -0
- package/dist/chunk-0qaxr89s.js.map +10 -0
- package/dist/chunk-2aa1w78q.js +3 -0
- package/dist/chunk-2aa1w78q.js.map +10 -0
- package/dist/chunk-bexr8da2.js +4 -0
- package/dist/chunk-bexr8da2.js.map +10 -0
- package/dist/chunk-dcj9twam.js +3 -0
- package/dist/chunk-dcj9twam.js.map +10 -0
- package/dist/{chunk-p1kdg37m.js → chunk-qwd1kp32.js} +2 -2
- package/dist/{chunk-p1kdg37m.js.map → chunk-qwd1kp32.js.map} +1 -1
- package/dist/chunk-sn6pgje5.js +3 -0
- package/dist/chunk-sn6pgje5.js.map +10 -0
- package/dist/chunk-th8ggrmx.js +4 -0
- package/dist/{chunk-6ndrbmhg.js.map → chunk-th8ggrmx.js.map} +3 -3
- package/dist/chunk-wfattb4a.js +3 -0
- package/dist/chunk-wfattb4a.js.map +10 -0
- package/dist/chunk-yah6cf33.js +3 -0
- package/dist/{chunk-hxt2nqa8.js.map → chunk-yah6cf33.js.map} +3 -3
- package/dist/src/bitget/index.cjs +2 -2
- package/dist/src/bitget/index.cjs.map +3 -3
- package/dist/src/bitget/index.js +2 -2
- package/dist/src/bitget/index.js.map +3 -3
- package/dist/src/coinbase/index.cjs +2 -2
- package/dist/src/coinbase/index.cjs.map +3 -3
- package/dist/src/coinbase/index.js +2 -2
- package/dist/src/coinbase/index.js.map +3 -3
- package/dist/src/cosmostation/index.cjs +3 -0
- package/dist/src/cosmostation/index.cjs.map +10 -0
- package/dist/src/cosmostation/index.js +3 -0
- package/dist/src/cosmostation/index.js.map +10 -0
- package/dist/src/ctrl/index.cjs +2 -2
- package/dist/src/ctrl/index.cjs.map +4 -4
- package/dist/src/ctrl/index.js +2 -2
- package/dist/src/ctrl/index.js.map +4 -4
- package/dist/src/evm-extensions/index.cjs +2 -2
- package/dist/src/evm-extensions/index.cjs.map +3 -3
- package/dist/src/evm-extensions/index.js +2 -2
- package/dist/src/evm-extensions/index.js.map +3 -3
- package/dist/src/exodus/index.cjs +2 -2
- package/dist/src/exodus/index.cjs.map +3 -3
- package/dist/src/exodus/index.js +2 -2
- package/dist/src/exodus/index.js.map +3 -3
- package/dist/src/index.js +2 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/keepkey/index.cjs +2 -2
- package/dist/src/keepkey/index.cjs.map +9 -9
- package/dist/src/keepkey/index.js +2 -2
- package/dist/src/keepkey/index.js.map +9 -9
- package/dist/src/keepkey-bex/index.cjs +2 -2
- package/dist/src/keepkey-bex/index.cjs.map +4 -4
- package/dist/src/keepkey-bex/index.js +2 -2
- package/dist/src/keepkey-bex/index.js.map +4 -4
- package/dist/src/keplr/index.cjs +2 -2
- package/dist/src/keplr/index.cjs.map +3 -3
- package/dist/src/keplr/index.js +2 -2
- package/dist/src/keplr/index.js.map +3 -3
- package/dist/src/keystore/index.cjs +2 -2
- package/dist/src/keystore/index.cjs.map +4 -4
- package/dist/src/keystore/index.js +2 -2
- package/dist/src/keystore/index.js.map +4 -4
- package/dist/src/ledger/index.cjs +3 -3
- package/dist/src/ledger/index.cjs.map +17 -15
- package/dist/src/ledger/index.js +3 -3
- package/dist/src/ledger/index.js.map +17 -15
- package/dist/src/okx/index.cjs +2 -2
- package/dist/src/okx/index.cjs.map +4 -4
- package/dist/src/okx/index.js +2 -2
- package/dist/src/okx/index.js.map +4 -4
- package/dist/src/onekey/index.cjs +2 -2
- package/dist/src/onekey/index.cjs.map +3 -3
- package/dist/src/onekey/index.js +2 -2
- package/dist/src/onekey/index.js.map +3 -3
- package/dist/src/phantom/index.js +2 -2
- package/dist/src/phantom/index.js.map +2 -2
- package/dist/src/polkadotjs/index.js +2 -2
- package/dist/src/polkadotjs/index.js.map +1 -1
- package/dist/src/radix/index.cjs +2 -2
- package/dist/src/radix/index.cjs.map +3 -3
- package/dist/src/radix/index.js +2 -2
- package/dist/src/radix/index.js.map +3 -3
- package/dist/src/talisman/index.js +2 -2
- package/dist/src/talisman/index.js.map +1 -1
- package/dist/src/trezor/index.cjs +2 -2
- package/dist/src/trezor/index.cjs.map +3 -3
- package/dist/src/trezor/index.js +2 -2
- package/dist/src/trezor/index.js.map +3 -3
- package/dist/src/walletconnect/index.cjs +2 -2
- package/dist/src/walletconnect/index.cjs.map +6 -7
- package/dist/src/walletconnect/index.js +2 -2
- package/dist/src/walletconnect/index.js.map +6 -7
- package/package.json +73 -28
- package/src/bitget/helpers.ts +4 -4
- package/src/coinbase/signer.ts +4 -4
- package/src/cosmostation/index.ts +142 -0
- package/src/ctrl/index.ts +83 -0
- package/src/ctrl/walletHelpers.ts +98 -70
- package/src/evm-extensions/index.ts +4 -3
- package/src/exodus/index.ts +8 -9
- package/src/helpers/near-browser-provider.d.ts +286 -0
- package/src/helpers/near.ts +206 -0
- package/src/keepkey/chains/cosmos.ts +44 -50
- package/src/keepkey/chains/evm.ts +16 -8
- package/src/keepkey/chains/mayachain.ts +3 -2
- package/src/keepkey/chains/thorchain.ts +3 -2
- package/src/keepkey/chains/utxo.ts +14 -3
- package/src/keepkey/coins.ts +10 -4
- package/src/keepkey/index.ts +15 -7
- package/src/keepkey-bex/index.ts +9 -14
- package/src/keepkey-bex/walletHelpers.ts +1 -1
- package/src/keplr/index.ts +4 -3
- package/src/keystore/helpers.ts +2 -4
- package/src/keystore/index.ts +2 -0
- package/src/ledger/clients/cosmos.ts +5 -4
- package/src/ledger/clients/evm.ts +7 -6
- package/src/ledger/clients/near.ts +86 -0
- package/src/ledger/clients/thorchain/helpers.ts +9 -4
- package/src/ledger/clients/thorchain/index.ts +3 -3
- package/src/ledger/clients/thorchain/lib.ts +3 -2
- package/src/ledger/clients/thorchain/utils.ts +20 -9
- package/src/ledger/clients/utxo.ts +3 -5
- package/src/ledger/clients/xrp.ts +66 -0
- package/src/ledger/cosmosTypes.ts +14 -10
- package/src/ledger/helpers/getLedgerAddress.ts +17 -3
- package/src/ledger/helpers/getLedgerClient.ts +63 -45
- package/src/ledger/helpers/getLedgerTransport.ts +5 -3
- package/src/ledger/index.ts +28 -7
- package/src/ledger/interfaces/CosmosLedgerInterface.ts +1 -2
- package/src/okx/helpers.ts +27 -9
- package/src/okx/index.ts +1 -0
- package/src/onekey/index.ts +3 -7
- package/src/radix/index.ts +4 -4
- package/src/trezor/evmSigner.ts +4 -4
- package/src/trezor/index.ts +14 -4
- package/src/types.ts +14 -0
- package/src/utils.ts +4 -0
- package/src/walletconnect/constants.ts +2 -0
- package/src/walletconnect/evmSigner.ts +8 -4
- package/src/walletconnect/helpers.ts +9 -2
- package/src/walletconnect/index.ts +134 -24
- package/dist/chunk-6ndrbmhg.js +0 -4
- package/dist/chunk-bhfpfqc3.js +0 -3
- package/dist/chunk-bhfpfqc3.js.map +0 -10
- package/dist/chunk-hxt2nqa8.js +0 -3
- package/dist/chunk-q81hzyra.js +0 -3
- package/dist/chunk-q81hzyra.js.map +0 -10
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
type FeeOption,
|
|
9
9
|
SwapKitError,
|
|
10
10
|
WalletOption,
|
|
11
|
+
providerRequest,
|
|
11
12
|
} from "@swapkit/helpers";
|
|
12
13
|
import { erc20ABI } from "@swapkit/helpers/contracts";
|
|
13
14
|
import type { ApproveParams, CallParams, EVMTxParams } from "@swapkit/toolboxes/evm";
|
|
@@ -59,12 +60,14 @@ export async function getCtrlProvider<T extends Chain>(
|
|
|
59
60
|
Chain.Polygon,
|
|
60
61
|
() => window.xfi?.ethereum,
|
|
61
62
|
)
|
|
62
|
-
.with(Chain.Cosmos, Chain.Kujira,
|
|
63
|
+
.with(Chain.Cosmos, Chain.Kujira, () => window.xfi?.keplr)
|
|
63
64
|
.with(Chain.Bitcoin, () => window.xfi?.bitcoin)
|
|
64
65
|
.with(Chain.BitcoinCash, () => window.xfi?.bitcoincash)
|
|
65
66
|
.with(Chain.Dogecoin, () => window.xfi?.dogecoin)
|
|
66
67
|
.with(Chain.Litecoin, () => window.xfi?.litecoin)
|
|
67
68
|
.with(Chain.Solana, () => window.xfi?.solana)
|
|
69
|
+
.with(Chain.THORChain, () => window.xfi?.thorchain)
|
|
70
|
+
.with(Chain.Maya, () => window.xfi?.mayachain)
|
|
68
71
|
.otherwise(() => undefined);
|
|
69
72
|
}
|
|
70
73
|
|
|
@@ -89,56 +92,84 @@ async function transaction({
|
|
|
89
92
|
});
|
|
90
93
|
}
|
|
91
94
|
|
|
95
|
+
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: <explanation>
|
|
92
96
|
export async function getCtrlAddress(chain: Chain) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
errorKey: "wallet_provider_not_found",
|
|
97
|
-
info: { wallet: WalletOption.CTRL, chain },
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if ([Chain.Cosmos, Chain.Kujira].includes(chain)) {
|
|
102
|
-
const provider = await getCtrlProvider(Chain.Cosmos);
|
|
103
|
-
if (!provider || "request" in provider) {
|
|
97
|
+
try {
|
|
98
|
+
const eipProvider = (await getCtrlProvider(chain)) as Eip1193Provider;
|
|
99
|
+
if (!eipProvider) {
|
|
104
100
|
throw new SwapKitError({
|
|
105
101
|
errorKey: "wallet_provider_not_found",
|
|
106
102
|
info: { wallet: WalletOption.CTRL, chain },
|
|
107
103
|
});
|
|
108
104
|
}
|
|
109
105
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
106
|
+
if ([Chain.Cosmos, Chain.Kujira].includes(chain)) {
|
|
107
|
+
const provider = await getCtrlProvider(Chain.Cosmos);
|
|
108
|
+
if (!provider || "request" in provider) {
|
|
109
|
+
throw new SwapKitError({
|
|
110
|
+
errorKey: "wallet_provider_not_found",
|
|
111
|
+
info: { wallet: WalletOption.CTRL, chain },
|
|
112
|
+
});
|
|
113
|
+
}
|
|
115
114
|
|
|
116
|
-
|
|
115
|
+
// Enabling before using the Keplr is recommended.
|
|
116
|
+
// This method will ask the user whether to allow access if they haven't visited this website.
|
|
117
|
+
// Also, it will request that the user unlock the wallet if the wallet is locked.
|
|
118
|
+
const chainId = ChainToChainId[chain];
|
|
119
|
+
await provider.enable(chainId);
|
|
117
120
|
|
|
118
|
-
|
|
119
|
-
return item?.address;
|
|
120
|
-
}
|
|
121
|
+
const offlineSigner = provider.getOfflineSigner(chainId);
|
|
121
122
|
|
|
122
|
-
|
|
123
|
-
|
|
123
|
+
const [item] = await offlineSigner.getAccounts();
|
|
124
|
+
return item?.address;
|
|
125
|
+
}
|
|
124
126
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
+
if (EVMChains.includes(chain as EVMChain)) {
|
|
128
|
+
// For CTRL wallet, we need to use the request method directly on the provider
|
|
129
|
+
if ("request" in eipProvider && typeof eipProvider.request === "function") {
|
|
130
|
+
const accounts = await eipProvider.request({ method: "eth_requestAccounts" });
|
|
131
|
+
return accounts[0];
|
|
132
|
+
}
|
|
133
|
+
const { BrowserProvider } = await import("ethers");
|
|
134
|
+
const provider = new BrowserProvider(eipProvider, "any");
|
|
135
|
+
const [response] = await providerRequest({
|
|
136
|
+
provider,
|
|
137
|
+
method: "eth_requestAccounts",
|
|
138
|
+
params: [],
|
|
139
|
+
});
|
|
140
|
+
return response;
|
|
141
|
+
}
|
|
127
142
|
|
|
128
|
-
|
|
129
|
-
|
|
143
|
+
if (chain === Chain.Solana) {
|
|
144
|
+
const provider = await getCtrlProvider(Chain.Solana);
|
|
130
145
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
146
|
+
const accounts = await provider.connect();
|
|
147
|
+
return accounts.publicKey.toString();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (chain === Chain.Near) {
|
|
151
|
+
if (!window.xfi?.near) {
|
|
152
|
+
throw new SwapKitError("wallet_ctrl_not_found", { chain: Chain.Near });
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (!window.xfi.near.isSignedIn?.()) {
|
|
156
|
+
const result = await window.xfi.near.request<string[]>?.({
|
|
157
|
+
method: "connect",
|
|
158
|
+
});
|
|
159
|
+
return result?.[0] || "";
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return window.xfi.near.getAccountId?.() || "";
|
|
163
|
+
}
|
|
134
164
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
165
|
+
const accounts = await eipProvider.request({ method: "request_accounts", params: [] });
|
|
166
|
+
return accounts[0];
|
|
167
|
+
} catch (_error) {
|
|
168
|
+
throw new SwapKitError({
|
|
169
|
+
errorKey: "wallet_provider_not_found",
|
|
170
|
+
info: { wallet: WalletOption.CTRL, chain },
|
|
171
|
+
});
|
|
172
|
+
}
|
|
142
173
|
}
|
|
143
174
|
|
|
144
175
|
export async function walletTransfer(
|
|
@@ -188,8 +219,9 @@ export function getCtrlMethods(provider: BrowserProvider, chain: EVMChain) {
|
|
|
188
219
|
if (!contractAddress) {
|
|
189
220
|
throw new SwapKitError("wallet_ctrl_contract_address_not_provided");
|
|
190
221
|
}
|
|
191
|
-
const { createContract, getCreateContractTxObject, isStateChangingCall
|
|
192
|
-
|
|
222
|
+
const { createContract, getCreateContractTxObject, isStateChangingCall } = await import(
|
|
223
|
+
"@swapkit/toolboxes/evm"
|
|
224
|
+
);
|
|
193
225
|
|
|
194
226
|
const isStateChanging = isStateChangingCall({ abi, funcName });
|
|
195
227
|
|
|
@@ -203,14 +235,14 @@ export function getCtrlMethods(provider: BrowserProvider, chain: EVMChain) {
|
|
|
203
235
|
txOverrides,
|
|
204
236
|
});
|
|
205
237
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
238
|
+
const signer = await provider.getSigner();
|
|
239
|
+
const tx = await signer.sendTransaction({
|
|
240
|
+
value: BigInt(value || 0),
|
|
241
|
+
from,
|
|
242
|
+
to,
|
|
243
|
+
data: data || "0x",
|
|
244
|
+
});
|
|
245
|
+
return tx.hash as T;
|
|
214
246
|
}
|
|
215
247
|
const contract = createContract(contractAddress, abi, provider);
|
|
216
248
|
|
|
@@ -219,9 +251,7 @@ export function getCtrlMethods(provider: BrowserProvider, chain: EVMChain) {
|
|
|
219
251
|
return typeof result?.hash === "string" ? result?.hash : result;
|
|
220
252
|
},
|
|
221
253
|
approve: async ({ assetAddress, spenderAddress, amount, from }: ApproveParams) => {
|
|
222
|
-
const { MAX_APPROVAL, getCreateContractTxObject
|
|
223
|
-
"@swapkit/toolboxes/evm"
|
|
224
|
-
);
|
|
254
|
+
const { MAX_APPROVAL, getCreateContractTxObject } = await import("@swapkit/toolboxes/evm");
|
|
225
255
|
const funcParams = [spenderAddress, BigInt(amount || MAX_APPROVAL)];
|
|
226
256
|
const txOverrides = { from };
|
|
227
257
|
|
|
@@ -236,31 +266,29 @@ export function getCtrlMethods(provider: BrowserProvider, chain: EVMChain) {
|
|
|
236
266
|
const createTx = getCreateContractTxObject({ provider, chain });
|
|
237
267
|
const { value, to, data } = await createTx(functionCallParams);
|
|
238
268
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
269
|
+
const signer = await provider.getSigner();
|
|
270
|
+
const tx = await signer.sendTransaction({
|
|
271
|
+
value: BigInt(value || 0),
|
|
272
|
+
from,
|
|
273
|
+
to,
|
|
274
|
+
data: data || "0x",
|
|
275
|
+
});
|
|
276
|
+
return tx.hash;
|
|
247
277
|
},
|
|
248
|
-
sendTransaction: async (
|
|
249
|
-
const { from, to, data, value } =
|
|
278
|
+
sendTransaction: async (txParams: EVMTxParams) => {
|
|
279
|
+
const { from, to, data, value } = txParams;
|
|
250
280
|
if (!to) {
|
|
251
281
|
throw new SwapKitError("wallet_ctrl_send_transaction_no_address");
|
|
252
282
|
}
|
|
253
283
|
|
|
254
|
-
const
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
} as any,
|
|
263
|
-
]);
|
|
284
|
+
const signer = await provider.getSigner();
|
|
285
|
+
const tx = await signer.sendTransaction({
|
|
286
|
+
value: BigInt(value || 0),
|
|
287
|
+
from,
|
|
288
|
+
to,
|
|
289
|
+
data: data || "0x",
|
|
290
|
+
});
|
|
291
|
+
return tx.hash;
|
|
264
292
|
},
|
|
265
293
|
};
|
|
266
294
|
}
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
ChainToHexChainId,
|
|
4
4
|
type EVMChain,
|
|
5
5
|
EVMChains,
|
|
6
|
+
SwapKitError,
|
|
6
7
|
WalletOption,
|
|
7
8
|
createWallet,
|
|
8
9
|
filterSupportedChains,
|
|
@@ -49,7 +50,7 @@ export const getWeb3WalletMethods = async ({
|
|
|
49
50
|
chain: EVMChain;
|
|
50
51
|
provider: BrowserProvider;
|
|
51
52
|
}) => {
|
|
52
|
-
if (!walletProvider) throw new
|
|
53
|
+
if (!walletProvider) throw new SwapKitError("wallet_evm_extensions_not_found");
|
|
53
54
|
const { getEvmToolbox } = await import("@swapkit/toolboxes/evm");
|
|
54
55
|
|
|
55
56
|
const signer = await provider.getSigner();
|
|
@@ -62,7 +63,7 @@ export const getWeb3WalletMethods = async ({
|
|
|
62
63
|
const networkParams = toolbox.getNetworkParams();
|
|
63
64
|
await switchEVMWalletNetwork(provider, chain, networkParams);
|
|
64
65
|
} catch (_error) {
|
|
65
|
-
throw new
|
|
66
|
+
throw new SwapKitError("wallet_evm_extensions_failed_to_switch_network", { chain });
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
69
|
}
|
|
@@ -89,7 +90,7 @@ export const evmWallet = createWallet({
|
|
|
89
90
|
await Promise.all(
|
|
90
91
|
filteredChains.map(async (chain) => {
|
|
91
92
|
if (walletType === WalletOption.EIP6963) {
|
|
92
|
-
if (!eip1193Provider) throw new
|
|
93
|
+
if (!eip1193Provider) throw new SwapKitError("wallet_evm_extensions_no_provider");
|
|
93
94
|
|
|
94
95
|
const provider = new BrowserProvider(eip1193Provider, "any");
|
|
95
96
|
await provider.send("eth_requestAccounts", []);
|
package/src/exodus/index.ts
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
prepareNetworkSwitch,
|
|
10
10
|
switchEVMWalletNetwork,
|
|
11
11
|
} from "@swapkit/helpers";
|
|
12
|
-
import
|
|
12
|
+
import { Psbt } from "bitcoinjs-lib";
|
|
13
13
|
import type { BrowserProvider, Eip1193Provider } from "ethers";
|
|
14
14
|
import {
|
|
15
15
|
AddressPurpose,
|
|
@@ -34,7 +34,6 @@ async function getWalletMethods({
|
|
|
34
34
|
}) {
|
|
35
35
|
switch (chain) {
|
|
36
36
|
case Chain.Bitcoin: {
|
|
37
|
-
const { Psbt } = await import("bitcoinjs-lib");
|
|
38
37
|
const { getUtxoToolbox } = await import("@swapkit/toolboxes/utxo");
|
|
39
38
|
|
|
40
39
|
let address = "";
|
|
@@ -50,11 +49,11 @@ async function getWalletMethods({
|
|
|
50
49
|
network: { type: BitcoinNetworkType.Mainnet },
|
|
51
50
|
},
|
|
52
51
|
onFinish: (response: GetAddressResponse) => {
|
|
53
|
-
if (!response.addresses[0]) throw new
|
|
52
|
+
if (!response.addresses[0]) throw new SwapKitError("wallet_exodus_no_address");
|
|
54
53
|
address = response.addresses[0].address;
|
|
55
54
|
},
|
|
56
55
|
onCancel: () => {
|
|
57
|
-
throw new
|
|
56
|
+
throw new SwapKitError("wallet_exodus_request_canceled");
|
|
58
57
|
},
|
|
59
58
|
};
|
|
60
59
|
|
|
@@ -80,7 +79,7 @@ async function getWalletMethods({
|
|
|
80
79
|
signedPsbt = Psbt.fromBase64(response.psbtBase64);
|
|
81
80
|
},
|
|
82
81
|
onCancel: () => {
|
|
83
|
-
throw new
|
|
82
|
+
throw new SwapKitError("wallet_exodus_signature_canceled");
|
|
84
83
|
},
|
|
85
84
|
};
|
|
86
85
|
|
|
@@ -104,7 +103,7 @@ async function getWalletMethods({
|
|
|
104
103
|
case Chain.Ethereum:
|
|
105
104
|
case Chain.Optimism:
|
|
106
105
|
case Chain.Polygon: {
|
|
107
|
-
if (!walletProvider) throw new
|
|
106
|
+
if (!walletProvider) throw new SwapKitError("wallet_exodus_not_found");
|
|
108
107
|
const { getProvider, getEvmToolbox } = await import("@swapkit/toolboxes/evm");
|
|
109
108
|
|
|
110
109
|
const jsonRpcProvider = await getProvider(chain);
|
|
@@ -122,13 +121,13 @@ async function getWalletMethods({
|
|
|
122
121
|
await switchEVMWalletNetwork(browserProvider, chain, networkParams);
|
|
123
122
|
}
|
|
124
123
|
} catch (_error) {
|
|
125
|
-
throw new
|
|
124
|
+
throw new SwapKitError("wallet_exodus_failed_to_switch_network", { chain });
|
|
126
125
|
}
|
|
127
126
|
|
|
128
127
|
return { ...prepareNetworkSwitch({ toolbox, chain, provider: browserProvider }), address };
|
|
129
128
|
}
|
|
130
129
|
default:
|
|
131
|
-
throw new
|
|
130
|
+
throw new SwapKitError("wallet_exodus_chain_not_supported", { chain });
|
|
132
131
|
}
|
|
133
132
|
}
|
|
134
133
|
|
|
@@ -138,7 +137,7 @@ export const exodusWallet = createWallet({
|
|
|
138
137
|
supportedChains: [...EVMChains, Chain.Bitcoin],
|
|
139
138
|
connect: ({ addChain, walletType, supportedChains }) =>
|
|
140
139
|
async function connectExodusWallet(chains: Chain[], wallet: Wallet) {
|
|
141
|
-
if (!wallet) throw new
|
|
140
|
+
if (!wallet) throw new SwapKitError("wallet_exodus_instance_missing");
|
|
142
141
|
const filteredChains = filterSupportedChains({ chains, supportedChains, walletType });
|
|
143
142
|
const { BrowserProvider } = await import("ethers");
|
|
144
143
|
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NEAR Browser Wallet Provider Interface Definitions
|
|
3
|
+
*
|
|
4
|
+
* This file contains the standard TypeScript interface definitions for NEAR browser wallet providers
|
|
5
|
+
* that inject themselves into the window object (e.g., OKX, XDEFI/CTRL, etc.)
|
|
6
|
+
*
|
|
7
|
+
* Based on:
|
|
8
|
+
* - NEAR Protocol wallet-selector library
|
|
9
|
+
* - Common patterns from OKX, XDEFI/CTRL, and other NEAR wallet implementations
|
|
10
|
+
* - NEAR API JS types
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type { PublicKey } from "near-api-js/lib/utils";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Transaction action types supported by NEAR
|
|
17
|
+
*/
|
|
18
|
+
export interface NearAction {
|
|
19
|
+
type: "FunctionCall" | "Transfer" | "Stake" | "AddKey" | "DeleteKey" | "DeleteAccount";
|
|
20
|
+
params?: {
|
|
21
|
+
methodName?: string;
|
|
22
|
+
args?: object;
|
|
23
|
+
gas?: string;
|
|
24
|
+
deposit?: string;
|
|
25
|
+
publicKey?: string;
|
|
26
|
+
beneficiaryId?: string;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Transaction structure for NEAR
|
|
32
|
+
*/
|
|
33
|
+
export interface NearTransaction {
|
|
34
|
+
receiverId: string;
|
|
35
|
+
actions: NearAction[];
|
|
36
|
+
// Optional fields
|
|
37
|
+
signerId?: string;
|
|
38
|
+
publicKey?: string;
|
|
39
|
+
nonce?: number;
|
|
40
|
+
recentBlockHash?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Message signing parameters
|
|
45
|
+
*/
|
|
46
|
+
export interface NearSignMessageParams {
|
|
47
|
+
message: string;
|
|
48
|
+
recipient: string;
|
|
49
|
+
nonce: Buffer | Uint8Array;
|
|
50
|
+
callbackUrl?: string;
|
|
51
|
+
state?: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Signed message response
|
|
56
|
+
*/
|
|
57
|
+
export interface NearSignedMessage {
|
|
58
|
+
accountId: string;
|
|
59
|
+
publicKey: string;
|
|
60
|
+
signature: string;
|
|
61
|
+
// Optional callback data
|
|
62
|
+
callbackUrl?: string;
|
|
63
|
+
state?: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Sign-in request parameters
|
|
68
|
+
*/
|
|
69
|
+
export interface NearSignInParams {
|
|
70
|
+
contractId?: string;
|
|
71
|
+
methodNames?: string[];
|
|
72
|
+
// Success and failure URLs for browser wallets
|
|
73
|
+
successUrl?: string;
|
|
74
|
+
failureUrl?: string;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Account information
|
|
79
|
+
*/
|
|
80
|
+
export interface NearAccount {
|
|
81
|
+
accountId: string;
|
|
82
|
+
publicKey?: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Access key information
|
|
87
|
+
*/
|
|
88
|
+
export interface NearAccessKey {
|
|
89
|
+
publicKey: PublicKey;
|
|
90
|
+
accessKey: {
|
|
91
|
+
nonce: number;
|
|
92
|
+
permission:
|
|
93
|
+
| "FullAccess"
|
|
94
|
+
| {
|
|
95
|
+
FunctionCall: {
|
|
96
|
+
allowance?: string;
|
|
97
|
+
receiverId: string;
|
|
98
|
+
methodNames: string[];
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Transaction execution result
|
|
106
|
+
*/
|
|
107
|
+
export interface NearFinalExecutionOutcome {
|
|
108
|
+
status: object;
|
|
109
|
+
transaction: object;
|
|
110
|
+
transaction_outcome: object;
|
|
111
|
+
receipts_outcome: object[];
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Standard NEAR browser wallet provider interface
|
|
116
|
+
*
|
|
117
|
+
* This interface represents the common API surface that NEAR browser wallets
|
|
118
|
+
* expose when they inject themselves into the window object.
|
|
119
|
+
*/
|
|
120
|
+
export interface NearBrowserWalletProvider {
|
|
121
|
+
// Connection Management
|
|
122
|
+
/**
|
|
123
|
+
* Request connection to the wallet
|
|
124
|
+
* Returns array of account IDs that were connected
|
|
125
|
+
*/
|
|
126
|
+
connect(): Promise<string[]>;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Alternative connection method used by some wallets
|
|
130
|
+
*/
|
|
131
|
+
request?(params: { method: "connect"; params?: any }): Promise<string[]>;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Disconnect from the wallet
|
|
135
|
+
*/
|
|
136
|
+
disconnect(): Promise<void>;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Sign out from the wallet (some wallets use this instead of disconnect)
|
|
140
|
+
*/
|
|
141
|
+
signOut?(): void;
|
|
142
|
+
|
|
143
|
+
// Account Management
|
|
144
|
+
/**
|
|
145
|
+
* Check if user is signed in
|
|
146
|
+
*/
|
|
147
|
+
isSignedIn?(): boolean;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Get the current account ID
|
|
151
|
+
*/
|
|
152
|
+
getAccountId(): string | Promise<string>;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Get list of accounts (some wallets support multiple accounts)
|
|
156
|
+
*/
|
|
157
|
+
getAccounts?(): Promise<NearAccount[]>;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Get the public key for the current account
|
|
161
|
+
*/
|
|
162
|
+
getPublicKey?(): Promise<string>;
|
|
163
|
+
|
|
164
|
+
// Legacy sign-in methods (used by some wallets)
|
|
165
|
+
/**
|
|
166
|
+
* Request sign in (legacy method)
|
|
167
|
+
*/
|
|
168
|
+
requestSignIn?(params: NearSignInParams): Promise<NearAccount>;
|
|
169
|
+
|
|
170
|
+
// Signing Operations
|
|
171
|
+
/**
|
|
172
|
+
* Sign a message
|
|
173
|
+
*/
|
|
174
|
+
signMessage(params: NearSignMessageParams): Promise<NearSignedMessage>;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Sign and send a single transaction
|
|
178
|
+
*/
|
|
179
|
+
signAndSendTransaction(params: {
|
|
180
|
+
receiverId: string;
|
|
181
|
+
actions: NearAction[];
|
|
182
|
+
// Optional parameters
|
|
183
|
+
signerId?: string;
|
|
184
|
+
publicKey?: string;
|
|
185
|
+
nonce?: number;
|
|
186
|
+
recentBlockHash?: string;
|
|
187
|
+
}): Promise<NearFinalExecutionOutcome>;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Sign and send multiple transactions
|
|
191
|
+
*/
|
|
192
|
+
signAndSendTransactions(params: {
|
|
193
|
+
transactions: NearTransaction[];
|
|
194
|
+
}): Promise<NearFinalExecutionOutcome[]>;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Request signing of transactions (alternative method used by some wallets)
|
|
198
|
+
*/
|
|
199
|
+
requestSignTransactions?(params: {
|
|
200
|
+
transactions: NearTransaction[];
|
|
201
|
+
}): Promise<any>;
|
|
202
|
+
|
|
203
|
+
// Verification
|
|
204
|
+
/**
|
|
205
|
+
* Verify ownership of an account
|
|
206
|
+
*/
|
|
207
|
+
verifyOwner?(params: {
|
|
208
|
+
message: string;
|
|
209
|
+
// Additional parameters may vary by wallet
|
|
210
|
+
}): Promise<{
|
|
211
|
+
accountId: string;
|
|
212
|
+
publicKey: string;
|
|
213
|
+
signature: string;
|
|
214
|
+
// Additional fields may be returned
|
|
215
|
+
}>;
|
|
216
|
+
|
|
217
|
+
// Network Information
|
|
218
|
+
/**
|
|
219
|
+
* Get the current network (mainnet, testnet, etc.)
|
|
220
|
+
*/
|
|
221
|
+
getNetwork?(): string | Promise<string>;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Check if wallet is connected to mainnet
|
|
225
|
+
*/
|
|
226
|
+
isMainnet?(): boolean;
|
|
227
|
+
|
|
228
|
+
// Wallet Metadata
|
|
229
|
+
/**
|
|
230
|
+
* Wallet name or identifier
|
|
231
|
+
*/
|
|
232
|
+
name?: string;
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Wallet version
|
|
236
|
+
*/
|
|
237
|
+
version?: string;
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Check if this is a specific wallet (used for wallet detection)
|
|
241
|
+
*/
|
|
242
|
+
isOKX?: boolean;
|
|
243
|
+
isXDEFI?: boolean;
|
|
244
|
+
isCTRL?: boolean;
|
|
245
|
+
|
|
246
|
+
// Event Handling (not all wallets support events)
|
|
247
|
+
on?(event: "accountsChanged" | "networkChanged" | "disconnect", handler: Function): void;
|
|
248
|
+
off?(event: string, handler: Function): void;
|
|
249
|
+
removeListener?(event: string, handler: Function): void;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Extended window interface for NEAR wallets
|
|
254
|
+
*/
|
|
255
|
+
declare global {
|
|
256
|
+
interface Window {
|
|
257
|
+
// Generic NEAR provider (if wallet uses this pattern)
|
|
258
|
+
near?: NearBrowserWalletProvider;
|
|
259
|
+
|
|
260
|
+
// Specific wallet providers
|
|
261
|
+
okxwallet?: {
|
|
262
|
+
near: NearBrowserWalletProvider;
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
xfi?: {
|
|
266
|
+
near: NearBrowserWalletProvider;
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
// Add other wallet-specific providers as needed
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Helper type for wallet detection
|
|
275
|
+
*/
|
|
276
|
+
export type NearWalletType = "okx" | "xdefi" | "ctrl" | "generic";
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Configuration for NEAR network
|
|
280
|
+
*/
|
|
281
|
+
export interface NearNetworkConfig {
|
|
282
|
+
networkId: "mainnet" | "testnet" | "betanet";
|
|
283
|
+
nodeUrl: string;
|
|
284
|
+
walletUrl?: string;
|
|
285
|
+
helperUrl?: string;
|
|
286
|
+
}
|