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

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 (132) hide show
  1. package/dist/chunk-czhtd6cy.js +4 -0
  2. package/dist/chunk-czhtd6cy.js.map +10 -0
  3. package/dist/{chunk-5m175wfy.js → chunk-p1kdg37m.js} +2 -2
  4. package/dist/{chunk-5m175wfy.js.map → chunk-p1kdg37m.js.map} +1 -1
  5. package/dist/{chunk-f76hj57k.js → chunk-q81hzyra.js} +2 -2
  6. package/dist/{chunk-f76hj57k.js.map → chunk-q81hzyra.js.map} +1 -1
  7. package/dist/chunk-qadd75nn.js +3 -0
  8. package/dist/chunk-qadd75nn.js.map +10 -0
  9. package/dist/src/bitget/index.cjs +2 -2
  10. package/dist/src/bitget/index.cjs.map +5 -5
  11. package/dist/src/bitget/index.js +2 -2
  12. package/dist/src/bitget/index.js.map +5 -5
  13. package/dist/src/coinbase/index.cjs +2 -2
  14. package/dist/src/coinbase/index.cjs.map +4 -4
  15. package/dist/src/coinbase/index.js +2 -3
  16. package/dist/src/coinbase/index.js.map +4 -4
  17. package/dist/src/ctrl/index.cjs +2 -2
  18. package/dist/src/ctrl/index.cjs.map +5 -5
  19. package/dist/src/ctrl/index.js +2 -2
  20. package/dist/src/ctrl/index.js.map +5 -5
  21. package/dist/src/evm-extensions/index.cjs +2 -2
  22. package/dist/src/evm-extensions/index.cjs.map +3 -3
  23. package/dist/src/evm-extensions/index.js +2 -3
  24. package/dist/src/evm-extensions/index.js.map +3 -3
  25. package/dist/src/exodus/index.cjs +2 -2
  26. package/dist/src/exodus/index.cjs.map +3 -3
  27. package/dist/src/exodus/index.js +2 -3
  28. package/dist/src/exodus/index.js.map +3 -3
  29. package/dist/src/index.cjs +2 -2
  30. package/dist/src/index.cjs.map +3 -4
  31. package/dist/src/index.js +2 -2
  32. package/dist/src/index.js.map +3 -4
  33. package/dist/src/keepkey/index.cjs +2 -2
  34. package/dist/src/keepkey/index.cjs.map +7 -7
  35. package/dist/src/keepkey/index.js +2 -3
  36. package/dist/src/keepkey/index.js.map +7 -7
  37. package/dist/src/keepkey-bex/index.cjs +2 -2
  38. package/dist/src/keepkey-bex/index.cjs.map +4 -4
  39. package/dist/src/keepkey-bex/index.js +2 -3
  40. package/dist/src/keepkey-bex/index.js.map +4 -4
  41. package/dist/src/keplr/index.cjs +2 -2
  42. package/dist/src/keplr/index.cjs.map +3 -3
  43. package/dist/src/keplr/index.js +2 -3
  44. package/dist/src/keplr/index.js.map +3 -3
  45. package/dist/src/keystore/index.cjs +2 -2
  46. package/dist/src/keystore/index.cjs.map +4 -4
  47. package/dist/src/keystore/index.js +2 -3
  48. package/dist/src/keystore/index.js.map +4 -4
  49. package/dist/src/ledger/index.cjs +3 -3
  50. package/dist/src/ledger/index.cjs.map +8 -8
  51. package/dist/src/ledger/index.js +3 -4
  52. package/dist/src/ledger/index.js.map +8 -8
  53. package/dist/src/okx/index.cjs +2 -2
  54. package/dist/src/okx/index.cjs.map +4 -4
  55. package/dist/src/okx/index.js +2 -3
  56. package/dist/src/okx/index.js.map +4 -4
  57. package/dist/src/onekey/index.cjs +3 -0
  58. package/dist/src/onekey/index.cjs.map +10 -0
  59. package/dist/src/onekey/index.js +3 -0
  60. package/dist/src/onekey/index.js.map +10 -0
  61. package/dist/src/phantom/index.cjs +2 -2
  62. package/dist/src/phantom/index.cjs.map +3 -3
  63. package/dist/src/phantom/index.js +2 -3
  64. package/dist/src/phantom/index.js.map +3 -3
  65. package/dist/src/polkadotjs/index.cjs +2 -2
  66. package/dist/src/polkadotjs/index.cjs.map +3 -3
  67. package/dist/src/polkadotjs/index.js +2 -3
  68. package/dist/src/polkadotjs/index.js.map +3 -3
  69. package/dist/src/radix/index.cjs +2 -2
  70. package/dist/src/radix/index.cjs.map +3 -3
  71. package/dist/src/radix/index.js +2 -3
  72. package/dist/src/radix/index.js.map +3 -3
  73. package/dist/src/talisman/index.cjs +2 -2
  74. package/dist/src/talisman/index.cjs.map +3 -3
  75. package/dist/src/talisman/index.js +2 -3
  76. package/dist/src/talisman/index.js.map +3 -3
  77. package/dist/src/trezor/index.cjs +2 -2
  78. package/dist/src/trezor/index.cjs.map +3 -3
  79. package/dist/src/trezor/index.js +2 -3
  80. package/dist/src/trezor/index.js.map +3 -3
  81. package/dist/src/walletconnect/index.cjs +2 -2
  82. package/dist/src/walletconnect/index.cjs.map +5 -5
  83. package/dist/src/walletconnect/index.js +2 -3
  84. package/dist/src/walletconnect/index.js.map +5 -5
  85. package/package.json +31 -26
  86. package/src/bitget/helpers.ts +33 -93
  87. package/src/bitget/index.ts +32 -54
  88. package/src/coinbase/index.ts +2 -2
  89. package/src/coinbase/signer.ts +46 -42
  90. package/src/ctrl/index.ts +157 -22
  91. package/src/ctrl/walletHelpers.ts +45 -94
  92. package/src/evm-extensions/index.ts +21 -40
  93. package/src/exodus/index.ts +18 -28
  94. package/src/index.ts +2 -37
  95. package/src/keepkey/chains/cosmos.ts +10 -7
  96. package/src/keepkey/chains/mayachain.ts +24 -24
  97. package/src/keepkey/chains/thorchain.ts +19 -13
  98. package/src/keepkey/chains/utxo.ts +36 -48
  99. package/src/keepkey/index.ts +9 -23
  100. package/src/keepkey-bex/index.ts +25 -23
  101. package/src/keepkey-bex/walletHelpers.ts +8 -36
  102. package/src/keplr/index.ts +6 -53
  103. package/src/keystore/helpers.ts +34 -55
  104. package/src/keystore/index.ts +15 -183
  105. package/src/ledger/clients/evm.ts +3 -7
  106. package/src/ledger/clients/thorchain/lib.ts +0 -19
  107. package/src/ledger/clients/utxo.ts +3 -2
  108. package/src/ledger/helpers/getLedgerClient.ts +2 -2
  109. package/src/ledger/index.ts +20 -21
  110. package/src/ledger/types.ts +1 -1
  111. package/src/okx/helpers.ts +23 -33
  112. package/src/okx/index.ts +4 -47
  113. package/src/onekey/evmSigner.ts +133 -0
  114. package/src/onekey/index.ts +213 -0
  115. package/src/phantom/index.ts +18 -42
  116. package/src/polkadotjs/index.ts +5 -7
  117. package/src/radix/index.ts +31 -47
  118. package/src/talisman/index.ts +15 -32
  119. package/src/trezor/index.ts +46 -45
  120. package/src/types.ts +199 -0
  121. package/src/utils.ts +54 -0
  122. package/src/walletconnect/constants.ts +1 -1
  123. package/src/walletconnect/helpers.ts +2 -2
  124. package/src/walletconnect/index.ts +36 -37
  125. package/dist/chunk-ha78se5g.js +0 -4
  126. package/dist/chunk-ha78se5g.js.map +0 -10
  127. package/dist/chunk-yvbvzc0q.js +0 -3
  128. package/dist/chunk-yvbvzc0q.js.map +0 -10
  129. package/src/bitget/bitgetWallet.ts +0 -32
  130. package/src/ctrl/ctrlWallet.ts +0 -175
  131. package/src/helpers.ts +0 -8
  132. package/src/ledger/ledgerLive.ts +0 -429
