@swapkit/wallets 3.0.0-beta.0 → 3.0.0-beta.10

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 (142) hide show
  1. package/dist/chunk-0ttw612a.js +4 -0
  2. package/dist/chunk-0ttw612a.js.map +10 -0
  3. package/dist/chunk-8pv8t9qa.js +3 -0
  4. package/dist/chunk-8pv8t9qa.js.map +10 -0
  5. package/dist/{chunk-5m175wfy.js → chunk-p1kdg37m.js} +2 -2
  6. package/dist/{chunk-5m175wfy.js.map → chunk-p1kdg37m.js.map} +1 -1
  7. package/dist/chunk-ta4bdjpy.js +3 -0
  8. package/dist/chunk-ta4bdjpy.js.map +10 -0
  9. package/dist/chunk-w07sv0jv.js +3 -0
  10. package/dist/chunk-w07sv0jv.js.map +10 -0
  11. package/dist/src/bitget/index.cjs +2 -2
  12. package/dist/src/bitget/index.cjs.map +5 -5
  13. package/dist/src/bitget/index.js +2 -2
  14. package/dist/src/bitget/index.js.map +5 -5
  15. package/dist/src/coinbase/index.cjs +2 -2
  16. package/dist/src/coinbase/index.cjs.map +4 -4
  17. package/dist/src/coinbase/index.js +2 -3
  18. package/dist/src/coinbase/index.js.map +4 -4
  19. package/dist/src/ctrl/index.cjs +2 -2
  20. package/dist/src/ctrl/index.cjs.map +5 -5
  21. package/dist/src/ctrl/index.js +2 -2
  22. package/dist/src/ctrl/index.js.map +5 -5
  23. package/dist/src/evm-extensions/index.cjs +2 -2
  24. package/dist/src/evm-extensions/index.cjs.map +3 -3
  25. package/dist/src/evm-extensions/index.js +2 -3
  26. package/dist/src/evm-extensions/index.js.map +3 -3
  27. package/dist/src/exodus/index.cjs +2 -2
  28. package/dist/src/exodus/index.cjs.map +3 -3
  29. package/dist/src/exodus/index.js +2 -3
  30. package/dist/src/exodus/index.js.map +3 -3
  31. package/dist/src/index.cjs +2 -2
  32. package/dist/src/index.cjs.map +3 -4
  33. package/dist/src/index.js +2 -2
  34. package/dist/src/index.js.map +3 -4
  35. package/dist/src/keepkey/index.cjs +2 -2
  36. package/dist/src/keepkey/index.cjs.map +7 -7
  37. package/dist/src/keepkey/index.js +2 -3
  38. package/dist/src/keepkey/index.js.map +7 -7
  39. package/dist/src/keepkey-bex/index.cjs +2 -2
  40. package/dist/src/keepkey-bex/index.cjs.map +4 -4
  41. package/dist/src/keepkey-bex/index.js +2 -3
  42. package/dist/src/keepkey-bex/index.js.map +4 -4
  43. package/dist/src/keplr/index.cjs +2 -2
  44. package/dist/src/keplr/index.cjs.map +3 -3
  45. package/dist/src/keplr/index.js +2 -3
  46. package/dist/src/keplr/index.js.map +3 -3
  47. package/dist/src/keystore/index.cjs +2 -2
  48. package/dist/src/keystore/index.cjs.map +4 -4
  49. package/dist/src/keystore/index.js +2 -3
  50. package/dist/src/keystore/index.js.map +4 -4
  51. package/dist/src/ledger/index.cjs +3 -3
  52. package/dist/src/ledger/index.cjs.map +11 -11
  53. package/dist/src/ledger/index.js +3 -4
  54. package/dist/src/ledger/index.js.map +11 -11
  55. package/dist/src/okx/index.cjs +2 -2
  56. package/dist/src/okx/index.cjs.map +4 -4
  57. package/dist/src/okx/index.js +2 -3
  58. package/dist/src/okx/index.js.map +4 -4
  59. package/dist/src/onekey/index.cjs +3 -0
  60. package/dist/src/onekey/index.cjs.map +10 -0
  61. package/dist/src/onekey/index.js +3 -0
  62. package/dist/src/onekey/index.js.map +10 -0
  63. package/dist/src/phantom/index.cjs +2 -2
  64. package/dist/src/phantom/index.cjs.map +3 -3
  65. package/dist/src/phantom/index.js +2 -3
  66. package/dist/src/phantom/index.js.map +3 -3
  67. package/dist/src/polkadotjs/index.cjs +2 -2
  68. package/dist/src/polkadotjs/index.cjs.map +3 -3
  69. package/dist/src/polkadotjs/index.js +2 -3
  70. package/dist/src/polkadotjs/index.js.map +3 -3
  71. package/dist/src/radix/index.cjs +2 -2
  72. package/dist/src/radix/index.cjs.map +3 -3
  73. package/dist/src/radix/index.js +2 -3
  74. package/dist/src/radix/index.js.map +3 -3
  75. package/dist/src/talisman/index.cjs +2 -2
  76. package/dist/src/talisman/index.cjs.map +3 -3
  77. package/dist/src/talisman/index.js +2 -3
  78. package/dist/src/talisman/index.js.map +3 -3
  79. package/dist/src/trezor/index.cjs +2 -2
  80. package/dist/src/trezor/index.cjs.map +3 -3
  81. package/dist/src/trezor/index.js +2 -3
  82. package/dist/src/trezor/index.js.map +3 -3
  83. package/dist/src/walletconnect/index.cjs +2 -2
  84. package/dist/src/walletconnect/index.cjs.map +5 -5
  85. package/dist/src/walletconnect/index.js +2 -3
  86. package/dist/src/walletconnect/index.js.map +5 -5
  87. package/package.json +29 -26
  88. package/src/bitget/helpers.ts +33 -93
  89. package/src/bitget/index.ts +32 -54
  90. package/src/coinbase/index.ts +2 -2
  91. package/src/coinbase/signer.ts +46 -42
  92. package/src/ctrl/index.ts +157 -22
  93. package/src/ctrl/walletHelpers.ts +45 -94
  94. package/src/evm-extensions/index.ts +21 -40
  95. package/src/exodus/index.ts +18 -28
  96. package/src/index.ts +2 -37
  97. package/src/keepkey/chains/cosmos.ts +10 -7
  98. package/src/keepkey/chains/mayachain.ts +25 -25
  99. package/src/keepkey/chains/thorchain.ts +20 -14
  100. package/src/keepkey/chains/utxo.ts +36 -48
  101. package/src/keepkey/index.ts +9 -23
  102. package/src/keepkey-bex/index.ts +25 -23
  103. package/src/keepkey-bex/walletHelpers.ts +8 -36
  104. package/src/keplr/index.ts +6 -53
  105. package/src/keystore/helpers.ts +33 -56
  106. package/src/keystore/index.ts +15 -183
  107. package/src/ledger/clients/cosmos.ts +2 -2
  108. package/src/ledger/clients/evm.ts +3 -7
  109. package/src/ledger/clients/thorchain/lib.ts +0 -19
  110. package/src/ledger/clients/utxo.ts +5 -4
  111. package/src/ledger/helpers/getLedgerClient.ts +2 -2
  112. package/src/ledger/helpers/getLedgerTransport.ts +3 -3
  113. package/src/ledger/index.ts +21 -22
  114. package/src/ledger/interfaces/CosmosLedgerInterface.ts +1 -1
  115. package/src/ledger/types.ts +1 -1
  116. package/src/okx/helpers.ts +23 -33
  117. package/src/okx/index.ts +4 -47
  118. package/src/onekey/evmSigner.ts +133 -0
  119. package/src/onekey/index.ts +213 -0
  120. package/src/phantom/index.ts +18 -42
  121. package/src/polkadotjs/index.ts +5 -7
  122. package/src/radix/index.ts +31 -47
  123. package/src/talisman/index.ts +15 -32
  124. package/src/trezor/evmSigner.ts +3 -3
  125. package/src/trezor/index.ts +49 -48
  126. package/src/types.ts +199 -0
  127. package/src/utils.ts +54 -0
  128. package/src/walletconnect/constants.ts +1 -1
  129. package/src/walletconnect/helpers.ts +2 -2
  130. package/src/walletconnect/index.ts +38 -39
  131. package/dist/chunk-bhfpfqc3.js +0 -3
  132. package/dist/chunk-bhfpfqc3.js.map +0 -10
  133. package/dist/chunk-f76hj57k.js +0 -3
  134. package/dist/chunk-f76hj57k.js.map +0 -10
  135. package/dist/chunk-ha78se5g.js +0 -4
  136. package/dist/chunk-ha78se5g.js.map +0 -10
  137. package/dist/chunk-yvbvzc0q.js +0 -3
  138. package/dist/chunk-yvbvzc0q.js.map +0 -10
  139. package/src/bitget/bitgetWallet.ts +0 -32
  140. package/src/ctrl/ctrlWallet.ts +0 -175
  141. package/src/helpers.ts +0 -8
  142. package/src/ledger/ledgerLive.ts +0 -429
