@swapkit/wallets 3.0.0-beta.20 → 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 (113) hide show
  1. package/dist/chunk-2aa1w78q.js +3 -0
  2. package/dist/chunk-2aa1w78q.js.map +10 -0
  3. package/dist/{chunk-s6xqbsy0.js → chunk-ebfkk1jn.js} +1 -1
  4. package/dist/{chunk-s6xqbsy0.js.map → chunk-ebfkk1jn.js.map} +1 -1
  5. package/dist/{chunk-sygzrjje.js → chunk-k9q04afa.js} +1 -1
  6. package/dist/{chunk-sygzrjje.js.map → chunk-k9q04afa.js.map} +1 -1
  7. package/dist/chunk-x5hgx9x9.js +3 -0
  8. package/dist/chunk-x5hgx9x9.js.map +10 -0
  9. package/dist/src/bitget/index.cjs +2 -2
  10. package/dist/src/bitget/index.cjs.map +3 -3
  11. package/dist/src/bitget/index.js +2 -2
  12. package/dist/src/bitget/index.js.map +3 -3
  13. package/dist/src/coinbase/index.cjs +2 -2
  14. package/dist/src/coinbase/index.cjs.map +3 -3
  15. package/dist/src/coinbase/index.js +2 -2
  16. package/dist/src/coinbase/index.js.map +3 -3
  17. package/dist/src/cosmostation/index.cjs +3 -0
  18. package/dist/src/cosmostation/index.cjs.map +10 -0
  19. package/dist/src/cosmostation/index.js +3 -0
  20. package/dist/src/cosmostation/index.js.map +10 -0
  21. package/dist/src/ctrl/index.js +1 -1
  22. package/dist/src/evm-extensions/index.cjs +2 -2
  23. package/dist/src/evm-extensions/index.cjs.map +3 -3
  24. package/dist/src/evm-extensions/index.js +2 -2
  25. package/dist/src/evm-extensions/index.js.map +3 -3
  26. package/dist/src/exodus/index.cjs +2 -2
  27. package/dist/src/exodus/index.cjs.map +3 -3
  28. package/dist/src/exodus/index.js +2 -2
  29. package/dist/src/exodus/index.js.map +3 -3
  30. package/dist/src/index.js +1 -1
  31. package/dist/src/keepkey/index.cjs +2 -2
  32. package/dist/src/keepkey/index.cjs.map +9 -9
  33. package/dist/src/keepkey/index.js +2 -2
  34. package/dist/src/keepkey/index.js.map +9 -9
  35. package/dist/src/keepkey-bex/index.cjs +2 -2
  36. package/dist/src/keepkey-bex/index.cjs.map +4 -4
  37. package/dist/src/keepkey-bex/index.js +2 -2
  38. package/dist/src/keepkey-bex/index.js.map +4 -4
  39. package/dist/src/keplr/index.cjs +2 -2
  40. package/dist/src/keplr/index.cjs.map +3 -3
  41. package/dist/src/keplr/index.js +2 -2
  42. package/dist/src/keplr/index.js.map +3 -3
  43. package/dist/src/keystore/index.cjs +2 -2
  44. package/dist/src/keystore/index.cjs.map +3 -3
  45. package/dist/src/keystore/index.js +2 -2
  46. package/dist/src/keystore/index.js.map +3 -3
  47. package/dist/src/ledger/index.cjs +3 -3
  48. package/dist/src/ledger/index.cjs.map +13 -13
  49. package/dist/src/ledger/index.js +3 -3
  50. package/dist/src/ledger/index.js.map +13 -13
  51. package/dist/src/okx/index.cjs +2 -2
  52. package/dist/src/okx/index.cjs.map +3 -3
  53. package/dist/src/okx/index.js +2 -2
  54. package/dist/src/okx/index.js.map +3 -3
  55. package/dist/src/onekey/index.cjs +2 -2
  56. package/dist/src/onekey/index.cjs.map +3 -3
  57. package/dist/src/onekey/index.js +2 -2
  58. package/dist/src/onekey/index.js.map +3 -3
  59. package/dist/src/phantom/index.js +1 -1
  60. package/dist/src/polkadotjs/index.js +1 -1
  61. package/dist/src/radix/index.cjs +2 -2
  62. package/dist/src/radix/index.cjs.map +3 -3
  63. package/dist/src/radix/index.js +2 -2
  64. package/dist/src/radix/index.js.map +3 -3
  65. package/dist/src/talisman/index.js +1 -1
  66. package/dist/src/trezor/index.cjs +1 -1
  67. package/dist/src/trezor/index.js +1 -1
  68. package/dist/src/walletconnect/index.cjs +2 -2
  69. package/dist/src/walletconnect/index.cjs.map +4 -4
  70. package/dist/src/walletconnect/index.js +2 -2
  71. package/dist/src/walletconnect/index.js.map +4 -4
  72. package/package.json +13 -8
  73. package/src/bitget/helpers.ts +3 -2
  74. package/src/coinbase/signer.ts +4 -4
  75. package/src/cosmostation/index.ts +8 -7
  76. package/src/evm-extensions/index.ts +4 -3
  77. package/src/exodus/index.ts +7 -7
  78. package/src/keepkey/chains/cosmos.ts +44 -50
  79. package/src/keepkey/chains/evm.ts +16 -8
  80. package/src/keepkey/chains/mayachain.ts +2 -1
  81. package/src/keepkey/chains/thorchain.ts +2 -1
  82. package/src/keepkey/chains/utxo.ts +9 -2
  83. package/src/keepkey/coins.ts +10 -4
  84. package/src/keepkey/index.ts +15 -7
  85. package/src/keepkey-bex/index.ts +9 -14
  86. package/src/keepkey-bex/walletHelpers.ts +1 -1
  87. package/src/keplr/index.ts +4 -3
  88. package/src/keystore/index.ts +1 -0
  89. package/src/ledger/clients/cosmos.ts +3 -2
  90. package/src/ledger/clients/evm.ts +6 -5
  91. package/src/ledger/clients/thorchain/helpers.ts +9 -4
  92. package/src/ledger/clients/thorchain/index.ts +3 -3
  93. package/src/ledger/clients/thorchain/lib.ts +3 -2
  94. package/src/ledger/clients/thorchain/utils.ts +20 -9
  95. package/src/ledger/cosmosTypes.ts +14 -10
  96. package/src/ledger/helpers/getLedgerClient.ts +54 -47
  97. package/src/ledger/helpers/getLedgerTransport.ts +1 -1
  98. package/src/ledger/index.ts +7 -6
  99. package/src/ledger/interfaces/CosmosLedgerInterface.ts +0 -1
  100. package/src/okx/helpers.ts +9 -8
  101. package/src/onekey/index.ts +2 -6
  102. package/src/radix/index.ts +4 -4
  103. package/src/trezor/evmSigner.ts +1 -1
  104. package/src/walletconnect/evmSigner.ts +6 -2
  105. package/src/walletconnect/index.ts +2 -2
  106. package/dist/chunk-4ef2xs46.js +0 -3
  107. package/dist/chunk-4ef2xs46.js.map +0 -10
  108. package/dist/chunk-qgv1myym.js +0 -3
  109. package/dist/chunk-qgv1myym.js.map +0 -10
  110. package/dist/chunk-w07sv0jv.js +0 -3
  111. package/dist/chunk-w07sv0jv.js.map +0 -10
  112. package/dist/chunk-y0g3prs9.js +0 -3
  113. package/dist/chunk-y0g3prs9.js.map +0 -10