@@ -5,13 +5,7 @@ import {
5
5
  NetworkDerivationPath,
6
6
  derivationPathToString,
7
7
  } from "@swapkit/helpers";
8
- import {
9
- AbstractSigner,
10
- type Provider,
11
- Signature,
12
- Transaction,
13
- type TransactionRequest,
14
- } from "ethers";
8
+ import { AbstractSigner, type Provider, type TransactionRequest } from "ethers";
15
9
 
16
10
  import { getLedgerTransport } from "../helpers/getLedgerTransport";
17
11
 
@@ -79,6 +73,7 @@ class EVMLedgerInterface extends AbstractSigner {
79
73
  };
80
74
 
81
75
  signMessage = async (messageHex: string) => {
76
+ const { Signature } = await import("ethers");
82
77
  await this.createTransportAndLedger();
83
78
 
84
79
  const sig = await this.ledgerApp?.signPersonalMessage(this.derivationPath, messageHex);
@@ -103,6 +98,7 @@ class EVMLedgerInterface extends AbstractSigner {
103
98
  }
104
99
 
105
100
  signTransaction = async (tx: TransactionRequest) => {
101
+ const { Transaction } = await import("ethers");
106
102
  await this.createTransportAndLedger();
107
103
 
108
104
  const transactionCount = await this.provider?.getTransactionCount(
@@ -1,4 +1,3 @@
1
- import crypto from "crypto";
2
1
  import type Transport from "@ledgerhq/hw-transport";
3
2
  /** ******************************************************************************
4
3
  * (c) 2019 ZondaX GmbH
@@ -16,8 +15,6 @@ import type Transport from "@ledgerhq/hw-transport";
16
15
  * See the License for the specific language governing permissions and
17
16
  * limitations under the License.
18
17
  ******************************************************************************* */
19
- import { bech32 } from "@scure/base";
20
- import Ripemd160 from "ripemd160";
21
18
 
22
19
  import {
23
20
  CHUNK_SIZE,
@@ -61,22 +58,6 @@ export class THORChainApp {
61
58
  return buf;
62
59
  }
63
60
 
64
- static getBech32FromPK(hrp: string, pk: Buffer) {
65
- if (pk.length !== 33) {
66
- throw new Error("expected compressed public key [31 bytes]");
67
- }
68
- // @ts-ignore
69
- const hashSha256 = crypto.createHash("sha256").update(pk).digest();
70
- // @ts-ignore
71
- const hashRip = new Ripemd160().update(hashSha256).digest();
72
- // @ts-ignore
73
- const encode = bech32.encode || bech32.bech32.encode;
74
- // @ts-ignore
75
- const toWords = bech32.toWords || bech32.bech32.toWords;
76
- // @ts-ignore
77
- return encode(hrp, toWords(hashRip));
78
- }
79
-
80
61
  async serializePath(path: number[]) {
81
62
  this.versionResponse = await getVersion(this.transport);
82
63
 
@@ -6,7 +6,8 @@ import {
6
6
  derivationPathToString,
7
7
  getWalletFormatFor,
8
8
  } from "@swapkit/helpers";
9
- import type { Psbt, UTXOType } from "@swapkit/toolboxes/utxo";
9
+ import type { UTXOType } from "@swapkit/toolboxes/utxo";
10
+ import type { Psbt } from "bitcoinjs-lib";
10
11
 
11
12
  import { getLedgerTransport } from "../helpers/getLedgerTransport";
12
13
 
@@ -21,7 +22,7 @@ const signUTXOTransaction = async (
21
22
  { psbt, inputUtxos, btcApp, derivationPath }: Params,
22
23
  options?: Partial<CreateTransactionArg>,
23
24
  ) => {
24
- const { Transaction } = await import("@swapkit/toolboxes/utxo");
25
+ const { Transaction } = await import("bitcoinjs-lib");
25
26
 
26
27
  const inputs = inputUtxos.map((item) => {
27
28
  const utxoTx = Transaction.fromHex(item.txHex || "");
@@ -10,7 +10,7 @@ import {
10
10
  OptimismLedger,
11
11
  PolygonLedger,
12
12
  } from "../clients/evm";
13
- import { THORChainLedger } from "../clients/thorchain/index";
13
+ import { THORChainLedger } from "../clients/thorchain";
14
14
  import {
15
15
  BitcoinCashLedger,
16
16
  BitcoinLedger,
@@ -69,7 +69,7 @@ export const getLedgerClient = async <T extends LedgerSupportedChain>({
69
69
  case Chain.Polygon:
70
70
  case Chain.Base: {
71
71
  const { getProvider } = await import("@swapkit/toolboxes/evm");
72
- const params = { provider: getProvider(chain), derivationPath };
72
+ const params = { provider: await getProvider(chain), derivationPath };
73
73
 
74
74
  switch (chain) {
75
75
  case Chain.BinanceSmartChain:
@@ -3,17 +3,18 @@ import {
3
3
  ChainId,
4
4
  type DerivationPathArray,
5
5
  FeeOption,
6
+ type GenericTransferParams,
6
7
  SKConfig,
7
8
  StagenetChain,
8
9
  WalletOption,
9
10
  createWallet,
10
11
  filterSupportedChains,
11
12
  } from "@swapkit/helpers";
12
- import type { DepositParam, TransferParams } from "@swapkit/toolboxes/cosmos";
13
+ import type { ThorchainDepositParams } from "@swapkit/toolboxes/cosmos";
13
14
  import type { UTXOBuildTxParams } from "@swapkit/toolboxes/utxo";
14
15
 
15
- import { getWalletSupportedChains } from "../helpers";
16
- import { getLedgerAddress, getLedgerClient } from "./helpers/index";
16
+ import { getWalletSupportedChains } from "../utils";
17
+ import { getLedgerAddress, getLedgerClient } from "./helpers";
17
18
 
18
19
  export const ledgerWallet = createWallet({
19
20
  name: "connectLedger",
@@ -42,7 +43,7 @@ export const ledgerWallet = createWallet({
42
43
 
43
44
  const walletMethods = await getWalletMethods({ chain, derivationPath });
44
45
 
45
- addChain({ ...walletMethods, chain, balance: [], walletType: WalletOption.LEDGER });
46
+ addChain({ ...walletMethods, chain, walletType: WalletOption.LEDGER });
46
47
 
47
48
  return true;
48
49
  },
@@ -97,9 +98,8 @@ async function getWalletMethods({
97
98
  case Chain.Dash:
98
99
  case Chain.Dogecoin:
99
100
  case Chain.Litecoin: {
100
- const { getToolboxByChain } = await import("@swapkit/toolboxes/utxo");
101
-
102
- const toolbox = getToolboxByChain(chain)();
101
+ const { getUtxoToolbox } = await import("@swapkit/toolboxes/utxo");
102
+ const toolbox = await getUtxoToolbox(chain as Chain.Bitcoin);
103
103
 
104
104
  const signer = await getLedgerClient({ chain, derivationPath });
105
105
  const address = await getLedgerAddress({ chain, ledgerClient: signer });
@@ -108,12 +108,12 @@ async function getWalletMethods({
108
108
  const feeRate = params.feeRate || (await toolbox.getFeeRates())[FeeOption.Average];
109
109
  const memo = [Chain.Bitcoin].includes(chain) ? params.memo : reduceMemo(params.memo);
110
110
 
111
- const { psbt, inputs } = await toolbox.buildTx({
111
+ const { psbt, inputs } = await toolbox.createTransaction({
112
112
  ...params,
113
113
  feeRate,
114
- fetchTxHex: true,
115
114
  memo,
116
115
  sender: address,
116
+ fetchTxHex: true,
117
117
  });
118
118
  const txHex = await signer.signTransaction(psbt, inputs);
119
119
  const tx = await toolbox.broadcastTx(txHex);
@@ -131,24 +131,23 @@ async function getWalletMethods({
131
131
  case Chain.Polygon:
132
132
  case Chain.BinanceSmartChain:
133
133
  case Chain.Base: {
134
- const { getToolboxByChain, getProvider } = await import("@swapkit/toolboxes/evm");
134
+ const { getEvmToolbox } = await import("@swapkit/toolboxes/evm");
135
135
  const signer = await getLedgerClient({ chain, derivationPath });
136
136
  const address = await getLedgerAddress({ chain, ledgerClient: signer });
137
- const provider = getProvider(chain);
138
- const toolbox = getToolboxByChain(chain)({ signer, provider });
137
+ const toolbox = await getEvmToolbox(chain, { signer });
139
138
 
140
139
  return { ...toolbox, address };
141
140
  }
142
141
 
143
142
  case Chain.Cosmos: {
144
- const { createSigningStargateClient, getMsgSendDenom, GaiaToolbox } = await import(
143
+ const { createSigningStargateClient, getMsgSendDenom, getCosmosToolbox } = await import(
145
144
  "@swapkit/toolboxes/cosmos"
146
145
  );
147
- const toolbox = GaiaToolbox();
146
+ const toolbox = await getCosmosToolbox(Chain.Cosmos);
148
147
  const signer = await getLedgerClient({ chain, derivationPath });
149
148
  const address = await getLedgerAddress({ chain, ledgerClient: signer });
150
149
 
151
- const transfer = async ({ assetValue, recipient, memo }: TransferParams) => {
150
+ const transfer = async ({ assetValue, recipient, memo }: GenericTransferParams) => {
152
151
  if (!assetValue) throw new Error("invalid asset");
153
152
 
154
153
  const sendCoinsMessage = {
@@ -188,13 +187,13 @@ async function getWalletMethods({
188
187
  const {
189
188
  createStargateClient,
190
189
  buildEncodedTxBody,
191
- ThorchainToolbox,
190
+ getCosmosToolbox,
192
191
  buildAminoMsg,
193
192
  getDefaultChainFee,
194
193
  fromBase64,
195
194
  parseAminoMessageForDirectSigning,
196
195
  } = await import("@swapkit/toolboxes/cosmos");
197
- const toolbox = ThorchainToolbox();
196
+ const toolbox = await getCosmosToolbox(chain);
198
197
  const signer = await getLedgerClient({ chain, derivationPath });
199
198
  const address = await getLedgerAddress({ chain, ledgerClient: signer });
200
199
 
@@ -207,7 +206,7 @@ async function getWalletMethods({
207
206
  assetValue,
208
207
  ...rest
209
208
  // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: Refactor to reduce complexity
210
- }: TransferParams | DepositParam) => {
209
+ }: GenericTransferParams | ThorchainDepositParams) => {
211
210
  const account = await toolbox.getAccount(address);
212
211
  if (!account) throw new Error("invalid account");
213
212
  if (!assetValue) throw new Error("invalid asset");
@@ -217,7 +216,7 @@ async function getWalletMethods({
217
216
  const sequence = (sequenceNumber || 0).toString();
218
217
 
219
218
  const orderedMessages = recursivelyOrderKeys([
220
- buildAminoMsg({ chain, from: address, assetValue, memo, ...rest }),
219
+ buildAminoMsg({ sender: address, assetValue, memo, ...rest }),
221
220
  ]);
222
221
 
223
222
  // get tx signing msg
@@ -262,8 +261,8 @@ async function getWalletMethods({
262
261
  return transactionHash;
263
262
  };
264
263
 
265
- const transfer = (params: TransferParams) => thorchainTransfer(params);
266
- const deposit = (params: DepositParam) => thorchainTransfer(params);
264
+ const transfer = (params: GenericTransferParams) => thorchainTransfer(params);
265
+ const deposit = (params: ThorchainDepositParams) => thorchainTransfer(params);
267
266
 
268
267
  return { ...toolbox, address, deposit, transfer, signMessage };
269
268
  }
@@ -8,7 +8,7 @@ import type {
8
8
  OptimismLedger,
9
9
  PolygonLedger,
10
10
  } from "./clients/evm";
11
- import type { THORChainLedger } from "./clients/thorchain/index";
11
+ import type { THORChainLedger } from "./clients/thorchain";
12
12
  import type {
13
13
  BitcoinCashLedger,
14
14
  BitcoinLedger,
@@ -6,8 +6,6 @@ import {
6
6
  prepareNetworkSwitch,
7
7
  switchEVMWalletNetwork,
8
8
  } from "@swapkit/helpers";
9
- import type { GaiaToolbox } from "@swapkit/toolboxes/cosmos";
10
- import type { BTCToolbox, Psbt, UTXOTransferParams } from "@swapkit/toolboxes/utxo";
11
9
  import type { Eip1193Provider } from "ethers";
12
10
 
13
11
  const cosmosTransfer =
@@ -24,7 +22,10 @@ const cosmosTransfer =
24
22
  const cosmJS = await createSigningStargateClient(SKConfig.get("rpcUrls").GAIA, offlineSigner);
25
23
 
26
24
  const coins = [
27
- { denom: asset?.symbol === "MUON" ? "umuon" : "uatom", amount: amount.amount().toString() },
25
+ {
26
+ denom: asset?.symbol === "MUON" ? "umuon" : "uatom",
27
+ amount: amount.amount().toString(),
28
+ },
28
29
  ];
29
30
 
30
31
  const { transactionHash } = await cosmJS.sendTokens(from, recipient, coins, 1.6, memo);
@@ -35,14 +36,13 @@ async function getWeb3WalletMethods({
35
36
  walletProvider,
36
37
  chain,
37
38
  }: { walletProvider: Eip1193Provider | undefined; chain: EVMChain }) {
38
- const { getToolboxByChain } = await import("@swapkit/toolboxes/evm");
39
+ const { getEvmToolbox } = await import("@swapkit/toolboxes/evm");
39
40
  const { BrowserProvider } = await import("ethers");
40
41
  if (!walletProvider) throw new Error("Requested web3 wallet is not installed");
41
42
 
42
43
  const provider = new BrowserProvider(walletProvider, "any");
43
44
  const signer = await provider.getSigner();
44
-
45
- const toolbox = getToolboxByChain(chain)({ provider, signer });
45
+ const toolbox = await getEvmToolbox(chain, { provider, signer });
46
46
 
47
47
  try {
48
48
  if (chain !== Chain.Ethereum && "getNetworkParams" in toolbox) {
@@ -55,15 +55,7 @@ async function getWeb3WalletMethods({
55
55
  return prepareNetworkSwitch({ toolbox, provider, chain });
56
56
  }
57
57
 
58
- export async function getWalletMethods(
59
- chain: Chain,
60
- ): Promise<
61
- (
62
- | ReturnType<typeof GaiaToolbox>
63
- | Awaited<ReturnType<typeof getWeb3WalletMethods>>
64
- | ReturnType<typeof BTCToolbox>
65
- ) & { address: string }
66
- > {
58
+ export async function getWalletMethods(chain: Chain) {
67
59
  switch (chain) {
68
60
  case Chain.Ethereum:
69
61
  case Chain.Base:
@@ -76,42 +68,40 @@ export async function getWalletMethods(
76
68
  throw new Error("No okxwallet found");
77
69
  }
78
70
 
79
- const { getProvider } = await import("@swapkit/toolboxes/evm");
80
-
81
71
  const evmWallet = await getWeb3WalletMethods({
82
72
  chain,
83
73
  walletProvider: window.okxwallet,
84
74
  });
85
-
86
75
  const address: string = (await window.okxwallet.send("eth_requestAccounts", [])).result[0];
87
76
 
88
- const getBalance = async (addressOverwrite?: string, potentialScamFilter = true) =>
89
- evmWallet.getBalance(addressOverwrite || address, potentialScamFilter, getProvider(chain));
90
-
91
- return { ...evmWallet, getBalance, address };
77
+ return { ...evmWallet, address };
92
78
  }
93
79
 
94
80
  case Chain.Bitcoin: {
95
81
  if (!(window.okxwallet && "bitcoin" in window.okxwallet)) {
96
82
  throw new Error("No bitcoin okxwallet found");
97
83
  }
98
- const { Psbt, BTCToolbox } = await import("@swapkit/toolboxes/utxo");
84
+ const { Psbt } = await import("bitcoinjs-lib");
85
+ const { getUtxoToolbox } = await import("@swapkit/toolboxes/utxo");
99
86
 
100
87
  const { bitcoin: wallet } = window.okxwallet;
101
88
  const address = (await wallet.connect()).address;
102
- const toolbox = BTCToolbox();
103
89
 
104
- const signTransaction = async (psbt: Psbt) => {
105
- const signedPsbt = await wallet.signPsbt(psbt.toHex(), { from: address, type: "list" });
90
+ const signer = {
91
+ signTransaction: async (psbt: InstanceType<typeof Psbt>) => {
92
+ const signedPsbt = await wallet.signPsbt(psbt.toHex(), {
93
+ from: address,
94
+ type: "list",
95
+ });
106
96
 
107
- return Psbt.fromHex(signedPsbt);
97
+ return Psbt.fromHex(signedPsbt);
98
+ },
99
+ getAddress: async () => Promise.resolve(address),
108
100
  };
109
101
 
110
- const transfer = (transferParams: UTXOTransferParams) => {
111
- return toolbox.transfer({ ...transferParams, signTransaction });
112
- };
102
+ const toolbox = await getUtxoToolbox(chain, { signer });
113
103
 
114
- return { ...toolbox, transfer, address };
104
+ return { ...toolbox, address };
115
105
  }
116
106
 
117
107
  case Chain.Cosmos: {
@@ -124,9 +114,9 @@ export async function getWalletMethods(
124
114
  const accounts = await wallet.getOfflineSignerOnlyAmino(ChainId.Cosmos).getAccounts();
125
115
  if (!accounts?.[0]) throw new Error("No cosmos account found");
126
116
 
127
- const { GaiaToolbox } = await import("@swapkit/toolboxes/cosmos");
117
+ const { getCosmosToolbox } = await import("@swapkit/toolboxes/cosmos");
128
118
  const [{ address }] = accounts;
129
- const toolbox = GaiaToolbox();
119
+ const toolbox = getCosmosToolbox(Chain.Cosmos);
130
120
 
131
121
  return { ...toolbox, address, transfer: cosmosTransfer() };
132
122
  }
package/src/okx/index.ts CHANGED
@@ -1,10 +1,7 @@
1
- import type { StdSignDoc, StdSignature } from "@cosmjs/amino";
2
- import type { EthereumWindowProvider } from "@swapkit/helpers";
3
1
  import { Chain, WalletOption, createWallet, filterSupportedChains } from "@swapkit/helpers";
4
2
 
5
- import { getWalletSupportedChains } from "../helpers";
3
+ import { getWalletSupportedChains } from "../utils";
6
4
  import { getWalletMethods } from "./helpers";
7
- import type { AminoSignResponse, OfflineAminoSigner } from "./types";
8
5
 
9
6
  export const okxWallet = createWallet({
10
7
  name: "connectOkx",
@@ -28,7 +25,9 @@ export const okxWallet = createWallet({
28
25
  filteredChains.map(async (chain) => {
29
26
  const walletMethods = await getWalletMethods(chain);
30
27
 
31
- addChain({ ...walletMethods, chain, balance: [], walletType });
28
+ const address = (await walletMethods.getAddress()) || "";
29
+
30
+ addChain({ ...walletMethods, address, chain, walletType });
32
31
  }),
33
32
  );
34
33
 
@@ -37,45 +36,3 @@ export const okxWallet = createWallet({
37
36
  });
38
37
 
39
38
  export const OKX_SUPPORTED_CHAINS = getWalletSupportedChains(okxWallet);
40
-
41
- declare global {
42
- interface Window {
43
- okxwallet?:
44
- | {
45
- bitcoin: {
46
- connect: () => Promise<{
47
- address: string;
48
- publicKey: string;
49
- }>;
50
- disconnect: () => Promise<void>;
51
- signMessage: (message: string, { from }: { from: string }) => Promise<string>;
52
- signPsbt: (
53
- psbtHex: string,
54
- { from, type }: { from: string; type: string },
55
- ) => Promise<string>;
56
- };
57
- keplr: {
58
- enable: (chainId: string | string[]) => Promise<void>;
59
- signAmino: (
60
- chainId: string,
61
- signer: string,
62
- signDoc: StdSignDoc,
63
- signOptions: any,
64
- ) => Promise<AminoSignResponse>;
65
- signArbitrary: (
66
- chainId: string,
67
- signer: string,
68
- data: string | Uint8Array,
69
- ) => Promise<StdSignature>;
70
- verifyArbitrary: (
71
- chainId: string,
72
- signer: string,
73
- data: string | Uint8Array,
74
- signature: StdSignature,
75
- ) => Promise<boolean>;
76
- getOfflineSignerOnlyAmino: (chainId: string) => OfflineAminoSigner;
77
- };
78
- }
79
- | EthereumWindowProvider;
80
- }
81
- }
@@ -0,0 +1,133 @@
1
+ import type { Chain, DerivationPathArray } from "@swapkit/helpers";
2
+ import { SwapKitError, WalletOption } from "@swapkit/helpers";
3
+ import type { JsonRpcProvider, Provider, Signer, TypedDataDomain, TypedDataField } from "ethers";
4
+
5
+ type OneKeyEVMSignerParams = {
6
+ chain: Chain;
7
+ derivationPath: DerivationPathArray;
8
+ provider: Provider | JsonRpcProvider;
9
+ };
10
+
11
+ export async function getEVMSigner({ chain, derivationPath, provider }: OneKeyEVMSignerParams) {
12
+ const { AbstractSigner, BrowserProvider } = await import("ethers");
13
+
14
+ class OneKeySigner extends AbstractSigner {
15
+ address: string;
16
+ chain: Chain;
17
+ derivationPath: DerivationPathArray;
18
+ readonly provider: Provider | JsonRpcProvider;
19
+
20
+ constructor({ chain, derivationPath, provider }: OneKeyEVMSignerParams) {
21
+ super(provider);
22
+
23
+ this.address = "";
24
+ this.chain = chain;
25
+ this.derivationPath = derivationPath;
26
+ this.provider = provider;
27
+ }
28
+
29
+ connect(provider: null | Provider): Signer {
30
+ if (!provider) {
31
+ throw new SwapKitError({
32
+ errorKey: "wallet_provider_not_found",
33
+ info: { wallet: WalletOption.ONEKEY, chain: this.chain },
34
+ });
35
+ }
36
+
37
+ return new OneKeySigner({
38
+ chain: this.chain,
39
+ derivationPath: this.derivationPath,
40
+ provider,
41
+ });
42
+ }
43
+
44
+ signTypedData(
45
+ domain: TypedDataDomain,
46
+ types: Record<string, TypedDataField[]>,
47
+ value: Record<string, any>,
48
+ ): Promise<string> {
49
+ if (!window.$onekey?.ethereum) {
50
+ throw new SwapKitError({
51
+ errorKey: "wallet_onekey_not_found",
52
+ info: { chain: this.chain },
53
+ });
54
+ }
55
+
56
+ return this.getAddress().then(async (_address) => {
57
+ try {
58
+ const signer = await new BrowserProvider(window.$onekey.ethereum).getSigner();
59
+ return signer.signTypedData(domain, types, value);
60
+ } catch (error) {
61
+ throw new SwapKitError({
62
+ errorKey: "core_wallet_sign_message_not_supported",
63
+ info: { wallet: WalletOption.ONEKEY, error },
64
+ });
65
+ }
66
+ });
67
+ }
68
+
69
+ getAddress = async () => {
70
+ if (this.address) return this.address;
71
+
72
+ if (!window.$onekey?.ethereum) {
73
+ throw new SwapKitError({
74
+ errorKey: "wallet_onekey_not_found",
75
+ info: { chain: this.chain },
76
+ });
77
+ }
78
+
79
+ const signer = await new BrowserProvider(window.$onekey.ethereum).getSigner();
80
+ this.address = await signer.getAddress();
81
+ return this.address;
82
+ };
83
+
84
+ signMessage = async (message: string) => {
85
+ if (!window.$onekey?.ethereum) {
86
+ throw new SwapKitError({
87
+ errorKey: "wallet_onekey_not_found",
88
+ info: { chain: this.chain },
89
+ });
90
+ }
91
+
92
+ const signer = await new BrowserProvider(window.$onekey.ethereum).getSigner();
93
+ return signer.signMessage(message);
94
+ };
95
+
96
+ signTransaction = async (transaction: any) => {
97
+ if (!window.$onekey?.ethereum) {
98
+ throw new SwapKitError({
99
+ errorKey: "wallet_onekey_not_found",
100
+ info: { chain: this.chain },
101
+ });
102
+ }
103
+
104
+ const signer = await new BrowserProvider(window.$onekey.ethereum).getSigner();
105
+ const { to, value, gasLimit, gasPrice, data, maxFeePerGas, maxPriorityFeePerGas } =
106
+ transaction;
107
+
108
+ if (!to) throw new SwapKitError("toolbox_evm_no_to_address");
109
+ if (!gasLimit) throw new SwapKitError("toolbox_evm_no_gas_price");
110
+
111
+ const tx: any = {
112
+ to,
113
+ data,
114
+ gasLimit,
115
+ };
116
+
117
+ if (value) {
118
+ tx.value = value;
119
+ }
120
+
121
+ if (maxFeePerGas && maxPriorityFeePerGas) {
122
+ tx.maxFeePerGas = maxFeePerGas;
123
+ tx.maxPriorityFeePerGas = maxPriorityFeePerGas;
124
+ } else if (gasPrice) {
125
+ tx.gasPrice = gasPrice;
126
+ }
127
+
128
+ return signer.signTransaction(tx);
129
+ };
130
+ }
131
+
132
+ return new OneKeySigner({ chain, derivationPath, provider });
133
+ }