@@ -35,7 +35,7 @@ export async function getEVMSigner({ chain, derivationPath, provider }: TrezorEV
35
35
 
36
36
  getAddress = async () => {
37
37
  if (!this.address) {
38
- const { default: TrezorConnect } = await import("@trezor/connect-web");
38
+ const TrezorConnect = (await import("@trezor/connect-web")).default;
39
39
 
40
40
  const result = await TrezorConnect.ethereumGetAddress({
41
41
  path: derivationPathToString(this.derivationPath),
@@ -56,7 +56,7 @@ export async function getEVMSigner({ chain, derivationPath, provider }: TrezorEV
56
56
  };
57
57
 
58
58
  signMessage = async (message: string) => {
59
- const { default: TrezorConnect } = await import("@trezor/connect-web");
59
+ const TrezorConnect = (await import("@trezor/connect-web")).default;
60
60
 
61
61
  const result = await TrezorConnect.ethereumSignMessage({
62
62
  path: derivationPathToString(this.derivationPath),
@@ -107,7 +107,7 @@ export async function getEVMSigner({ chain, derivationPath, provider }: TrezorEV
107
107
  throw new SwapKitError({ errorKey: "wallet_missing_params", info: { gasPrice } });
108
108
  }
109
109
 
110
- const { default: TrezorConnect } = await import("@trezor/connect-web");
110
+ const TrezorConnect = (await import("@trezor/connect-web")).default;
111
111
  const { toHexString } = await import("@swapkit/toolboxes/evm");
112
112
  const { Transaction } = await import("ethers");
113
113
 
@@ -2,6 +2,7 @@ import {
2
2
  Chain,
3
3
  type DerivationPathArray,
4
4
  FeeOption,
5
+ type GenericTransferParams,
5
6
  SKConfig,
6
7
  SwapKitError,
7
8
  WalletOption,
@@ -9,8 +10,9 @@ import {
9
10
  derivationPathToString,
10
11
  filterSupportedChains,
11
12
  } from "@swapkit/helpers";
12
- import type { Psbt, UTXOTransferParams, UTXOType } from "@swapkit/toolboxes/utxo";
13
- import { getWalletSupportedChains } from "../helpers";
13
+ import type { UTXOToolboxes, UTXOType } from "@swapkit/toolboxes/utxo";
14
+ import type { Psbt } from "bitcoinjs-lib";
15
+ import { getWalletSupportedChains } from "../utils";
14
16
 
15
17
  function getScriptType(derivationPath: DerivationPathArray) {
16
18
  switch (derivationPath[0]) {
@@ -25,10 +27,10 @@ function getScriptType(derivationPath: DerivationPathArray) {
25
27
  }
26
28
  }
27
29
 
28
- async function getToolbox({
30
+ async function getTrezorWallet<T extends Chain>({
29
31
  chain,
30
32
  derivationPath,
31
- }: { chain: Chain; derivationPath: DerivationPathArray }) {
33
+ }: { chain: T; derivationPath: DerivationPathArray }) {
32
34
  switch (chain) {
33
35
  case Chain.BinanceSmartChain:
34
36
  case Chain.Avalanche:
@@ -37,15 +39,15 @@ async function getToolbox({
37
39
  case Chain.Polygon:
38
40
  case Chain.Base:
39
41
  case Chain.Ethereum: {
40
- const { getProvider, getToolboxByChain } = await import("@swapkit/toolboxes/evm");
42
+ const { getProvider, getEvmToolbox } = await import("@swapkit/toolboxes/evm");
41
43
  const { getEVMSigner } = await import("./evmSigner");
42
44
 
43
- const provider = getProvider(chain);
45
+ const provider = await getProvider(chain);
44
46
  const signer = await getEVMSigner({ chain, derivationPath, provider });
45
47
  const address = await signer.getAddress();
46
- const toolbox = getToolboxByChain(chain)({ provider, signer });
48
+ const toolbox = await getEvmToolbox(chain, { provider, signer });
47
49
 
48
- return { address, walletMethods: toolbox };
50
+ return { ...toolbox, address };
49
51
  }
50
52
 
51
53
  case Chain.Bitcoin:
@@ -53,10 +55,7 @@ async function getToolbox({
53
55
  case Chain.Dash:
54
56
  case Chain.Dogecoin:
55
57
  case Chain.Litecoin: {
56
- const { toCashAddress, getToolboxByChain, BCHToolbox } = await import(
57
- "@swapkit/toolboxes/utxo"
58
- );
59
-
58
+ const { toCashAddress, getUtxoToolbox } = await import("@swapkit/toolboxes/utxo");
60
59
  const scriptType = getScriptType(derivationPath);
61
60
 
62
61
  if (!scriptType) {
@@ -67,10 +66,9 @@ async function getToolbox({
67
66
  }
68
67
 
69
68
  const coin = chain.toLowerCase();
70
- const toolbox = getToolboxByChain(chain)();
71
69
 
72
70
  const getAddress = async (path: DerivationPathArray = derivationPath) => {
73
- const { default: TrezorConnect } = await import("@trezor/connect-web");
71
+ const TrezorConnect = (await import("@trezor/connect-web")).default;
74
72
  const { success, payload } = await TrezorConnect.getAddress({
75
73
  path: derivationPathToString(path),
76
74
  coin,
@@ -86,44 +84,43 @@ async function getToolbox({
86
84
  });
87
85
  }
88
86
 
89
- return chain === Chain.BitcoinCash
90
- ? (toolbox as ReturnType<typeof BCHToolbox>).stripPrefix(payload.address)
91
- : payload.address;
87
+ if (chain === Chain.BitcoinCash) {
88
+ const toolbox = await getUtxoToolbox(chain as Chain.BitcoinCash);
89
+ return toolbox.stripPrefix(payload.address);
90
+ }
91
+
92
+ return payload.address;
92
93
  };
93
94
 
94
95
  const address = await getAddress();
95
96
 
96
97
  const signTransaction = async (psbt: Psbt, inputs: UTXOType[], memo = "") => {
97
- const { default: TrezorConnect } = await import("@trezor/connect-web");
98
+ const TrezorConnect = (await import("@trezor/connect-web")).default;
98
99
  const address_n = derivationPath.map((pathElement, index) =>
99
100
  index < 3 ? ((pathElement as number) | 0x80000000) >>> 0 : (pathElement as number),
100
101
  );
102
+ const toolbox = await getUtxoToolbox(chain as Chain.BitcoinCash);
101
103
 
102
104
  const result = await TrezorConnect.signTransaction({
103
105
  coin,
104
- inputs: inputs.map((input) => ({
106
+ inputs: inputs.map(({ hash, index, value }) => ({
105
107
  // Hardens the first 3 elements of the derivation path - required by trezor
106
108
  address_n,
107
- prev_hash: input.hash,
108
- prev_index: input.index,
109
+ prev_hash: hash,
110
+ prev_index: index,
109
111
  // object needs amount but does not use it for signing
110
- amount: input.value,
112
+ amount: value,
111
113
  script_type: scriptType.input,
112
114
  })),
113
115
 
114
116
  // Lint is not happy with the type of txOutputs
115
- // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: TODO: refactor
116
117
  outputs: psbt.txOutputs.map((output: any) => {
117
118
  const outputAddress =
118
119
  chain === Chain.BitcoinCash && output.address
119
- ? toCashAddress(output.address)
120
+ ? toolbox.stripPrefix(toCashAddress(output.address))
120
121
  : output.address;
121
122
 
122
- // Strip prefix from BCH address to compare with stripped address from Trezor
123
- const isChangeAddress =
124
- chain === Chain.BitcoinCash && outputAddress
125
- ? (toolbox as ReturnType<typeof BCHToolbox>).stripPrefix(outputAddress) === address
126
- : outputAddress === address;
123
+ const isChangeAddress = outputAddress === address;
127
124
 
128
125
  // OP_RETURN
129
126
  if (!output.address) {
@@ -134,17 +131,13 @@ async function getToolbox({
134
131
  };
135
132
  }
136
133
 
137
- // Change Address
138
- if (isChangeAddress) {
139
- return { address_n, amount: output.value, script_type: scriptType.output };
140
- }
141
-
142
- // Outgoing UTXO
143
- return { address: outputAddress, amount: output.value, script_type: "PAYTOADDRESS" };
134
+ return isChangeAddress
135
+ ? { amount: output.value, address_n, script_type: scriptType.output }
136
+ : { amount: output.value, address: outputAddress, script_type: "PAYTOADDRESS" };
144
137
  }),
145
138
  });
146
139
 
147
- if (result.success && result.payload?.serializedTx) {
140
+ if (result.success) {
148
141
  return result.payload.serializedTx;
149
142
  }
150
143
 
@@ -158,30 +151,36 @@ async function getToolbox({
158
151
  };
159
152
 
160
153
  const transfer = async ({
161
- from,
162
154
  recipient,
163
155
  feeOptionKey,
164
156
  feeRate: paramFeeRate,
165
157
  memo,
166
158
  ...rest
167
- }: UTXOTransferParams) => {
168
- if (!(from && recipient)) {
159
+ }: GenericTransferParams) => {
160
+ if (!(address && recipient)) {
169
161
  throw new SwapKitError({
170
162
  errorKey: "wallet_missing_params",
171
- info: { wallet: WalletOption.TREZOR, memo, from, recipient },
163
+ info: { wallet: WalletOption.TREZOR, memo, address, recipient },
172
164
  });
173
165
  }
174
166
 
167
+ const toolbox = await getUtxoToolbox(chain);
168
+
175
169
  const feeRate =
176
170
  paramFeeRate || (await toolbox.getFeeRates())[feeOptionKey || FeeOption.Fast];
177
171
 
178
- const { psbt, inputs } = await toolbox.buildTx({
172
+ const createTxMethod =
173
+ chain === Chain.BitcoinCash
174
+ ? (toolbox as UTXOToolboxes["BCH"]).buildTx
175
+ : (toolbox as UTXOToolboxes["BTC"]).createTransaction;
176
+
177
+ const { psbt, inputs } = await createTxMethod({
179
178
  ...rest,
180
179
  memo,
181
180
  recipient,
182
181
  feeRate,
183
- sender: from,
184
- fetchTxHex: chain === Chain.Dogecoin,
182
+ sender: address,
183
+ fetchTxHex: true,
185
184
  });
186
185
 
187
186
  const txHex = await signTransaction(psbt, inputs, memo);
@@ -190,7 +189,9 @@ async function getToolbox({
190
189
  return tx;
191
190
  };
192
191
 
193
- return { address, walletMethods: { ...toolbox, transfer, signTransaction } };
192
+ const toolbox = await getUtxoToolbox(chain);
193
+
194
+ return { ...toolbox, address, transfer, signTransaction };
194
195
  }
195
196
 
196
197
  default:
@@ -228,7 +229,7 @@ export const trezorWallet = createWallet({
228
229
  });
229
230
  }
230
231
 
231
- const { default: TrezorConnect } = await import("@trezor/connect-web");
232
+ const TrezorConnect = (await import("@trezor/connect-web")).default;
232
233
  const { success } = await TrezorConnect.getDeviceState();
233
234
 
234
235
  if (!success) {
@@ -236,9 +237,9 @@ export const trezorWallet = createWallet({
236
237
  TrezorConnect.init({ lazyLoad: true, manifest });
237
238
  }
238
239
 
239
- const { address, walletMethods } = await getToolbox({ chain, derivationPath });
240
+ const wallet = await getTrezorWallet({ chain, derivationPath });
240
241
 
241
- addChain({ ...walletMethods, address, balance: [], chain, walletType });
242
+ addChain({ ...wallet, chain, walletType });
242
243
 
243
244
  return true;
244
245
  },
package/src/types.ts ADDED
@@ -0,0 +1,199 @@
1
+ import type {
2
+ AminoSignResponse,
3
+ OfflineAminoSigner,
4
+ StdSignDoc,
5
+ StdSignature,
6
+ } from "@cosmjs/amino";
7
+ import type { Keplr } from "@keplr-wallet/types";
8
+ import { type EthereumWindowProvider, WalletOption } from "@swapkit/helpers";
9
+ import type { SolanaProvider } from "@swapkit/toolboxes/solana";
10
+ import type { BrowserProvider, Eip1193Provider } from "ethers";
11
+
12
+ import type { SubstrateInjectedExtension } from "@swapkit/toolboxes/substrate";
13
+ import type { bitgetWallet } from "./bitget";
14
+ import type { coinbaseWallet } from "./coinbase";
15
+ import type { ctrlWallet } from "./ctrl";
16
+ import type { evmWallet } from "./evm-extensions";
17
+ import type { exodusWallet } from "./exodus";
18
+ import type { keepkeyWallet } from "./keepkey";
19
+ import type { keepkeyBexWallet } from "./keepkey-bex";
20
+ import type { keplrWallet } from "./keplr";
21
+ import type { keystoreWallet } from "./keystore";
22
+ import type { ledgerWallet } from "./ledger";
23
+ import type { okxWallet } from "./okx";
24
+ import type { onekeyWallet } from "./onekey";
25
+ import type { phantomWallet } from "./phantom";
26
+ import type { polkadotWallet } from "./polkadotjs";
27
+ import type { radixWallet } from "./radix";
28
+ import type { talismanWallet } from "./talisman";
29
+ import type { trezorWallet } from "./trezor";
30
+ import type { walletconnectWallet } from "./walletconnect";
31
+
32
+ export type SKWallets = {
33
+ [WalletOption.BITGET]: typeof bitgetWallet;
34
+ [WalletOption.BRAVE]: typeof evmWallet;
35
+ [WalletOption.COINBASE_MOBILE]: typeof coinbaseWallet;
36
+ [WalletOption.COINBASE_WEB]: typeof evmWallet;
37
+ [WalletOption.CTRL]: typeof ctrlWallet;
38
+ [WalletOption.EIP6963]: typeof evmWallet;
39
+ [WalletOption.EXODUS]: typeof exodusWallet;
40
+ [WalletOption.KEEPKEY]: typeof keepkeyWallet;
41
+ [WalletOption.KEEPKEY_BEX]: typeof keepkeyBexWallet;
42
+ [WalletOption.KEPLR]: typeof keplrWallet;
43
+ [WalletOption.KEYSTORE]: typeof keystoreWallet;
44
+ [WalletOption.LEAP]: typeof keplrWallet;
45
+ [WalletOption.LEDGER]: typeof ledgerWallet;
46
+ [WalletOption.LEDGER_LIVE]: typeof ledgerWallet;
47
+ [WalletOption.METAMASK]: typeof evmWallet;
48
+ [WalletOption.OKX]: typeof okxWallet;
49
+ [WalletOption.OKX_MOBILE]: typeof evmWallet;
50
+ [WalletOption.ONEKEY]: typeof onekeyWallet;
51
+ [WalletOption.PHANTOM]: typeof phantomWallet;
52
+ [WalletOption.POLKADOT_JS]: typeof polkadotWallet;
53
+ [WalletOption.RADIX_WALLET]: typeof radixWallet;
54
+ [WalletOption.TALISMAN]: typeof talismanWallet;
55
+ [WalletOption.TREZOR]: typeof trezorWallet;
56
+ [WalletOption.TRUSTWALLET_WEB]: typeof evmWallet;
57
+ [WalletOption.WALLETCONNECT]: typeof walletconnectWallet;
58
+ };
59
+
60
+ export type SKConnectWallets = SKWallets[keyof SKWallets];
61
+
62
+ export type SKWalletsSupportedChains = {
63
+ [WalletOption.BITGET]: typeof bitgetWallet.connectBitget.supportedChains;
64
+ [WalletOption.BRAVE]: typeof evmWallet.connectEVMWallet.supportedChains;
65
+ [WalletOption.COINBASE_MOBILE]: typeof coinbaseWallet.connectCoinbaseWallet.supportedChains;
66
+ [WalletOption.COINBASE_WEB]: typeof evmWallet.connectEVMWallet.supportedChains;
67
+ [WalletOption.CTRL]: typeof ctrlWallet.connectCtrl.supportedChains;
68
+ [WalletOption.EIP6963]: typeof evmWallet.connectEVMWallet.supportedChains;
69
+ [WalletOption.EXODUS]: typeof exodusWallet.connectExodusWallet.supportedChains;
70
+ [WalletOption.KEEPKEY]: typeof keepkeyWallet.connectKeepkey.supportedChains;
71
+ [WalletOption.KEEPKEY_BEX]: typeof keepkeyBexWallet.connectKeepkeyBex.supportedChains;
72
+ [WalletOption.KEPLR]: typeof keplrWallet.connectKeplr.supportedChains;
73
+ [WalletOption.KEYSTORE]: typeof keystoreWallet.connectKeystore.supportedChains;
74
+ [WalletOption.LEAP]: typeof keplrWallet.connectKeplr.supportedChains;
75
+ [WalletOption.LEDGER]: typeof ledgerWallet.connectLedger.supportedChains;
76
+ [WalletOption.LEDGER_LIVE]: typeof ledgerWallet.connectLedger.supportedChains;
77
+ [WalletOption.METAMASK]: typeof evmWallet.connectEVMWallet.supportedChains;
78
+ [WalletOption.OKX]: typeof okxWallet.connectOkx.supportedChains;
79
+ [WalletOption.OKX_MOBILE]: typeof evmWallet.connectEVMWallet.supportedChains;
80
+ [WalletOption.ONEKEY]: typeof onekeyWallet.connectOnekeyWallet.supportedChains;
81
+ [WalletOption.PHANTOM]: typeof phantomWallet.connectPhantom.supportedChains;
82
+ [WalletOption.POLKADOT_JS]: typeof polkadotWallet.connectPolkadotJs.supportedChains;
83
+ [WalletOption.RADIX_WALLET]: typeof radixWallet.connectRadixWallet.supportedChains;
84
+ [WalletOption.TALISMAN]: typeof talismanWallet.connectTalisman.supportedChains;
85
+ [WalletOption.TREZOR]: typeof trezorWallet.connectTrezor.supportedChains;
86
+ [WalletOption.TRUSTWALLET_WEB]: typeof evmWallet.connectEVMWallet.supportedChains;
87
+ [WalletOption.WALLETCONNECT]: typeof walletconnectWallet.connectWalletconnect.supportedChains;
88
+ };
89
+
90
+ type UnisatToSignInputs = {
91
+ index: number;
92
+ sighashTypes?: number[];
93
+ disableTweakSigner?: boolean;
94
+ } & ({ address: string } | { publicKey: string });
95
+
96
+ declare global {
97
+ interface Window {
98
+ injectedWeb3?: SubstrateInjectedExtension;
99
+ talismanEth?: EthereumWindowProvider;
100
+ $onekey?: any;
101
+ braveSolana: any;
102
+ coinbaseWalletExtension: EthereumWindowProvider;
103
+ ethereum: EthereumWindowProvider;
104
+ keplr: Keplr;
105
+ leap: Keplr;
106
+ trustwallet: EthereumWindowProvider;
107
+ phantom: {
108
+ solana: SolanaProvider;
109
+ };
110
+
111
+ xfi?: {
112
+ binance: Eip1193Provider;
113
+ bitcoin: Eip1193Provider;
114
+ bitcoincash: Eip1193Provider;
115
+ dogecoin: Eip1193Provider;
116
+ ethereum: BrowserProvider;
117
+ keplr: Keplr;
118
+ litecoin: Eip1193Provider;
119
+ thorchain: Eip1193Provider;
120
+ mayachain: Eip1193Provider;
121
+ solana: SolanaProvider & { isXDEFI: boolean };
122
+ };
123
+
124
+ bitkeep?: {
125
+ unisat: {
126
+ requestAccounts: () => Promise<[string, ...string[]]>;
127
+ signMessage: (message: string, type?: "ecdsa" | "bip322-simple") => Promise<string>;
128
+ signPsbt: (
129
+ psbtHex: string,
130
+ {
131
+ autoFinalized,
132
+ toSignInputs,
133
+ }: { autoFinalized?: boolean; toSignInputs?: UnisatToSignInputs[] },
134
+ ) => Promise<string>;
135
+ };
136
+ keplr: {
137
+ enable: (chainId: string | string[]) => Promise<void>;
138
+ signAmino: (
139
+ chainId: string,
140
+ signer: string,
141
+ signDoc: StdSignDoc,
142
+ signOptions: any,
143
+ ) => Promise<AminoSignResponse>;
144
+ signArbitrary: (
145
+ chainId: string,
146
+ signer: string,
147
+ data: string | Uint8Array,
148
+ ) => Promise<StdSignature>;
149
+ verifyArbitrary: (
150
+ chainId: string,
151
+ signer: string,
152
+ data: string | Uint8Array,
153
+ signature: StdSignature,
154
+ ) => Promise<boolean>;
155
+ getOfflineSignerOnlyAmino: (chainId: string) => OfflineAminoSigner;
156
+ };
157
+ solana: SolanaProvider;
158
+ ethereum: EthereumWindowProvider;
159
+ };
160
+
161
+ okxwallet?:
162
+ | {
163
+ bitcoin: {
164
+ connect: () => Promise<{
165
+ address: string;
166
+ publicKey: string;
167
+ }>;
168
+ disconnect: () => Promise<void>;
169
+ signMessage: (message: string, { from }: { from: string }) => Promise<string>;
170
+ signPsbt: (
171
+ psbtHex: string,
172
+ { from, type }: { from: string; type: string },
173
+ ) => Promise<string>;
174
+ };
175
+ keplr: {
176
+ enable: (chainId: string | string[]) => Promise<void>;
177
+ signAmino: (
178
+ chainId: string,
179
+ signer: string,
180
+ signDoc: StdSignDoc,
181
+ signOptions: any,
182
+ ) => Promise<AminoSignResponse>;
183
+ signArbitrary: (
184
+ chainId: string,
185
+ signer: string,
186
+ data: string | Uint8Array,
187
+ ) => Promise<StdSignature>;
188
+ verifyArbitrary: (
189
+ chainId: string,
190
+ signer: string,
191
+ data: string | Uint8Array,
192
+ signature: StdSignature,
193
+ ) => Promise<boolean>;
194
+ getOfflineSignerOnlyAmino: (chainId: string) => OfflineAminoSigner;
195
+ };
196
+ }
197
+ | EthereumWindowProvider;
198
+ }
199
+ }
package/src/utils.ts ADDED
@@ -0,0 +1,54 @@
1
+ import { WalletOption, type createWallet } from "@swapkit/helpers";
2
+ import type { SKWallets } from "./types";
3
+
4
+ export function getWalletSupportedChains<
5
+ T extends ReturnType<typeof createWallet<any, any, any, any>>,
6
+ >(wallet: T): T[keyof T]["supportedChains"] {
7
+ const walletName = Object.keys(wallet)?.[0] || "";
8
+ return wallet?.[walletName]?.supportedChains || [];
9
+ }
10
+
11
+ export async function loadWallet<W extends WalletOption>(walletOption: W): Promise<SKWallets[W]> {
12
+ const { match } = await import("ts-pattern");
13
+
14
+ const wallet = await match(walletOption as WalletOption)
15
+ .with(WalletOption.COINBASE_MOBILE, async () => (await import("./coinbase")).coinbaseWallet)
16
+ .with(WalletOption.BITGET, async () => (await import("./bitget")).bitgetWallet)
17
+ .with(WalletOption.CTRL, async () => (await import("./ctrl")).ctrlWallet)
18
+ .with(WalletOption.OKX, async () => (await import("./okx")).okxWallet)
19
+ .with(WalletOption.ONEKEY, async () => (await import("./onekey")).onekeyWallet)
20
+ .with(WalletOption.EXODUS, async () => (await import("./exodus")).exodusWallet)
21
+ .with(WalletOption.KEEPKEY, async () => (await import("./keepkey")).keepkeyWallet)
22
+ .with(WalletOption.KEEPKEY_BEX, async () => (await import("./keepkey-bex")).keepkeyBexWallet)
23
+ .with(
24
+ WalletOption.WALLETCONNECT,
25
+ async () => (await import("./walletconnect")).walletconnectWallet,
26
+ )
27
+ .with(WalletOption.KEPLR, WalletOption.LEAP, async () => (await import("./keplr")).keplrWallet)
28
+ .with(
29
+ WalletOption.BRAVE,
30
+ WalletOption.COINBASE_WEB,
31
+ WalletOption.EIP6963,
32
+ WalletOption.METAMASK,
33
+ WalletOption.OKX_MOBILE,
34
+ WalletOption.TRUSTWALLET_WEB,
35
+ async () => (await import("./evm-extensions")).evmWallet,
36
+ )
37
+
38
+ .with(WalletOption.KEYSTORE, async () => (await import("./keystore")).keystoreWallet)
39
+ .with(WalletOption.TREZOR, async () => (await import("./trezor")).trezorWallet)
40
+ .with(
41
+ WalletOption.LEDGER,
42
+ // TODO: Remove
43
+ WalletOption.LEDGER_LIVE,
44
+ async () => (await import("./ledger")).ledgerWallet,
45
+ )
46
+
47
+ .with(WalletOption.PHANTOM, async () => (await import("./phantom")).phantomWallet)
48
+ .with(WalletOption.POLKADOT_JS, async () => (await import("./polkadotjs")).polkadotWallet)
49
+ .with(WalletOption.RADIX_WALLET, async () => (await import("./radix")).radixWallet)
50
+ .with(WalletOption.TALISMAN, async () => (await import("./talisman")).talismanWallet)
51
+ .exhaustive();
52
+
53
+ return wallet as SKWallets[W];
54
+ }
@@ -4,7 +4,7 @@ export const DEFAULT_RELAY_URL = "wss://relay.walletconnect.com";
4
4
 
5
5
  export const ETHEREUM_MAINNET_ID = "eip155:1";
6
6
  export const BSC_MAINNET_ID = "eip155:56";
7
- export const AVALACHE_MAINNET_ID = "eip155:43114";
7
+ export const AVALANCHE_MAINNET_ID = "eip155:43114";
8
8
  export const THORCHAIN_MAINNET_ID = "cosmos:thorchain";
9
9
  export const COSMOS_HUB_MAINNET_ID = "cosmos:cosmoshub-4";
10
10
  export const KUJIRA_MAINNET_ID = "cosmos:kaiyo-1";
@@ -2,7 +2,7 @@ import { Chain, type EVMChain } from "@swapkit/helpers";
2
2
 
3
3
  import {
4
4
  ARBITRUM_ONE_MAINNET_ID,
5
- AVALACHE_MAINNET_ID,
5
+ AVALANCHE_MAINNET_ID,
6
6
  BASE_MAINNET_ID,
7
7
  BSC_MAINNET_ID,
8
8
  COSMOS_HUB_MAINNET_ID,
@@ -27,7 +27,7 @@ export const getAddressByChain = (
27
27
  export const chainToChainId = (chain: Chain) => {
28
28
  switch (chain) {
29
29
  case Chain.Avalanche:
30
- return AVALACHE_MAINNET_ID;
30
+ return AVALANCHE_MAINNET_ID;
31
31
  case Chain.Base:
32
32
  return BASE_MAINNET_ID;
33
33
  case Chain.BinanceSmartChain: