@swapkit/wallets 3.0.0-beta.2 → 3.0.0-beta.21

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 (126) hide show
  1. package/dist/chunk-2aa1w78q.js +3 -0
  2. package/dist/chunk-2aa1w78q.js.map +10 -0
  3. package/dist/{chunk-p1kdg37m.js → chunk-38ztynv0.js} +1 -1
  4. package/dist/{chunk-p1kdg37m.js.map → chunk-38ztynv0.js.map} +1 -1
  5. package/dist/chunk-ebfkk1jn.js +4 -0
  6. package/dist/{chunk-czhtd6cy.js.map → chunk-ebfkk1jn.js.map} +3 -3
  7. package/dist/chunk-k9q04afa.js +3 -0
  8. package/dist/{chunk-qadd75nn.js.map → chunk-k9q04afa.js.map} +3 -3
  9. package/dist/chunk-x5hgx9x9.js +3 -0
  10. package/dist/chunk-x5hgx9x9.js.map +10 -0
  11. package/dist/src/bitget/index.cjs +2 -2
  12. package/dist/src/bitget/index.cjs.map +3 -3
  13. package/dist/src/bitget/index.js +2 -2
  14. package/dist/src/bitget/index.js.map +3 -3
  15. package/dist/src/coinbase/index.cjs +2 -2
  16. package/dist/src/coinbase/index.cjs.map +3 -3
  17. package/dist/src/coinbase/index.js +2 -2
  18. package/dist/src/coinbase/index.js.map +3 -3
  19. package/dist/src/cosmostation/index.cjs +3 -0
  20. package/dist/src/cosmostation/index.cjs.map +10 -0
  21. package/dist/src/cosmostation/index.js +3 -0
  22. package/dist/src/cosmostation/index.js.map +10 -0
  23. package/dist/src/ctrl/index.cjs +2 -2
  24. package/dist/src/ctrl/index.cjs.map +3 -3
  25. package/dist/src/ctrl/index.js +2 -2
  26. package/dist/src/ctrl/index.js.map +3 -3
  27. package/dist/src/evm-extensions/index.cjs +2 -2
  28. package/dist/src/evm-extensions/index.cjs.map +3 -3
  29. package/dist/src/evm-extensions/index.js +2 -2
  30. package/dist/src/evm-extensions/index.js.map +3 -3
  31. package/dist/src/exodus/index.cjs +2 -2
  32. package/dist/src/exodus/index.cjs.map +3 -3
  33. package/dist/src/exodus/index.js +2 -2
  34. package/dist/src/exodus/index.js.map +3 -3
  35. package/dist/src/index.js +1 -1
  36. package/dist/src/keepkey/index.cjs +2 -2
  37. package/dist/src/keepkey/index.cjs.map +9 -9
  38. package/dist/src/keepkey/index.js +2 -2
  39. package/dist/src/keepkey/index.js.map +9 -9
  40. package/dist/src/keepkey-bex/index.cjs +2 -2
  41. package/dist/src/keepkey-bex/index.cjs.map +4 -4
  42. package/dist/src/keepkey-bex/index.js +2 -2
  43. package/dist/src/keepkey-bex/index.js.map +4 -4
  44. package/dist/src/keplr/index.cjs +2 -2
  45. package/dist/src/keplr/index.cjs.map +3 -3
  46. package/dist/src/keplr/index.js +2 -2
  47. package/dist/src/keplr/index.js.map +3 -3
  48. package/dist/src/keystore/index.cjs +2 -2
  49. package/dist/src/keystore/index.cjs.map +4 -4
  50. package/dist/src/keystore/index.js +2 -2
  51. package/dist/src/keystore/index.js.map +4 -4
  52. package/dist/src/ledger/index.cjs +3 -3
  53. package/dist/src/ledger/index.cjs.map +16 -15
  54. package/dist/src/ledger/index.js +3 -3
  55. package/dist/src/ledger/index.js.map +16 -15
  56. package/dist/src/okx/index.cjs +2 -2
  57. package/dist/src/okx/index.cjs.map +3 -3
  58. package/dist/src/okx/index.js +2 -2
  59. package/dist/src/okx/index.js.map +3 -3
  60. package/dist/src/onekey/index.cjs +2 -2
  61. package/dist/src/onekey/index.cjs.map +3 -3
  62. package/dist/src/onekey/index.js +2 -2
  63. package/dist/src/onekey/index.js.map +3 -3
  64. package/dist/src/phantom/index.js +1 -1
  65. package/dist/src/polkadotjs/index.js +1 -1
  66. package/dist/src/radix/index.cjs +2 -2
  67. package/dist/src/radix/index.cjs.map +3 -3
  68. package/dist/src/radix/index.js +2 -2
  69. package/dist/src/radix/index.js.map +3 -3
  70. package/dist/src/talisman/index.js +1 -1
  71. package/dist/src/trezor/index.cjs +2 -2
  72. package/dist/src/trezor/index.cjs.map +3 -3
  73. package/dist/src/trezor/index.js +2 -2
  74. package/dist/src/trezor/index.js.map +3 -3
  75. package/dist/src/walletconnect/index.cjs +2 -2
  76. package/dist/src/walletconnect/index.cjs.map +4 -4
  77. package/dist/src/walletconnect/index.js +2 -2
  78. package/dist/src/walletconnect/index.js.map +4 -4
  79. package/package.json +32 -27
  80. package/src/bitget/helpers.ts +4 -4
  81. package/src/coinbase/signer.ts +4 -4
  82. package/src/cosmostation/index.ts +142 -0
  83. package/src/ctrl/walletHelpers.ts +82 -70
  84. package/src/evm-extensions/index.ts +4 -3
  85. package/src/exodus/index.ts +8 -9
  86. package/src/keepkey/chains/cosmos.ts +44 -50
  87. package/src/keepkey/chains/evm.ts +16 -8
  88. package/src/keepkey/chains/mayachain.ts +3 -2
  89. package/src/keepkey/chains/thorchain.ts +3 -2
  90. package/src/keepkey/chains/utxo.ts +9 -2
  91. package/src/keepkey/coins.ts +10 -4
  92. package/src/keepkey/index.ts +15 -7
  93. package/src/keepkey-bex/index.ts +9 -14
  94. package/src/keepkey-bex/walletHelpers.ts +1 -1
  95. package/src/keplr/index.ts +4 -3
  96. package/src/keystore/helpers.ts +2 -4
  97. package/src/keystore/index.ts +1 -0
  98. package/src/ledger/clients/cosmos.ts +5 -4
  99. package/src/ledger/clients/evm.ts +7 -6
  100. package/src/ledger/clients/thorchain/helpers.ts +9 -4
  101. package/src/ledger/clients/thorchain/index.ts +3 -3
  102. package/src/ledger/clients/thorchain/lib.ts +3 -2
  103. package/src/ledger/clients/thorchain/utils.ts +20 -9
  104. package/src/ledger/clients/utxo.ts +3 -5
  105. package/src/ledger/clients/xrp.ts +66 -0
  106. package/src/ledger/cosmosTypes.ts +14 -10
  107. package/src/ledger/helpers/getLedgerAddress.ts +12 -3
  108. package/src/ledger/helpers/getLedgerClient.ts +56 -45
  109. package/src/ledger/helpers/getLedgerTransport.ts +5 -3
  110. package/src/ledger/index.ts +18 -7
  111. package/src/ledger/interfaces/CosmosLedgerInterface.ts +1 -2
  112. package/src/okx/helpers.ts +11 -9
  113. package/src/onekey/index.ts +3 -7
  114. package/src/radix/index.ts +4 -4
  115. package/src/trezor/evmSigner.ts +4 -4
  116. package/src/trezor/index.ts +14 -4
  117. package/src/types.ts +3 -0
  118. package/src/utils.ts +4 -0
  119. package/src/walletconnect/evmSigner.ts +6 -2
  120. package/src/walletconnect/index.ts +4 -4
  121. package/dist/chunk-bhfpfqc3.js +0 -3
  122. package/dist/chunk-bhfpfqc3.js.map +0 -10
  123. package/dist/chunk-czhtd6cy.js +0 -4
  124. package/dist/chunk-q81hzyra.js +0 -3
  125. package/dist/chunk-q81hzyra.js.map +0 -10
  126. package/dist/chunk-qadd75nn.js +0 -3
@@ -1,6 +1,6 @@
1
1
  import type { CoinbaseWalletProvider } from "@coinbase/wallet-sdk";
2
2
  import type { createCoinbaseWalletSDK } from "@coinbase/wallet-sdk/dist/createCoinbaseWalletSDK.js";
3
- import { Chain } from "@swapkit/helpers";
3
+ import { Chain, SwapKitError } from "@swapkit/helpers";
4
4
  import type { Provider } from "ethers";
5
5
 
6
6
  async function getCoinbaseMobileSigner(
@@ -22,7 +22,7 @@ async function getCoinbaseMobileSigner(
22
22
  method: "eth_requestAccounts",
23
23
  });
24
24
 
25
- if (!accounts[0]) throw new Error("No Account found");
25
+ if (!accounts[0]) throw new SwapKitError("wallet_coinbase_no_accounts");
26
26
 
27
27
  return accounts[0];
28
28
  }
@@ -41,7 +41,7 @@ async function getCoinbaseMobileSigner(
41
41
  }
42
42
 
43
43
  signTypedData = () => {
44
- throw new Error("this method is not implemented");
44
+ throw new SwapKitError("wallet_coinbase_method_not_supported", { method: "signTypedData" });
45
45
  };
46
46
 
47
47
  connect(provider: Provider) {
@@ -78,6 +78,6 @@ export const getWalletMethods = async ({
78
78
  }
79
79
 
80
80
  default:
81
- throw new Error(`No wallet for chain ${chain}`);
81
+ throw new SwapKitError("wallet_coinbase_chain_not_supported", { chain });
82
82
  }
83
83
  };
@@ -0,0 +1,142 @@
1
+ import type { Keplr } from "@keplr-wallet/types";
2
+ import {
3
+ Chain,
4
+ ChainId,
5
+ ChainToChainId,
6
+ SwapKitError,
7
+ WalletOption,
8
+ createWallet,
9
+ filterSupportedChains,
10
+ } from "@swapkit/helpers";
11
+
12
+ const cosmostationSupportedChainIds = [ChainId.Cosmos, ChainId.Kujira, ChainId.THORChain] as const;
13
+ const cosmostationSupportedEVMChains = [
14
+ Chain.Ethereum,
15
+ Chain.BinanceSmartChain,
16
+ Chain.Avalanche,
17
+ Chain.Polygon,
18
+ Chain.Arbitrum,
19
+ Chain.Optimism,
20
+ Chain.Base,
21
+ ] as const;
22
+
23
+ declare global {
24
+ interface Window {
25
+ cosmostation?: {
26
+ providers?: {
27
+ keplr?: Keplr;
28
+ };
29
+ };
30
+ }
31
+ }
32
+
33
+ async function connectCosmosChains(chains: Chain[], addChain: any, keplrProvider: Keplr) {
34
+ await Promise.all(
35
+ chains.map(async (chain) => {
36
+ const chainId = ChainToChainId[chain] as (typeof cosmostationSupportedChainIds)[number];
37
+
38
+ await keplrProvider.enable(chainId);
39
+ const signer = keplrProvider.getOfflineSignerOnlyAmino(chainId);
40
+ if (!signer) throw new SwapKitError("wallet_cosmostation_signer_not_found");
41
+
42
+ const { getCosmosToolbox } = await import("@swapkit/toolboxes/cosmos");
43
+
44
+ const accounts = await signer.getAccounts();
45
+ if (!accounts?.[0]?.address) throw new SwapKitError("wallet_cosmostation_no_accounts");
46
+
47
+ const [{ address }] = accounts;
48
+ const toolbox = getCosmosToolbox(chain as any, { signer });
49
+
50
+ addChain({
51
+ ...toolbox,
52
+ chain,
53
+ address,
54
+ walletType: WalletOption.COSMOSTATION,
55
+ });
56
+ }),
57
+ );
58
+ }
59
+
60
+ async function connectEvmChains(chains: Chain[], addChain: any) {
61
+ const provider = window.ethereum;
62
+
63
+ if (!provider) {
64
+ throw new SwapKitError("wallet_cosmostation_evm_provider_not_found");
65
+ }
66
+
67
+ const accounts = (await provider.request({
68
+ method: "eth_requestAccounts",
69
+ })) as string[];
70
+
71
+ if (!accounts || accounts.length === 0) {
72
+ throw new SwapKitError("wallet_cosmostation_no_evm_accounts");
73
+ }
74
+
75
+ const { getEvmToolbox } = await import("@swapkit/toolboxes/evm");
76
+
77
+ for (const chain of chains) {
78
+ const toolbox = getEvmToolbox(chain as any, { provider });
79
+ const [address] = accounts;
80
+
81
+ if (!address) {
82
+ throw new SwapKitError("wallet_cosmostation_no_evm_address");
83
+ }
84
+
85
+ addChain({
86
+ ...toolbox,
87
+ chain,
88
+ address,
89
+ walletType: WalletOption.COSMOSTATION,
90
+ });
91
+ }
92
+ }
93
+
94
+ export const cosmostationWallet = createWallet({
95
+ name: "connectCosmostation",
96
+ supportedChains: [
97
+ Chain.Cosmos,
98
+ Chain.Kujira,
99
+ Chain.THORChain,
100
+ Chain.Ethereum,
101
+ Chain.BinanceSmartChain,
102
+ Chain.Avalanche,
103
+ Chain.Polygon,
104
+ Chain.Arbitrum,
105
+ Chain.Optimism,
106
+ Chain.Base,
107
+ ],
108
+ connect: ({ addChain, supportedChains }) =>
109
+ async function connectCosmostation(chains: Chain[]) {
110
+ const filteredChains = filterSupportedChains({
111
+ chains,
112
+ supportedChains,
113
+ walletType: WalletOption.COSMOSTATION,
114
+ });
115
+
116
+ if (!window.cosmostation) {
117
+ throw new SwapKitError("wallet_cosmostation_not_found");
118
+ }
119
+
120
+ const cosmosChains = filteredChains.filter((chain) =>
121
+ cosmostationSupportedChainIds.includes(ChainToChainId[chain] as any),
122
+ );
123
+ const evmChains = filteredChains.filter((chain) =>
124
+ cosmostationSupportedEVMChains.includes(chain as any),
125
+ );
126
+
127
+ if (cosmosChains.length > 0) {
128
+ const keplrProvider = window.cosmostation.providers?.keplr;
129
+ if (!keplrProvider) {
130
+ throw new SwapKitError("wallet_cosmostation_keplr_provider_not_found");
131
+ }
132
+
133
+ await connectCosmosChains(cosmosChains, addChain, keplrProvider);
134
+ }
135
+
136
+ if (evmChains.length > 0) {
137
+ await connectEvmChains(evmChains, addChain);
138
+ }
139
+
140
+ return true;
141
+ },
142
+ });
@@ -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, Chain.Maya, Chain.THORChain, () => window.xfi?.keplr)
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
 
@@ -90,55 +93,67 @@ async function transaction({
90
93
  }
91
94
 
92
95
  export async function getCtrlAddress(chain: Chain) {
93
- const eipProvider = (await getCtrlProvider(chain)) as Eip1193Provider;
94
- if (!eipProvider) {
95
- throw new SwapKitError({
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) {
96
+ try {
97
+ const eipProvider = (await getCtrlProvider(chain)) as Eip1193Provider;
98
+ if (!eipProvider) {
104
99
  throw new SwapKitError({
105
100
  errorKey: "wallet_provider_not_found",
106
101
  info: { wallet: WalletOption.CTRL, chain },
107
102
  });
108
103
  }
109
104
 
110
- // Enabling before using the Keplr is recommended.
111
- // This method will ask the user whether to allow access if they haven't visited this website.
112
- // Also, it will request that the user unlock the wallet if the wallet is locked.
113
- const chainId = ChainToChainId[chain];
114
- await provider.enable(chainId);
105
+ if ([Chain.Cosmos, Chain.Kujira].includes(chain)) {
106
+ const provider = await getCtrlProvider(Chain.Cosmos);
107
+ if (!provider || "request" in provider) {
108
+ throw new SwapKitError({
109
+ errorKey: "wallet_provider_not_found",
110
+ info: { wallet: WalletOption.CTRL, chain },
111
+ });
112
+ }
115
113
 
116
- const offlineSigner = provider.getOfflineSigner(chainId);
114
+ // Enabling before using the Keplr is recommended.
115
+ // This method will ask the user whether to allow access if they haven't visited this website.
116
+ // Also, it will request that the user unlock the wallet if the wallet is locked.
117
+ const chainId = ChainToChainId[chain];
118
+ await provider.enable(chainId);
117
119
 
118
- const [item] = await offlineSigner.getAccounts();
119
- return item?.address;
120
- }
120
+ const offlineSigner = provider.getOfflineSigner(chainId);
121
121
 
122
- if (EVMChains.includes(chain as EVMChain)) {
123
- const [response] = await eipProvider.request({ method: "eth_requestAccounts", params: [] });
122
+ const [item] = await offlineSigner.getAccounts();
123
+ return item?.address;
124
+ }
124
125
 
125
- return response;
126
- }
126
+ if (EVMChains.includes(chain as EVMChain)) {
127
+ // For CTRL wallet, we need to use the request method directly on the provider
128
+ if ("request" in eipProvider && typeof eipProvider.request === "function") {
129
+ const accounts = await eipProvider.request({ method: "eth_requestAccounts" });
130
+ return accounts[0];
131
+ }
132
+ const { BrowserProvider } = await import("ethers");
133
+ const provider = new BrowserProvider(eipProvider, "any");
134
+ const [response] = await providerRequest({
135
+ provider,
136
+ method: "eth_requestAccounts",
137
+ params: [],
138
+ });
139
+ return response;
140
+ }
127
141
 
128
- if (chain === Chain.Solana) {
129
- const provider = await getCtrlProvider(Chain.Solana);
142
+ if (chain === Chain.Solana) {
143
+ const provider = await getCtrlProvider(Chain.Solana);
130
144
 
131
- const accounts = await provider.connect();
132
- return accounts.publicKey.toString();
133
- }
145
+ const accounts = await provider.connect();
146
+ return accounts.publicKey.toString();
147
+ }
134
148
 
135
- return new Promise((resolve, reject) =>
136
- eipProvider.request(
137
- { method: "request_accounts", params: [] },
138
- // @ts-expect-error
139
- (error: any, [response]: string[]) => (error ? reject(error) : resolve(response)),
140
- ),
141
- );
149
+ const accounts = await eipProvider.request({ method: "request_accounts", params: [] });
150
+ return accounts[0];
151
+ } catch (_error) {
152
+ throw new SwapKitError({
153
+ errorKey: "wallet_provider_not_found",
154
+ info: { wallet: WalletOption.CTRL, chain },
155
+ });
156
+ }
142
157
  }
143
158
 
144
159
  export async function walletTransfer(
@@ -188,8 +203,9 @@ export function getCtrlMethods(provider: BrowserProvider, chain: EVMChain) {
188
203
  if (!contractAddress) {
189
204
  throw new SwapKitError("wallet_ctrl_contract_address_not_provided");
190
205
  }
191
- const { createContract, getCreateContractTxObject, isStateChangingCall, toHexString } =
192
- await import("@swapkit/toolboxes/evm");
206
+ const { createContract, getCreateContractTxObject, isStateChangingCall } = await import(
207
+ "@swapkit/toolboxes/evm"
208
+ );
193
209
 
194
210
  const isStateChanging = isStateChangingCall({ abi, funcName });
195
211
 
@@ -203,14 +219,14 @@ export function getCtrlMethods(provider: BrowserProvider, chain: EVMChain) {
203
219
  txOverrides,
204
220
  });
205
221
 
206
- return provider.send("eth_sendTransaction", [
207
- {
208
- value: toHexString(BigInt(value || 0)),
209
- from,
210
- to,
211
- data: data || "0x",
212
- } as any,
213
- ]);
222
+ const signer = await provider.getSigner();
223
+ const tx = await signer.sendTransaction({
224
+ value: BigInt(value || 0),
225
+ from,
226
+ to,
227
+ data: data || "0x",
228
+ });
229
+ return tx.hash as T;
214
230
  }
215
231
  const contract = createContract(contractAddress, abi, provider);
216
232
 
@@ -219,9 +235,7 @@ export function getCtrlMethods(provider: BrowserProvider, chain: EVMChain) {
219
235
  return typeof result?.hash === "string" ? result?.hash : result;
220
236
  },
221
237
  approve: async ({ assetAddress, spenderAddress, amount, from }: ApproveParams) => {
222
- const { MAX_APPROVAL, getCreateContractTxObject, toHexString } = await import(
223
- "@swapkit/toolboxes/evm"
224
- );
238
+ const { MAX_APPROVAL, getCreateContractTxObject } = await import("@swapkit/toolboxes/evm");
225
239
  const funcParams = [spenderAddress, BigInt(amount || MAX_APPROVAL)];
226
240
  const txOverrides = { from };
227
241
 
@@ -236,31 +250,29 @@ export function getCtrlMethods(provider: BrowserProvider, chain: EVMChain) {
236
250
  const createTx = getCreateContractTxObject({ provider, chain });
237
251
  const { value, to, data } = await createTx(functionCallParams);
238
252
 
239
- return provider.send("eth_sendTransaction", [
240
- {
241
- value: toHexString(BigInt(value || 0)),
242
- from,
243
- to,
244
- data: data || "0x",
245
- } as any,
246
- ]);
253
+ const signer = await provider.getSigner();
254
+ const tx = await signer.sendTransaction({
255
+ value: BigInt(value || 0),
256
+ from,
257
+ to,
258
+ data: data || "0x",
259
+ });
260
+ return tx.hash;
247
261
  },
248
- sendTransaction: async (tx: EVMTxParams) => {
249
- const { from, to, data, value } = tx;
262
+ sendTransaction: async (txParams: EVMTxParams) => {
263
+ const { from, to, data, value } = txParams;
250
264
  if (!to) {
251
265
  throw new SwapKitError("wallet_ctrl_send_transaction_no_address");
252
266
  }
253
267
 
254
- const { toHexString } = await import("@swapkit/toolboxes/evm");
255
-
256
- return provider.send("eth_sendTransaction", [
257
- {
258
- value: toHexString(BigInt(value || 0)),
259
- from,
260
- to,
261
- data: data || "0x",
262
- } as any,
263
- ]);
268
+ const signer = await provider.getSigner();
269
+ const tx = await signer.sendTransaction({
270
+ value: BigInt(value || 0),
271
+ from,
272
+ to,
273
+ data: data || "0x",
274
+ });
275
+ return tx.hash;
264
276
  },
265
277
  };
266
278
  }
@@ -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 Error("Requested web3 wallet is not installed");
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 Error(`Failed to add/switch ${chain} network: ${chain}`);
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 Error("Missing provider");
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", []);
@@ -9,7 +9,7 @@ import {
9
9
  prepareNetworkSwitch,
10
10
  switchEVMWalletNetwork,
11
11
  } from "@swapkit/helpers";
12
- import type { Psbt } from "bitcoinjs-lib";
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 Error("No address found");
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 Error("Request canceled");
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 Error("Signature canceled");
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 Error("Requested web3 wallet is not installed");
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 Error(`Failed to add/switch ${chain} network: ${chain}`);
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 Error(`Unsupported chain: ${chain}`);
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 Error("Missing Exodus Wallet instance");
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
 
@@ -21,64 +21,58 @@ export const cosmosWalletMethods = async ({
21
21
  getFeeRateFromThorswap,
22
22
  createStargateClient,
23
23
  } = await import("@swapkit/toolboxes/cosmos");
24
+ const derivationPathString = derivationPath
25
+ ? derivationPathToString(derivationPath)
26
+ : `${DerivationPath.GAIA}/0`;
24
27
 
25
- try {
26
- const derivationPathString = derivationPath
27
- ? derivationPathToString(derivationPath)
28
- : `${DerivationPath.GAIA}/0`;
28
+ const { address: fromAddress } = (await sdk.address.cosmosGetAddress({
29
+ address_n: bip32ToAddressNList(derivationPathString),
30
+ })) as { address: string };
29
31
 
30
- const { address: fromAddress } = (await sdk.address.cosmosGetAddress({
31
- address_n: bip32ToAddressNList(derivationPathString),
32
- })) as { address: string };
32
+ const toolbox = await getCosmosToolbox(Chain.Cosmos);
33
33
 
34
- const toolbox = await getCosmosToolbox(Chain.Cosmos);
35
-
36
- if (DEFAULT_COSMOS_FEE_MAINNET.amount[0]) {
37
- DEFAULT_COSMOS_FEE_MAINNET.amount[0].amount = String(
38
- await getFeeRateFromThorswap(ChainId.Cosmos, 500),
39
- );
40
- }
34
+ if (DEFAULT_COSMOS_FEE_MAINNET.amount[0]) {
35
+ DEFAULT_COSMOS_FEE_MAINNET.amount[0].amount = String(
36
+ await getFeeRateFromThorswap(ChainId.Cosmos, 500),
37
+ );
38
+ }
41
39
 
42
- // TODO support other cosmos assets
43
- const transfer = async ({ assetValue, recipient, memo }: GenericTransferParams) => {
44
- const amount = assetValue.getBaseValue("string");
45
- const accountInfo = await toolbox.getAccount(fromAddress);
40
+ // TODO support other cosmos assets
41
+ const transfer = async ({ assetValue, recipient, memo }: GenericTransferParams) => {
42
+ const amount = assetValue.getBaseValue("string");
43
+ const accountInfo = await toolbox.getAccount(fromAddress);
46
44
 
47
- const keepKeySignedTx = await sdk.cosmos.cosmosSignAmino({
48
- signerAddress: fromAddress,
49
- signDoc: {
50
- fee: DEFAULT_COSMOS_FEE_MAINNET,
51
- memo: memo || "",
52
- sequence: accountInfo?.sequence.toString() ?? "",
53
- chain_id: ChainId.Cosmos,
54
- account_number: accountInfo?.accountNumber.toString() ?? "",
55
- msgs: [
56
- {
57
- value: {
58
- amount: [{ denom: "uatom", amount }],
59
- to_address: recipient,
60
- from_address: fromAddress,
61
- },
62
- type: "cosmos-sdk/MsgSend",
45
+ const keepKeySignedTx = await sdk.cosmos.cosmosSignAmino({
46
+ signerAddress: fromAddress,
47
+ signDoc: {
48
+ fee: DEFAULT_COSMOS_FEE_MAINNET,
49
+ memo: memo || "",
50
+ sequence: accountInfo?.sequence.toString() ?? "",
51
+ chain_id: ChainId.Cosmos,
52
+ account_number: accountInfo?.accountNumber.toString() ?? "",
53
+ msgs: [
54
+ {
55
+ value: {
56
+ amount: [{ denom: "uatom", amount }],
57
+ to_address: recipient,
58
+ from_address: fromAddress,
63
59
  },
64
- ],
65
- },
66
- });
60
+ type: "cosmos-sdk/MsgSend",
61
+ },
62
+ ],
63
+ },
64
+ });
67
65
 
68
- const decodedBytes = atob(keepKeySignedTx.serialized);
69
- const uint8Array = new Uint8Array(decodedBytes.length).map((_, i) =>
70
- decodedBytes.charCodeAt(i),
71
- );
66
+ const decodedBytes = atob(keepKeySignedTx.serialized);
67
+ const uint8Array = new Uint8Array(decodedBytes.length).map((_, i) =>
68
+ decodedBytes.charCodeAt(i),
69
+ );
72
70
 
73
- const client = await createStargateClient(SKConfig.get("rpcUrls")[Chain.Cosmos]);
74
- const response = await client.broadcastTx(uint8Array);
71
+ const client = await createStargateClient(SKConfig.get("rpcUrls")[Chain.Cosmos]);
72
+ const response = await client.broadcastTx(uint8Array);
75
73
 
76
- return response.transactionHash;
77
- };
74
+ return response.transactionHash;
75
+ };
78
76
 
79
- return { ...toolbox, transfer, address: fromAddress };
80
- } catch (e) {
81
- console.error(e);
82
- throw e;
83
- }
77
+ return { ...toolbox, transfer, address: fromAddress };
84
78
  };
@@ -4,6 +4,7 @@ import {
4
4
  ChainToChainId,
5
5
  type DerivationPathArray,
6
6
  NetworkDerivationPath,
7
+ SwapKitError,
7
8
  derivationPathToString,
8
9
  } from "@swapkit/helpers";
9
10
  import type { JsonRpcProvider, Provider, TransactionRequest } from "ethers";
@@ -35,7 +36,7 @@ export class KeepKeySigner extends AbstractSigner {
35
36
  }
36
37
 
37
38
  signTypedData(): Promise<string> {
38
- throw new Error("this method is not implemented");
39
+ throw new SwapKitError("wallet_keepkey_method_not_supported", { method: "signTypedData" });
39
40
  }
40
41
 
41
42
  getAddress = async () => {
@@ -62,14 +63,21 @@ export class KeepKeySigner extends AbstractSigner {
62
63
  gasPrice,
63
64
  // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: <explanation>
64
65
  }: TransactionRequest) => {
65
- if (!to) throw new Error("Missing to address");
66
- if (!gasLimit) throw new Error("Missing gasLimit");
67
- if (!data) throw new Error("Missing data");
66
+ if (!to)
67
+ throw new SwapKitError("wallet_keepkey_invalid_params", { reason: "Missing to address" });
68
+ if (!gasLimit)
69
+ throw new SwapKitError("wallet_keepkey_invalid_params", { reason: "Missing gasLimit" });
70
+ if (!data) throw new SwapKitError("wallet_keepkey_invalid_params", { reason: "Missing data" });
68
71
 
69
72
  const isEIP1559 = !!((maxFeePerGas || maxPriorityFeePerGas) && !gasPrice);
70
- if (isEIP1559 && !maxFeePerGas) throw new Error("Missing maxFeePerGas");
71
- if (isEIP1559 && !maxPriorityFeePerGas) throw new Error("Missing maxFeePerGas");
72
- if (!(isEIP1559 || gasPrice)) throw new Error("Missing gasPrice");
73
+ if (isEIP1559 && !maxFeePerGas)
74
+ throw new SwapKitError("wallet_keepkey_invalid_params", { reason: "Missing maxFeePerGas" });
75
+ if (isEIP1559 && !maxPriorityFeePerGas)
76
+ throw new SwapKitError("wallet_keepkey_invalid_params", {
77
+ reason: "Missing maxPriorityFeePerGas",
78
+ });
79
+ if (!(isEIP1559 || gasPrice))
80
+ throw new SwapKitError("wallet_keepkey_invalid_params", { reason: "Missing gasPrice" });
73
81
 
74
82
  const { toHexString } = await import("@swapkit/toolboxes/evm");
75
83
 
@@ -100,7 +108,7 @@ export class KeepKeySigner extends AbstractSigner {
100
108
  };
101
109
 
102
110
  sendTransaction = async (tx: TransactionRequest): Promise<any> => {
103
- if (!this.provider) throw new Error("No provider set");
111
+ if (!this.provider) throw new SwapKitError("wallet_keepkey_no_provider");
104
112
 
105
113
  const signedTxHex = await this.signTransaction(tx);
106
114