@swapkit/wallets 3.0.0-beta.20 → 3.0.0-beta.22
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.
- package/dist/chunk-2aa1w78q.js +3 -0
- package/dist/chunk-2aa1w78q.js.map +10 -0
- package/dist/{chunk-s6xqbsy0.js → chunk-ebfkk1jn.js} +1 -1
- package/dist/{chunk-s6xqbsy0.js.map → chunk-ebfkk1jn.js.map} +1 -1
- package/dist/{chunk-sygzrjje.js → chunk-k9q04afa.js} +1 -1
- package/dist/{chunk-sygzrjje.js.map → chunk-k9q04afa.js.map} +1 -1
- package/dist/chunk-x5hgx9x9.js +3 -0
- package/dist/chunk-x5hgx9x9.js.map +10 -0
- package/dist/src/bitget/index.cjs +2 -2
- package/dist/src/bitget/index.cjs.map +3 -3
- package/dist/src/bitget/index.js +2 -2
- package/dist/src/bitget/index.js.map +3 -3
- package/dist/src/coinbase/index.cjs +2 -2
- package/dist/src/coinbase/index.cjs.map +3 -3
- package/dist/src/coinbase/index.js +2 -2
- package/dist/src/coinbase/index.js.map +3 -3
- package/dist/src/cosmostation/index.cjs +3 -0
- package/dist/src/cosmostation/index.cjs.map +10 -0
- package/dist/src/cosmostation/index.js +3 -0
- package/dist/src/cosmostation/index.js.map +10 -0
- package/dist/src/ctrl/index.js +1 -1
- package/dist/src/evm-extensions/index.cjs +2 -2
- package/dist/src/evm-extensions/index.cjs.map +3 -3
- package/dist/src/evm-extensions/index.js +2 -2
- package/dist/src/evm-extensions/index.js.map +3 -3
- package/dist/src/exodus/index.cjs +2 -2
- package/dist/src/exodus/index.cjs.map +3 -3
- package/dist/src/exodus/index.js +2 -2
- package/dist/src/exodus/index.js.map +3 -3
- package/dist/src/index.js +1 -1
- package/dist/src/keepkey/index.cjs +2 -2
- package/dist/src/keepkey/index.cjs.map +9 -9
- package/dist/src/keepkey/index.js +2 -2
- package/dist/src/keepkey/index.js.map +9 -9
- package/dist/src/keepkey-bex/index.cjs +2 -2
- package/dist/src/keepkey-bex/index.cjs.map +4 -4
- package/dist/src/keepkey-bex/index.js +2 -2
- package/dist/src/keepkey-bex/index.js.map +4 -4
- package/dist/src/keplr/index.cjs +2 -2
- package/dist/src/keplr/index.cjs.map +3 -3
- package/dist/src/keplr/index.js +2 -2
- package/dist/src/keplr/index.js.map +3 -3
- package/dist/src/keystore/index.cjs +2 -2
- package/dist/src/keystore/index.cjs.map +3 -3
- package/dist/src/keystore/index.js +2 -2
- package/dist/src/keystore/index.js.map +3 -3
- package/dist/src/ledger/index.cjs +3 -3
- package/dist/src/ledger/index.cjs.map +13 -13
- package/dist/src/ledger/index.js +3 -3
- package/dist/src/ledger/index.js.map +13 -13
- package/dist/src/okx/index.cjs +2 -2
- package/dist/src/okx/index.cjs.map +3 -3
- package/dist/src/okx/index.js +2 -2
- package/dist/src/okx/index.js.map +3 -3
- package/dist/src/onekey/index.cjs +2 -2
- package/dist/src/onekey/index.cjs.map +3 -3
- package/dist/src/onekey/index.js +2 -2
- package/dist/src/onekey/index.js.map +3 -3
- package/dist/src/phantom/index.js +1 -1
- package/dist/src/polkadotjs/index.js +1 -1
- package/dist/src/radix/index.cjs +2 -2
- package/dist/src/radix/index.cjs.map +3 -3
- package/dist/src/radix/index.js +2 -2
- package/dist/src/radix/index.js.map +3 -3
- package/dist/src/talisman/index.js +1 -1
- package/dist/src/trezor/index.cjs +1 -1
- package/dist/src/trezor/index.js +1 -1
- package/dist/src/walletconnect/index.cjs +2 -2
- package/dist/src/walletconnect/index.cjs.map +4 -4
- package/dist/src/walletconnect/index.js +2 -2
- package/dist/src/walletconnect/index.js.map +4 -4
- package/package.json +13 -8
- package/src/bitget/helpers.ts +3 -2
- package/src/coinbase/signer.ts +4 -4
- package/src/cosmostation/index.ts +8 -7
- package/src/evm-extensions/index.ts +4 -3
- package/src/exodus/index.ts +7 -7
- package/src/keepkey/chains/cosmos.ts +44 -50
- package/src/keepkey/chains/evm.ts +16 -8
- package/src/keepkey/chains/mayachain.ts +2 -1
- package/src/keepkey/chains/thorchain.ts +2 -1
- package/src/keepkey/chains/utxo.ts +9 -2
- package/src/keepkey/coins.ts +10 -4
- package/src/keepkey/index.ts +15 -7
- package/src/keepkey-bex/index.ts +9 -14
- package/src/keepkey-bex/walletHelpers.ts +1 -1
- package/src/keplr/index.ts +4 -3
- package/src/keystore/index.ts +1 -0
- package/src/ledger/clients/cosmos.ts +3 -2
- package/src/ledger/clients/evm.ts +6 -5
- package/src/ledger/clients/thorchain/helpers.ts +9 -4
- package/src/ledger/clients/thorchain/index.ts +3 -3
- package/src/ledger/clients/thorchain/lib.ts +3 -2
- package/src/ledger/clients/thorchain/utils.ts +20 -9
- package/src/ledger/cosmosTypes.ts +14 -10
- package/src/ledger/helpers/getLedgerClient.ts +54 -47
- package/src/ledger/helpers/getLedgerTransport.ts +1 -1
- package/src/ledger/index.ts +7 -6
- package/src/ledger/interfaces/CosmosLedgerInterface.ts +0 -1
- package/src/okx/helpers.ts +9 -8
- package/src/onekey/index.ts +2 -6
- package/src/radix/index.ts +4 -4
- package/src/trezor/evmSigner.ts +1 -1
- package/src/walletconnect/evmSigner.ts +6 -2
- package/src/walletconnect/index.ts +2 -2
- package/dist/chunk-4ef2xs46.js +0 -3
- package/dist/chunk-4ef2xs46.js.map +0 -10
- package/dist/chunk-qgv1myym.js +0 -3
- package/dist/chunk-qgv1myym.js.map +0 -10
- package/dist/chunk-w07sv0jv.js +0 -3
- package/dist/chunk-w07sv0jv.js.map +0 -10
- package/dist/chunk-y0g3prs9.js +0 -3
- 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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
: `${DerivationPath.GAIA}/0`;
|
|
28
|
+
const { address: fromAddress } = (await sdk.address.cosmosGetAddress({
|
|
29
|
+
address_n: bip32ToAddressNList(derivationPathString),
|
|
30
|
+
})) as { address: string };
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
address_n: bip32ToAddressNList(derivationPathString),
|
|
32
|
-
})) as { address: string };
|
|
32
|
+
const toolbox = await getCosmosToolbox(Chain.Cosmos);
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
const decodedBytes = atob(keepKeySignedTx.serialized);
|
|
67
|
+
const uint8Array = new Uint8Array(decodedBytes.length).map((_, i) =>
|
|
68
|
+
decodedBytes.charCodeAt(i),
|
|
69
|
+
);
|
|
72
70
|
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
const client = await createStargateClient(SKConfig.get("rpcUrls")[Chain.Cosmos]);
|
|
72
|
+
const response = await client.broadcastTx(uint8Array);
|
|
75
73
|
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
return response.transactionHash;
|
|
75
|
+
};
|
|
78
76
|
|
|
79
|
-
|
|
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
|
|
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)
|
|
66
|
-
|
|
67
|
-
if (!
|
|
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)
|
|
71
|
-
|
|
72
|
-
if (
|
|
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
|
|
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
|
|
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
|
|
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)
|
|
105
|
-
|
|
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
|
package/src/keepkey/coins.ts
CHANGED
|
@@ -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
|
|
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)
|
|
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)
|
|
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
|
|
64
|
+
throw new SwapKitError("wallet_keepkey_invalid_params", { reason: "Invalid modifier" });
|
|
59
65
|
}
|
|
60
66
|
}
|
|
61
67
|
}
|
package/src/keepkey/index.ts
CHANGED
|
@@ -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
|
|
48
|
+
const pairingInfo = SKConfig.get("integrations").keepKey;
|
|
49
|
+
if (!pairingInfo) throw new Error("KeepKey config not found");
|
|
48
50
|
|
|
49
|
-
|
|
51
|
+
const initialApiKey = SKConfig.get("apiKeys").keepKey || "1234";
|
|
50
52
|
|
|
51
53
|
await checkAndLaunch();
|
|
52
54
|
|
|
53
|
-
|
|
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
|
|
120
|
+
throw new SwapKitError("wallet_keepkey_chain_not_supported", { chain });
|
|
112
121
|
}
|
|
113
122
|
}
|
|
114
123
|
|
|
115
|
-
// kk-sdk docs: https://
|
|
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 (
|
|
137
|
-
console.error(error);
|
|
145
|
+
} catch (_error) {
|
|
138
146
|
return false;
|
|
139
147
|
}
|
|
140
148
|
}
|
package/src/keepkey-bex/index.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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 };
|
package/src/keplr/index.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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 });
|
package/src/keystore/index.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
14
|
+
throw new SwapKitError("wallet_ledger_invalid_params", { reason: "Path too short" });
|
|
14
15
|
}
|
|
15
16
|
if (path.length > 10) {
|
|
16
|
-
throw new
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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);
|