@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
@@ -9,9 +9,7 @@ import {
9
9
  prepareNetworkSwitch,
10
10
  switchEVMWalletNetwork,
11
11
  } from "@swapkit/helpers";
12
- import type { NonETHToolbox } from "@swapkit/toolboxes/evm";
13
- import type { UTXOTransferParams } from "@swapkit/toolboxes/utxo";
14
- import type { Psbt } from "@swapkit/toolboxes/utxo";
12
+ import type { Psbt } from "bitcoinjs-lib";
15
13
  import type { BrowserProvider, Eip1193Provider } from "ethers";
16
14
  import {
17
15
  AddressPurpose,
@@ -23,9 +21,9 @@ import {
23
21
  getAddress,
24
22
  signTransaction as satsSignTransaction,
25
23
  } from "sats-connect";
26
- import { getWalletSupportedChains } from "../helpers";
24
+ import { getWalletSupportedChains } from "../utils";
27
25
 
28
- export const getWalletMethods = async ({
26
+ async function getWalletMethods({
29
27
  walletProvider,
30
28
  provider,
31
29
  chain,
@@ -33,11 +31,11 @@ export const getWalletMethods = async ({
33
31
  walletProvider?: Eip1193Provider;
34
32
  provider: BrowserProvider | BitcoinProvider;
35
33
  chain: Chain;
36
- }) => {
34
+ }) {
37
35
  switch (chain) {
38
36
  case Chain.Bitcoin: {
39
- const { BTCToolbox, Psbt } = await import("@swapkit/toolboxes/utxo");
40
- const toolbox = BTCToolbox();
37
+ const { Psbt } = await import("bitcoinjs-lib");
38
+ const { getUtxoToolbox } = await import("@swapkit/toolboxes/utxo");
41
39
 
42
40
  let address = "";
43
41
 
@@ -60,6 +58,7 @@ export const getWalletMethods = async ({
60
58
  },
61
59
  };
62
60
 
61
+ // TODO: Towan - probably not needed ?
63
62
  await getAddress(getAddressOptions);
64
63
 
65
64
  async function signTransaction(psbt: Psbt) {
@@ -90,14 +89,13 @@ export const getWalletMethods = async ({
90
89
  return signedPsbt;
91
90
  }
92
91
 
93
- const transfer = (transferParams: UTXOTransferParams) => {
94
- return toolbox.transfer({
95
- ...transferParams,
96
- signTransaction,
97
- });
92
+ const signer = {
93
+ signTransaction,
94
+ getAddress: () => Promise.resolve(address),
98
95
  };
96
+ const toolbox = await getUtxoToolbox(chain, { signer });
99
97
 
100
- return { ...toolbox, transfer, address };
98
+ return { ...toolbox, address };
101
99
  }
102
100
  case Chain.Arbitrum:
103
101
  case Chain.Avalanche:
@@ -107,35 +105,32 @@ export const getWalletMethods = async ({
107
105
  case Chain.Optimism:
108
106
  case Chain.Polygon: {
109
107
  if (!walletProvider) throw new Error("Requested web3 wallet is not installed");
110
- const { getProvider, getToolboxByChain } = await import("@swapkit/toolboxes/evm");
108
+ const { getProvider, getEvmToolbox } = await import("@swapkit/toolboxes/evm");
111
109
 
112
- const jsonRpcProvider = getProvider(chain);
110
+ const jsonRpcProvider = await getProvider(chain);
113
111
  const browserProvider = provider as BrowserProvider;
114
112
 
115
113
  await browserProvider.send("eth_requestAccounts", []);
116
114
 
117
115
  const signer = await browserProvider.getSigner();
118
116
  const address = await signer.getAddress();
119
- const toolbox = getToolboxByChain(chain)({ provider: jsonRpcProvider, signer });
117
+ const toolbox = await getEvmToolbox(chain, { provider: jsonRpcProvider, signer });
120
118
 
121
119
  try {
122
120
  if (chain !== Chain.Ethereum) {
123
- const networkParams = (toolbox as NonETHToolbox).getNetworkParams();
121
+ const networkParams = toolbox.getNetworkParams();
124
122
  await switchEVMWalletNetwork(browserProvider, chain, networkParams);
125
123
  }
126
124
  } catch (_error) {
127
125
  throw new Error(`Failed to add/switch ${chain} network: ${chain}`);
128
126
  }
129
127
 
130
- return {
131
- address,
132
- ...prepareNetworkSwitch<typeof toolbox>({ toolbox, chain, provider: browserProvider }),
133
- };
128
+ return { ...prepareNetworkSwitch({ toolbox, chain, provider: browserProvider }), address };
134
129
  }
135
130
  default:
136
131
  throw new Error(`Unsupported chain: ${chain}`);
137
132
  }
138
- };
133
+ }
139
134
 
140
135
  export const exodusWallet = createWallet({
141
136
  name: "connectExodusWallet",
@@ -162,9 +157,6 @@ export const exodusWallet = createWallet({
162
157
  walletProvider: providers.ethereum,
163
158
  });
164
159
 
165
- const getBalance = async (potentialScamFilter = true) =>
166
- walletMethods.getBalance(address, potentialScamFilter);
167
-
168
160
  const disconnect = () =>
169
161
  provider.send("wallet_revokePermissions", [{ eth_accounts: {} }]);
170
162
 
@@ -173,8 +165,6 @@ export const exodusWallet = createWallet({
173
165
  disconnect,
174
166
  chain,
175
167
  address,
176
- getBalance,
177
- balance: [],
178
168
  walletType: WalletOption.EXODUS,
179
169
  });
180
170
  }),
package/src/index.ts CHANGED
@@ -1,37 +1,2 @@
1
- import { bitgetWallet } from "./bitget";
2
- import { coinbaseWallet } from "./coinbase";
3
- import { ctrlWallet } from "./ctrl";
4
- import { evmWallet } from "./evm-extensions";
5
- import { exodusWallet } from "./exodus";
6
- import { keepkeyWallet } from "./keepkey";
7
- import { keepkeyBexWallet } from "./keepkey-bex";
8
- import { keplrWallet } from "./keplr";
9
- import { keystoreWallet } from "./keystore";
10
- import { ledgerWallet } from "./ledger";
11
- import { okxWallet } from "./okx";
12
- import { phantomWallet } from "./phantom";
13
- import { polkadotWallet } from "./polkadotjs";
14
- import { radixWallet } from "./radix";
15
- import { talismanWallet } from "./talisman";
16
- import { trezorWallet } from "./trezor";
17
- import { walletconnectWallet } from "./walletconnect";
18
-
19
- export const wallets = {
20
- ...bitgetWallet,
21
- ...coinbaseWallet,
22
- ...ctrlWallet,
23
- ...evmWallet,
24
- ...exodusWallet,
25
- ...keepkeyWallet,
26
- ...keepkeyBexWallet,
27
- ...keplrWallet,
28
- ...keystoreWallet,
29
- ...ledgerWallet,
30
- ...okxWallet,
31
- ...phantomWallet,
32
- ...polkadotWallet,
33
- ...radixWallet,
34
- ...talismanWallet,
35
- ...trezorWallet,
36
- ...walletconnectWallet,
37
- };
1
+ export * from "./utils";
2
+ export * from "./types";
@@ -7,7 +7,7 @@ import {
7
7
  SKConfig,
8
8
  derivationPathToString,
9
9
  } from "@swapkit/helpers";
10
- import type { TransferParams } from "@swapkit/toolboxes/cosmos";
10
+ import type { GenericTransferParams } from "@swapkit/helpers";
11
11
 
12
12
  import { bip32ToAddressNList } from "../coins";
13
13
 
@@ -15,9 +15,12 @@ export const cosmosWalletMethods = async ({
15
15
  sdk,
16
16
  derivationPath,
17
17
  }: { sdk: KeepKeySdk; derivationPath?: DerivationPathArray }) => {
18
- const { DEFAULT_COSMOS_FEE_MAINNET, GaiaToolbox, createStargateClient } = await import(
19
- "@swapkit/toolboxes/cosmos"
20
- );
18
+ const {
19
+ DEFAULT_COSMOS_FEE_MAINNET,
20
+ getCosmosToolbox,
21
+ getFeeRateFromThorswap,
22
+ createStargateClient,
23
+ } = await import("@swapkit/toolboxes/cosmos");
21
24
 
22
25
  try {
23
26
  const derivationPathString = derivationPath
@@ -28,16 +31,16 @@ export const cosmosWalletMethods = async ({
28
31
  address_n: bip32ToAddressNList(derivationPathString),
29
32
  })) as { address: string };
30
33
 
31
- const toolbox = GaiaToolbox();
34
+ const toolbox = await getCosmosToolbox(Chain.Cosmos);
32
35
 
33
36
  if (DEFAULT_COSMOS_FEE_MAINNET.amount[0]) {
34
37
  DEFAULT_COSMOS_FEE_MAINNET.amount[0].amount = String(
35
- await toolbox?.getFeeRateFromThorswap?.(ChainId.Cosmos, 500),
38
+ await getFeeRateFromThorswap(ChainId.Cosmos, 500),
36
39
  );
37
40
  }
38
41
 
39
42
  // TODO support other cosmos assets
40
- const transfer = async ({ assetValue, recipient, memo }: TransferParams) => {
43
+ const transfer = async ({ assetValue, recipient, memo }: GenericTransferParams) => {
41
44
  const amount = assetValue.getBaseValue("string");
42
45
  const accountInfo = await toolbox.getAccount(fromAddress);
43
46
 
@@ -5,17 +5,18 @@ import {
5
5
  ChainId,
6
6
  DerivationPath,
7
7
  type DerivationPathArray,
8
+ type GenericTransferParams,
8
9
  SKConfig,
9
10
  derivationPathToString,
10
11
  } from "@swapkit/helpers";
11
- import type { DepositParam, TransferParams } from "@swapkit/toolboxes/cosmos";
12
+ import type { ThorchainDepositParams } from "@swapkit/toolboxes/cosmos";
12
13
 
13
14
  import { bip32ToAddressNList } from "../coins";
14
15
 
15
16
  type SignTransactionParams = {
16
17
  assetValue: AssetValue;
17
18
  recipient?: string;
18
- from: string;
19
+ sender: string;
19
20
  memo: string | undefined;
20
21
  };
21
22
 
@@ -26,9 +27,9 @@ export const mayachainWalletMethods = async ({
26
27
  sdk: KeepKeySdk;
27
28
  derivationPath?: DerivationPathArray;
28
29
  }) => {
29
- const { createStargateClient, getToolboxByChain } = await import("@swapkit/toolboxes/cosmos");
30
+ const { createStargateClient, getCosmosToolbox } = await import("@swapkit/toolboxes/cosmos");
30
31
 
31
- const toolbox = getToolboxByChain(Chain.Maya)();
32
+ const toolbox = await getCosmosToolbox(Chain.Maya);
32
33
  const derivationPathString = derivationPath
33
34
  ? derivationPathToString(derivationPath)
34
35
  : `${DerivationPath.MAYA}/0`;
@@ -37,11 +38,16 @@ export const mayachainWalletMethods = async ({
37
38
  address_n: bip32ToAddressNList(derivationPathString),
38
39
  })) as { address: string };
39
40
 
40
- const signTransaction = async ({ assetValue, recipient, from, memo }: SignTransactionParams) => {
41
+ const signTransaction = async ({
42
+ assetValue,
43
+ recipient,
44
+ sender,
45
+ memo,
46
+ }: SignTransactionParams) => {
41
47
  const { makeSignDoc } = await import("@cosmjs/amino");
42
48
  const { getDenomWithChain } = await import("@swapkit/toolboxes/cosmos");
43
49
 
44
- const account = await toolbox.getAccount(from);
50
+ const account = await toolbox.getAccount(sender);
45
51
  if (!account) throw new Error("Account not found");
46
52
  const { accountNumber, sequence = 0 } = account;
47
53
  const amount = assetValue.getBaseValue("string");
@@ -54,7 +60,7 @@ export const mayachainWalletMethods = async ({
54
60
  type: "mayachain/MsgSend",
55
61
  value: {
56
62
  amount: [{ amount, denom: assetValue.symbol.toLowerCase() }],
57
- from_address: from,
63
+ from_address: sender,
58
64
  to_address: recipient,
59
65
  },
60
66
  }
@@ -63,7 +69,7 @@ export const mayachainWalletMethods = async ({
63
69
  value: {
64
70
  coins: [{ amount, asset: getDenomWithChain(assetValue) }],
65
71
  memo,
66
- signer: from,
72
+ signer: sender,
67
73
  },
68
74
  };
69
75
 
@@ -76,41 +82,35 @@ export const mayachainWalletMethods = async ({
76
82
  sequence,
77
83
  );
78
84
 
79
- const signedTx = isTransfer
80
- ? await sdk.mayachain.mayachainSignAminoTransfer({
81
- // TODO can we ignore this ?
82
- // @ts-expect-error readonly cant be assigned to writable
83
- signDoc,
84
- signerAddress: from,
85
- })
86
- : await sdk.mayachain.mayachainSignAminoDeposit({
87
- // @ts-expect-error
88
- signDoc,
89
- signerAddress: from,
90
- });
85
+ const sdkMethod = isTransfer
86
+ ? sdk.mayachain.mayachainSignAminoTransfer
87
+ : sdk.mayachain.mayachainSignAminoDeposit;
88
+
89
+ // @ts-expect-error TC
90
+ const signedTx = await sdkMethod({ signDoc, signerAddress: sender });
91
91
  const decodedBytes = atob(signedTx.serialized);
92
92
  return new Uint8Array(decodedBytes.length).map((_, i) => decodedBytes.charCodeAt(i));
93
93
  };
94
94
 
95
- const transfer = async ({ assetValue, recipient, memo }: TransferParams) => {
95
+ const transfer = async ({ assetValue, recipient, memo }: GenericTransferParams) => {
96
96
  const stargateClient = await createStargateClient(SKConfig.get("rpcUrls")[Chain.Maya]);
97
97
  const signedTransaction = await signTransaction({
98
98
  assetValue,
99
99
  recipient,
100
100
  memo,
101
- from: fromAddress,
101
+ sender: fromAddress,
102
102
  });
103
103
  const { transactionHash } = await stargateClient.broadcastTx(signedTransaction);
104
104
 
105
105
  return transactionHash;
106
106
  };
107
107
 
108
- const deposit = async ({ assetValue, memo }: DepositParam) => {
108
+ const deposit = async ({ assetValue, memo }: ThorchainDepositParams) => {
109
109
  const stargateClient = await createStargateClient(SKConfig.get("rpcUrls")[Chain.Maya]);
110
110
  const signedTransaction = await signTransaction({
111
111
  assetValue,
112
112
  memo,
113
- from: fromAddress,
113
+ sender: fromAddress,
114
114
  });
115
115
  const { transactionHash } = await stargateClient.broadcastTx(signedTransaction);
116
116
 
@@ -9,17 +9,18 @@ import {
9
9
  ChainId,
10
10
  DerivationPath,
11
11
  type DerivationPathArray,
12
+ type GenericTransferParams,
12
13
  SKConfig,
13
14
  derivationPathToString,
14
15
  } from "@swapkit/helpers";
15
- import type { DepositParam, TransferParams } from "@swapkit/toolboxes/cosmos";
16
+ import type { ThorchainDepositParams } from "@swapkit/toolboxes/cosmos";
16
17
 
17
18
  import { bip32ToAddressNList } from "../coins";
18
19
 
19
20
  type SignTransactionParams = {
20
21
  assetValue: AssetValue;
21
22
  recipient?: string;
22
- from: string;
23
+ sender: string;
23
24
  memo: string | undefined;
24
25
  };
25
26
 
@@ -31,10 +32,10 @@ export const thorchainWalletMethods = async ({
31
32
  derivationPath?: DerivationPathArray;
32
33
  }) => {
33
34
  const { makeSignDoc } = await import("@cosmjs/amino");
34
- const { buildAminoMsg, getDefaultChainFee, createStargateClient, ThorchainToolbox } =
35
+ const { buildAminoMsg, getDefaultChainFee, createStargateClient, getCosmosToolbox } =
35
36
  await import("@swapkit/toolboxes/cosmos");
36
37
 
37
- const toolbox = ThorchainToolbox();
38
+ const toolbox = await getCosmosToolbox(Chain.THORChain);
38
39
  const derivationPathString = derivationPath
39
40
  ? derivationPathToString(derivationPath)
40
41
  : `${DerivationPath.THOR}/0`;
@@ -43,14 +44,19 @@ export const thorchainWalletMethods = async ({
43
44
  address_n: bip32ToAddressNList(derivationPathString),
44
45
  })) as { address: string };
45
46
 
46
- const signTransaction = async ({ assetValue, recipient, from, memo }: SignTransactionParams) => {
47
- const account = await toolbox.getAccount(from);
47
+ const signTransaction = async ({
48
+ assetValue,
49
+ recipient,
50
+ sender,
51
+ memo,
52
+ }: SignTransactionParams) => {
53
+ const account = await toolbox.getAccount(sender);
48
54
  if (!account) throw new Error("Account not found");
49
55
  const { accountNumber, sequence = 0 } = account;
50
56
 
51
57
  const isTransfer = recipient && recipient !== "";
52
58
 
53
- const msg = buildAminoMsg({ chain: Chain.THORChain, from, recipient, assetValue, memo });
59
+ const msg = buildAminoMsg({ sender, recipient, assetValue, memo });
54
60
 
55
61
  const chainId = ChainId.THORChain;
56
62
 
@@ -66,35 +72,35 @@ export const thorchainWalletMethods = async ({
66
72
  const signedTx = isTransfer
67
73
  ? await sdk.thorchain.thorchainSignAminoTransfer({
68
74
  signDoc: signDoc as TypesThorchainSignDocTransfer,
69
- signerAddress: from,
75
+ signerAddress: sender,
70
76
  })
71
77
  : await sdk.thorchain.thorchainSignAminoDeposit({
72
78
  signDoc: signDoc as TypesThorchainSignDocDeposit,
73
- signerAddress: from,
79
+ signerAddress: sender,
74
80
  });
75
81
  const decodedBytes = atob(signedTx.serialized);
76
82
  return new Uint8Array(decodedBytes.length).map((_, i) => decodedBytes.charCodeAt(i));
77
83
  };
78
84
 
79
- const transfer = async ({ assetValue, recipient, memo }: TransferParams) => {
85
+ const transfer = async ({ assetValue, recipient, memo }: GenericTransferParams) => {
80
86
  const stargateClient = await createStargateClient(SKConfig.get("rpcUrls")[Chain.THORChain]);
81
87
  const signedTransaction = await signTransaction({
82
88
  assetValue,
83
89
  recipient,
84
90
  memo,
85
- from: fromAddress,
91
+ sender: fromAddress,
86
92
  });
87
93
  const { transactionHash } = await stargateClient.broadcastTx(signedTransaction);
88
94
 
89
95
  return transactionHash;
90
96
  };
91
97
 
92
- const deposit = async ({ assetValue, memo }: DepositParam) => {
98
+ const deposit = async ({ assetValue, memo }: ThorchainDepositParams) => {
93
99
  const stargateClient = await createStargateClient(SKConfig.get("rpcUrls")[Chain.THORChain]);
94
100
  const signedTransaction = await signTransaction({
95
101
  assetValue,
96
102
  memo,
97
- from: fromAddress,
103
+ sender: fromAddress,
98
104
  });
99
105
  const { transactionHash } = await stargateClient.broadcastTx(signedTransaction);
100
106
 
@@ -1,30 +1,18 @@
1
+ import type { KeepKeySdk } from "@keepkey/keepkey-sdk";
1
2
  import {
2
3
  Chain,
3
4
  DerivationPath,
4
5
  type DerivationPathArray,
5
6
  FeeOption,
7
+ type GenericTransferParams,
6
8
  type UTXOChain,
7
9
  derivationPathToString,
8
10
  } from "@swapkit/helpers";
9
- import type { BCHToolbox, Psbt, UTXOToolbox, UTXOTransferParams } from "@swapkit/toolboxes/utxo";
11
+ import type { Psbt } from "bitcoinjs-lib";
10
12
 
13
+ import type { UTXOToolboxes } from "@swapkit/toolboxes/utxo";
11
14
  import { ChainToKeepKeyName, bip32ToAddressNList } from "../coins";
12
15
 
13
- type KKUtxoWalletParams = {
14
- sdk: any;
15
- chain: UTXOChain;
16
- derivationPath?: DerivationPathArray;
17
- };
18
-
19
- interface psbtTxOutput {
20
- address: string;
21
- script: Buffer;
22
- value: number;
23
- change?: boolean; // Optional, assuming it indicates if the output is a change
24
- }
25
- interface ExtendedPsbt extends Psbt {
26
- txOutputs: psbtTxOutput[];
27
- }
28
16
  interface KeepKeyInputObject {
29
17
  addressNList: number[];
30
18
  scriptType: string;
@@ -38,21 +26,13 @@ export const utxoWalletMethods = async ({
38
26
  sdk,
39
27
  chain,
40
28
  derivationPath,
41
- }: KKUtxoWalletParams): Promise<
42
- UTXOToolbox & {
43
- address: string;
44
- signTransaction: (
45
- psbt: ExtendedPsbt,
46
- inputs: KeepKeyInputObject[],
47
- memo?: string,
48
- ) => Promise<string>;
49
- transfer: (params: UTXOTransferParams) => Promise<string>;
50
- }
51
- > => {
52
- const { getToolboxByChain } = await import("@swapkit/toolboxes/utxo");
53
-
54
- const toolbox = getToolboxByChain(chain)();
55
- const scriptType = [Chain.Bitcoin, Chain.Litecoin].includes(chain) ? "p2wpkh" : "p2pkh";
29
+ }: { sdk: KeepKeySdk; chain: UTXOChain; derivationPath?: DerivationPathArray }) => {
30
+ const { getUtxoToolbox } = await import("@swapkit/toolboxes/utxo");
31
+ // This might not work for BCH
32
+ const toolbox = await getUtxoToolbox(chain);
33
+ const scriptType = [Chain.Bitcoin, Chain.Litecoin].includes(chain)
34
+ ? ("p2wpkh" as const)
35
+ : ("p2pkh" as const);
56
36
 
57
37
  const derivationPathString = derivationPath
58
38
  ? derivationPathToString(derivationPath)
@@ -64,17 +44,21 @@ export const utxoWalletMethods = async ({
64
44
  address_n: bip32ToAddressNList(derivationPathString),
65
45
  };
66
46
 
67
- const { address: walletAddress } = await sdk.address.utxoGetAddress(addressInfo);
47
+ const walletAddress: string = (await sdk.address.utxoGetAddress(addressInfo)).address;
68
48
 
69
49
  const signTransaction = async (psbt: Psbt, inputs: KeepKeyInputObject[], memo = "") => {
70
50
  const outputs = psbt.txOutputs
71
51
  .map((output) => {
72
- const { value, address, change } = output as psbtTxOutput;
52
+ const { value, address, change } = output as {
53
+ address: string;
54
+ script: Buffer;
55
+ value: number;
56
+ change?: boolean;
57
+ };
73
58
 
74
59
  const outputAddress =
75
- chain === Chain.BitcoinCash
76
- ? (toolbox as ReturnType<typeof BCHToolbox>).stripToCashAddress(address)
77
- : address;
60
+ // @ts-expect-error - stripToCashAddress is not defined in the UTXO toolbox just only on BCH
61
+ chain === Chain.BitcoinCash ? toolbox.stripToCashAddress(address) : address;
78
62
 
79
63
  if (change || address === walletAddress) {
80
64
  return {
@@ -85,6 +69,7 @@ export const utxoWalletMethods = async ({
85
69
  scriptType,
86
70
  };
87
71
  }
72
+
88
73
  if (outputAddress) {
89
74
  return { address: outputAddress, amount: value, addressType: "spend" };
90
75
  }
@@ -103,41 +88,44 @@ export const utxoWalletMethods = async ({
103
88
  coin: ChainToKeepKeyName[chain],
104
89
  inputs,
105
90
  outputs: removeNullAndEmptyObjectsFromArray(outputs),
106
- version: 1,
107
- locktime: 0,
108
91
  opReturnData: memo,
109
92
  });
110
- return responseSign.serializedTx;
93
+
94
+ return responseSign.serializedTx?.toString();
111
95
  };
112
96
 
113
97
  const transfer = async ({
114
- from,
115
98
  recipient,
116
99
  feeOptionKey,
117
100
  feeRate,
118
101
  memo,
119
102
  ...rest
120
- }: UTXOTransferParams) => {
121
- if (!from) throw new Error("From address must be provided");
103
+ }: GenericTransferParams) => {
104
+ if (!walletAddress) throw new Error("From address must be provided");
122
105
  if (!recipient) throw new Error("Recipient address must be provided");
123
106
 
124
- const { psbt, inputs: rawInputs } = await toolbox.buildTx({
107
+ const createTxMethod =
108
+ chain === Chain.BitcoinCash
109
+ ? (toolbox as UTXOToolboxes["BCH"]).buildTx
110
+ : (toolbox as UTXOToolboxes["BTC"]).createTransaction;
111
+
112
+ const { psbt, inputs: rawInputs } = await createTxMethod({
125
113
  ...rest,
126
114
  memo,
127
115
  recipient,
128
116
  feeRate: feeRate || (await toolbox.getFeeRates())[feeOptionKey || FeeOption.Fast],
129
- sender: from,
130
- fetchTxHex: chain === Chain.BitcoinCash,
117
+ sender: walletAddress,
118
+ fetchTxHex: true,
131
119
  });
132
120
 
133
121
  const inputs = rawInputs.map(({ value, index, hash, txHex }) => ({
134
122
  //@TODO don't hardcode master, lookup on blockbook what input this is for and what path that address is!
135
123
  addressNList: addressInfo.address_n,
136
- scriptType,
137
124
  amount: value.toString(),
138
- vout: index,
139
- txid: hash,
140
125
  hex: txHex || "",
126
+ scriptType,
127
+ txid: hash,
128
+ vout: index,
141
129
  }));
142
130
 
143
131
  const txHex = await signTransaction(psbt, inputs, memo);
@@ -11,7 +11,7 @@ import {
11
11
  import { KeepKeySdk } from "@keepkey/keepkey-sdk";
12
12
  export type { PairingInfo } from "@keepkey/keepkey-sdk";
13
13
 
14
- import { getWalletSupportedChains } from "../helpers";
14
+ import { getWalletSupportedChains } from "../utils";
15
15
  import { cosmosWalletMethods } from "./chains/cosmos";
16
16
  import { KeepKeySigner } from "./chains/evm";
17
17
  import { mayachainWalletMethods } from "./chains/mayachain";
@@ -60,13 +60,9 @@ export const keepkeyWallet = createWallet({
60
60
  derivationPath: derivationPathMap?.[chain] || NetworkDerivationPath[chain],
61
61
  sdk: keepKeySdk,
62
62
  });
63
+ const address = (await walletMethods.getAddress()) || "";
63
64
 
64
- addChain({
65
- ...walletMethods,
66
- balance: [],
67
- chain,
68
- walletType: WalletOption.KEEPKEY,
69
- });
65
+ addChain({ ...walletMethods, address, chain, walletType: WalletOption.KEEPKEY });
70
66
  }),
71
67
  );
72
68
  return true;
@@ -80,7 +76,7 @@ async function getWalletMethods({
80
76
  chain,
81
77
  derivationPath,
82
78
  }: { sdk: KeepKeySdk; chain: Chain; derivationPath?: DerivationPathArray }) {
83
- const { getProvider, getToolboxByChain } = await import("@swapkit/toolboxes/evm");
79
+ const { getProvider, getEvmToolbox } = await import("@swapkit/toolboxes/evm");
84
80
 
85
81
  switch (chain) {
86
82
  case Chain.BinanceSmartChain:
@@ -89,17 +85,11 @@ async function getWalletMethods({
89
85
  case Chain.Polygon:
90
86
  case Chain.Avalanche:
91
87
  case Chain.Ethereum: {
92
- const provider = getProvider(chain);
93
- const signer = new KeepKeySigner({
94
- sdk,
95
- chain,
96
- derivationPath,
97
- provider,
98
- });
99
- const address = await signer.getAddress();
100
- const toolbox = getToolboxByChain(chain)({ provider, signer });
88
+ const provider = await getProvider(chain);
89
+ const signer = new KeepKeySigner({ sdk, chain, derivationPath, provider });
90
+ const toolbox = await getEvmToolbox(chain, { provider, signer });
101
91
 
102
- return { address, ...toolbox };
92
+ return toolbox;
103
93
  }
104
94
  case Chain.Cosmos: {
105
95
  return cosmosWalletMethods({ sdk, derivationPath });
@@ -115,11 +105,7 @@ async function getWalletMethods({
115
105
  case Chain.Dash:
116
106
  case Chain.Dogecoin:
117
107
  case Chain.Litecoin: {
118
- return utxoWalletMethods({
119
- sdk,
120
- chain,
121
- derivationPath,
122
- });
108
+ return utxoWalletMethods({ sdk, chain, derivationPath });
123
109
  }
124
110
  default:
125
111
  throw new Error(`Chain not supported ${chain}`);