@@ -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
 
@@ -7,6 +7,7 @@ import {
7
7
  type DerivationPathArray,
8
8
  type GenericTransferParams,
9
9
  SKConfig,
10
+ SwapKitError,
10
11
  derivationPathToString,
11
12
  } from "@swapkit/helpers";
12
13
  import type { ThorchainDepositParams } from "@swapkit/toolboxes/cosmos";
@@ -48,7 +49,7 @@ export const mayachainWalletMethods = async ({
48
49
  const { getDenomWithChain } = await import("@swapkit/toolboxes/cosmos");
49
50
 
50
51
  const account = await toolbox.getAccount(sender);
51
- if (!account) throw new Error("Account not found");
52
+ if (!account) throw new SwapKitError("wallet_keepkey_account_not_found");
52
53
  const { accountNumber, sequence = 0 } = account;
53
54
  const amount = assetValue.getBaseValue("string");
54
55
 
@@ -11,6 +11,7 @@ import {
11
11
  type DerivationPathArray,
12
12
  type GenericTransferParams,
13
13
  SKConfig,
14
+ SwapKitError,
14
15
  derivationPathToString,
15
16
  } from "@swapkit/helpers";
16
17
  import type { ThorchainDepositParams } from "@swapkit/toolboxes/cosmos";
@@ -51,7 +52,7 @@ export const thorchainWalletMethods = async ({
51
52
  memo,
52
53
  }: SignTransactionParams) => {
53
54
  const account = await toolbox.getAccount(sender);
54
- if (!account) throw new Error("Account not found");
55
+ if (!account) throw new SwapKitError("wallet_keepkey_account_not_found");
55
56
  const { accountNumber, sequence = 0 } = account;
56
57
 
57
58
  const isTransfer = recipient && recipient !== "";
@@ -5,6 +5,7 @@ import {
5
5
  type DerivationPathArray,
6
6
  FeeOption,
7
7
  type GenericTransferParams,
8
+ SwapKitError,
8
9
  type UTXOChain,
9
10
  derivationPathToString,
10
11
  } from "@swapkit/helpers";
@@ -101,8 +102,14 @@ export const utxoWalletMethods = async ({
101
102
  memo,
102
103
  ...rest
103
104
  }: GenericTransferParams) => {
104
- if (!walletAddress) throw new Error("From address must be provided");
105
- if (!recipient) throw new Error("Recipient address must be provided");
105
+ if (!walletAddress)
106
+ throw new SwapKitError("wallet_keepkey_invalid_params", {
107
+ reason: "From address must be provided",
108
+ });
109
+ if (!recipient)
110
+ throw new SwapKitError("wallet_keepkey_invalid_params", {
111
+ reason: "Recipient address must be provided",
112
+ });
106
113
 
107
114
  const createTxMethod =
108
115
  chain === Chain.BitcoinCash
@@ -2,6 +2,8 @@
2
2
  KeepKey Specific bip32 path conventions
3
3
  */
4
4
 
5
+ import { SwapKitError } from "@swapkit/helpers";
6
+
5
7
  const HARDENED = 0x80000000;
6
8
 
7
9
  export enum ChainToKeepKeyName {
@@ -27,7 +29,9 @@ export function bip32ToAddressNList(initPath: string): number[] {
27
29
  let path = initPath;
28
30
 
29
31
  if (!bip32Like(path)) {
30
- throw new Error(`Not a bip32 path: '${path}'`);
32
+ throw new SwapKitError("wallet_keepkey_invalid_params", {
33
+ reason: `Not a bip32 path: '${path}'`,
34
+ });
31
35
  }
32
36
 
33
37
  if (/^m\//i.test(path)) {
@@ -44,18 +48,20 @@ export function bip32ToAddressNList(initPath: string): number[] {
44
48
  const segment = segments[i];
45
49
  if (segment) {
46
50
  const tmp = /(\d+)([hH']?)/.exec(segment);
47
- if (tmp === null) throw new Error("Invalid input");
51
+ if (tmp === null)
52
+ throw new SwapKitError("wallet_keepkey_invalid_params", { reason: "Invalid input" });
48
53
 
49
54
  const [, num = "", modifier = ""] = tmp;
50
55
 
51
56
  ret[i] = Number.parseInt(num, 10);
52
57
 
53
- if (ret[i] >= HARDENED) throw new Error("Invalid child index");
58
+ if (ret[i] >= HARDENED)
59
+ throw new SwapKitError("wallet_keepkey_invalid_params", { reason: "Invalid child index" });
54
60
 
55
61
  if (modifier === "h" || modifier === "H" || modifier === "'") {
56
62
  ret[i] += HARDENED;
57
63
  } else if (modifier.length > 0) {
58
- throw new Error("Invalid modifier");
64
+ throw new SwapKitError("wallet_keepkey_invalid_params", { reason: "Invalid modifier" });
59
65
  }
60
66
  }
61
67
  }
@@ -3,6 +3,7 @@ import {
3
3
  type DerivationPathArray,
4
4
  NetworkDerivationPath,
5
5
  SKConfig,
6
+ SwapKitError,
6
7
  WalletOption,
7
8
  createWallet,
8
9
  filterSupportedChains,
@@ -44,15 +45,22 @@ export const keepkeyWallet = createWallet({
44
45
  derivationPathMap?: Record<Chain, DerivationPathArray>,
45
46
  ) {
46
47
  const filteredChains = filterSupportedChains({ chains, supportedChains, walletType });
47
- const config = SKConfig.get("integrations").keepKey;
48
+ const pairingInfo = SKConfig.get("integrations").keepKey;
49
+ if (!pairingInfo) throw new Error("KeepKey config not found");
48
50
 
49
- if (!config) throw new Error("KeepKey config not found");
51
+ const initialApiKey = SKConfig.get("apiKeys").keepKey || "1234";
50
52
 
51
53
  await checkAndLaunch();
52
54
 
53
- const keepkeyConfig = { ...config, apiKey: SKConfig.get("apiKeys").keepKey };
55
+ // Conform to the expected { apiKey, pairingInfo } structure
56
+ const keepkeyConfig = { apiKey: initialApiKey, pairingInfo };
54
57
  const keepKeySdk = await KeepKeySdk.create(keepkeyConfig);
55
58
 
59
+ // Persist the new API key via SKConfig after pairing
60
+ if (keepkeyConfig.apiKey && keepkeyConfig.apiKey !== initialApiKey) {
61
+ SKConfig.setApiKey("keepKey", keepkeyConfig.apiKey);
62
+ }
63
+
56
64
  await Promise.all(
57
65
  filteredChains.map(async (chain) => {
58
66
  const walletMethods = await getWalletMethods({
@@ -84,6 +92,7 @@ async function getWalletMethods({
84
92
  case Chain.Optimism:
85
93
  case Chain.Polygon:
86
94
  case Chain.Avalanche:
95
+ case Chain.Base:
87
96
  case Chain.Ethereum: {
88
97
  const provider = await getProvider(chain);
89
98
  const signer = new KeepKeySigner({ sdk, chain, derivationPath, provider });
@@ -108,11 +117,11 @@ async function getWalletMethods({
108
117
  return utxoWalletMethods({ sdk, chain, derivationPath });
109
118
  }
110
119
  default:
111
- throw new Error(`Chain not supported ${chain}`);
120
+ throw new SwapKitError("wallet_keepkey_chain_not_supported", { chain });
112
121
  }
113
122
  }
114
123
 
115
- // kk-sdk docs: https://medium.com/@highlander_35968/building-on-the-keepkey-sdk-2023fda41f38
124
+ // kk-sdk docs: https://keepkey.com/blog/building_on_the_keepkey_sdk
116
125
  // test spec: if offline, launch keepkey-bridge
117
126
  async function checkAndLaunch(attempts = 0) {
118
127
  if (attempts >= 3) {
@@ -133,8 +142,7 @@ async function checkKeepkeyAvailability(spec = "http://localhost:1646/spec/swagg
133
142
  try {
134
143
  const response = await fetch(spec);
135
144
  return response.status === 200;
136
- } catch (error) {
137
- console.error(error);
145
+ } catch (_error) {
138
146
  return false;
139
147
  }
140
148
  }
@@ -83,11 +83,11 @@ async function getWalletMethods(chain: (typeof KEEPKEY_BEX_SUPPORTED_CHAINS)[num
83
83
 
84
84
  // @ts-expect-error assumed available connection
85
85
  const signer = window.keepkey?.cosmos?.getOfflineSignerOnlyAmino(ChainIdToChain[chain]);
86
- if (!signer) throw new Error("Could not load signer");
86
+ if (!signer) throw new SwapKitError("wallet_keepkey_signer_not_found");
87
87
  const toolbox = getCosmosToolbox(chain, { signer });
88
88
 
89
89
  const accounts = await signer.getAccounts();
90
- if (!accounts?.[0]?.address) throw new Error("No accounts found");
90
+ if (!accounts?.[0]?.address) throw new SwapKitError("wallet_keepkey_no_accounts");
91
91
 
92
92
  const [{ address }] = accounts;
93
93
 
@@ -103,18 +103,13 @@ async function getWalletMethods(chain: (typeof KEEPKEY_BEX_SUPPORTED_CHAINS)[num
103
103
  const toolbox = await getUtxoToolbox(chain);
104
104
 
105
105
  const getBalance = async () => {
106
- try {
107
- const providerChain = getProviderNameFromChain(chain);
108
- // @ts-expect-error We assuming there chains via switch
109
- const balance = await window?.keepkey?.[providerChain]?.request({
110
- method: "request_balance",
111
- });
112
- const assetValue = AssetValue.from({ chain, value: balance[0].balance });
113
- return [assetValue];
114
- } catch (error) {
115
- console.error("Error fetching balance:", error);
116
- throw error;
117
- }
106
+ const providerChain = getProviderNameFromChain(chain);
107
+ // @ts-expect-error We assuming there chains via switch
108
+ const balance = await window?.keepkey?.[providerChain]?.request({
109
+ method: "request_balance",
110
+ });
111
+ const assetValue = AssetValue.from({ chain, value: balance[0].balance });
112
+ return [assetValue];
118
113
  };
119
114
 
120
115
  return { ...toolbox, getBalance, transfer: walletTransfer };
@@ -60,7 +60,7 @@ export const getProviderNameFromChain = (chain: Chain): string => {
60
60
  case Chain.Litecoin:
61
61
  return "litecoin";
62
62
  default:
63
- throw new Error("Unsupported chain");
63
+ throw new SwapKitError("wallet_keepkey_chain_not_supported", { chain });
64
64
  }
65
65
  };
66
66
 
@@ -2,6 +2,7 @@ import {
2
2
  Chain,
3
3
  ChainId,
4
4
  ChainToChainId,
5
+ SwapKitError,
5
6
  WalletOption,
6
7
  createWallet,
7
8
  filterSupportedChains,
@@ -28,19 +29,19 @@ export const keplrWallet = createWallet({
28
29
 
29
30
  if (!keplrSupportedChainIds.includes(chainId)) {
30
31
  const chainConfig = chainRegistry.get(chainId);
31
- if (!chainConfig) throw new Error(`Unsupported chain ${chain}`);
32
+ if (!chainConfig) throw new SwapKitError("wallet_keplr_chain_not_supported", { chain });
32
33
 
33
34
  await keplrClient.experimentalSuggestChain(chainConfig);
34
35
  }
35
36
 
36
37
  keplrClient?.enable(chainId);
37
38
  const signer = keplrClient?.getOfflineSignerOnlyAmino(chainId);
38
- if (!signer) throw new Error("Could not load signer");
39
+ if (!signer) throw new SwapKitError("wallet_keplr_signer_not_found");
39
40
 
40
41
  const { getCosmosToolbox } = await import("@swapkit/toolboxes/cosmos");
41
42
 
42
43
  const accounts = await signer.getAccounts();
43
- if (!accounts?.[0]?.address) throw new Error("No accounts found");
44
+ if (!accounts?.[0]?.address) throw new SwapKitError("wallet_keplr_no_accounts");
44
45
 
45
46
  const [{ address }] = accounts;
46
47
  const toolbox = getCosmosToolbox(chain, { signer });
@@ -23,6 +23,7 @@ export const keystoreWallet = createWallet({
23
23
  Chain.Chainflip,
24
24
  Chain.Ripple,
25
25
  Chain.Solana,
26
+ Chain.Tron,
26
27
  ],
27
28
  connect: ({ addChain, supportedChains, walletType }) =>
28
29
  async function connectKeystore(
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  type DerivationPathArray,
3
3
  NetworkDerivationPath,
4
+ SwapKitError,
4
5
  derivationPathToString,
5
6
  } from "@swapkit/helpers";
6
7
  import { CosmosLedgerInterface } from "../interfaces/CosmosLedgerInterface";
@@ -41,7 +42,7 @@ export class CosmosLedger extends CosmosLedgerInterface {
41
42
  rawTx,
42
43
  );
43
44
 
44
- if (!this.pubKey) throw new Error("Public Key not found");
45
+ if (!this.pubKey) throw new SwapKitError("wallet_ledger_pubkey_not_found");
45
46
 
46
47
  this.validateResponse(return_code, error_message);
47
48
 
@@ -61,7 +62,7 @@ export class CosmosLedger extends CosmosLedgerInterface {
61
62
  const accountIndex = accounts.findIndex((account) => account.address === signerAddress);
62
63
 
63
64
  if (accountIndex === -1) {
64
- throw new Error(`Address ${signerAddress} not found in wallet`);
65
+ throw new SwapKitError("wallet_ledger_address_not_found", { address: signerAddress });
65
66
  }
66
67
 
67
68
  const { encodeSecp256k1Signature, serializeSignDoc } = (await import("@cosmjs/amino")).default;
@@ -3,6 +3,7 @@ import {
3
3
  ChainId,
4
4
  type DerivationPathArray,
5
5
  NetworkDerivationPath,
6
+ SwapKitError,
6
7
  derivationPathToString,
7
8
  } from "@swapkit/helpers";
8
9
  import { AbstractSigner, type Provider, type TransactionRequest } from "ethers";
@@ -58,7 +59,7 @@ class EVMLedgerInterface extends AbstractSigner {
58
59
 
59
60
  getAddress = async () => {
60
61
  const response = await this.getAddressAndPubKey();
61
- if (!response) throw new Error("Could not get Address");
62
+ if (!response) throw new SwapKitError("wallet_ledger_failed_to_get_address");
62
63
  return response.address;
63
64
  };
64
65
 
@@ -78,7 +79,7 @@ class EVMLedgerInterface extends AbstractSigner {
78
79
 
79
80
  const sig = await this.ledgerApp?.signPersonalMessage(this.derivationPath, messageHex);
80
81
 
81
- if (!sig) throw new Error("Signing failed");
82
+ if (!sig) throw new SwapKitError("wallet_ledger_signing_error");
82
83
 
83
84
  sig.r = `0x${sig.r}`;
84
85
  sig.s = `0x${sig.s}`;
@@ -86,7 +87,7 @@ class EVMLedgerInterface extends AbstractSigner {
86
87
  };
87
88
 
88
89
  sendTransaction = async (tx: TransactionRequest): Promise<any> => {
89
- if (!this.provider) throw new Error("No provider set");
90
+ if (!this.provider) throw new SwapKitError("wallet_ledger_no_provider");
90
91
 
91
92
  const signedTxHex = await this.signTransaction(tx);
92
93
 
@@ -94,7 +95,7 @@ class EVMLedgerInterface extends AbstractSigner {
94
95
  };
95
96
 
96
97
  signTypedData(): Promise<string> {
97
- throw new Error("Method not implemented.");
98
+ throw new SwapKitError("wallet_ledger_method_not_supported", { method: "signTypedData" });
98
99
  }
99
100
 
100
101
  signTransaction = async (tx: TransactionRequest) => {
@@ -141,7 +142,7 @@ class EVMLedgerInterface extends AbstractSigner {
141
142
  resolution,
142
143
  );
143
144
 
144
- if (!signature) throw new Error("Could not sign transaction");
145
+ if (!signature) throw new SwapKitError("wallet_ledger_signing_error");
145
146
 
146
147
  const { r, s, v } = signature;
147
148
 
@@ -1,3 +1,4 @@
1
+ import { SwapKitError } from "@swapkit/helpers";
1
2
  import {
2
3
  CLA,
3
4
  ERROR_CODE,
@@ -10,10 +11,10 @@ import {
10
11
 
11
12
  export function serializePathv1(path: number[]) {
12
13
  if (path == null || path.length < 3) {
13
- throw new Error("Invalid path.");
14
+ throw new SwapKitError("wallet_ledger_invalid_params", { reason: "Path too short" });
14
15
  }
15
16
  if (path.length > 10) {
16
- throw new Error("Invalid path. Length should be <= 10");
17
+ throw new SwapKitError("wallet_ledger_invalid_params", { reason: "Path too long" });
17
18
  }
18
19
  const buf = Buffer.alloc(1 + 4 * path.length);
19
20
  buf.writeUInt8(path.length, 0);
@@ -61,7 +62,9 @@ export async function signSendChunkv1(
61
62
 
62
63
  function compressPublicKey(publicKey: Buffer) {
63
64
  if (publicKey.length !== 65) {
64
- throw new Error("decompressed public key length should be 65 bytes");
65
+ throw new SwapKitError("wallet_ledger_invalid_params", {
66
+ reason: "decompressed public key length should be 65 bytes",
67
+ });
65
68
  }
66
69
  const y = publicKey.slice(33, 65);
67
70
 
@@ -90,7 +93,9 @@ export async function publicKeyv1(app: any, data: Buffer) {
90
93
 
91
94
  export function serializePathv2(path: number[]) {
92
95
  if (!path || path.length !== 5) {
93
- throw new Error("Invalid path.");
96
+ throw new SwapKitError("wallet_ledger_invalid_params", {
97
+ reason: "Path must be exactly 5 elements",
98
+ });
94
99
  }
95
100
 
96
101
  const buf = Buffer.alloc(20);
@@ -1,5 +1,5 @@
1
1
  import { base64 } from "@scure/base";
2
- import { type DerivationPathArray, NetworkDerivationPath } from "@swapkit/helpers";
2
+ import { type DerivationPathArray, NetworkDerivationPath, SwapKitError } from "@swapkit/helpers";
3
3
 
4
4
  import { CosmosLedgerInterface } from "../../interfaces/CosmosLedgerInterface";
5
5
  import type { GetAddressAndPubKeyResponse } from "../../types";
@@ -64,7 +64,7 @@ export class THORChainLedger extends CosmosLedgerInterface {
64
64
  rawTx,
65
65
  );
66
66
 
67
- if (!this.pubKey) throw new Error("Public Key not found");
67
+ if (!this.pubKey) throw new SwapKitError("wallet_ledger_pubkey_not_found");
68
68
 
69
69
  this.validateResponse(return_code, error_message);
70
70
 
@@ -85,7 +85,7 @@ export class THORChainLedger extends CosmosLedgerInterface {
85
85
  message,
86
86
  );
87
87
 
88
- if (!this.pubKey) throw new Error("Public Key not found");
88
+ if (!this.pubKey) throw new SwapKitError("wallet_ledger_pubkey_not_found");
89
89
 
90
90
  this.validateResponse(return_code, error_message);
91
91
 
@@ -1,4 +1,5 @@
1
1
  import type Transport from "@ledgerhq/hw-transport";
2
+ import { SwapKitError } from "@swapkit/helpers";
2
3
  /** ******************************************************************************
3
4
  * (c) 2019 ZondaX GmbH
4
5
  * (c) 2016-2017 Ledger
@@ -42,7 +43,7 @@ export class THORChainApp {
42
43
 
43
44
  constructor(transport: any) {
44
45
  if (!transport) {
45
- throw new Error("Transport has not been defined");
46
+ throw new SwapKitError("wallet_ledger_transport_not_defined");
46
47
  }
47
48
 
48
49
  this.transport = transport;
@@ -50,7 +51,7 @@ export class THORChainApp {
50
51
 
51
52
  static serializeHRP(hrp: string) {
52
53
  if (hrp == null || hrp.length < 3 || hrp.length > 83) {
53
- throw new Error("Invalid HRP");
54
+ throw new SwapKitError("wallet_ledger_invalid_params", { reason: "Invalid HRP" });
54
55
  }
55
56
  const buf = Buffer.alloc(1 + hrp.length);
56
57
  buf.writeUInt8(hrp.length, 0);