@swapkit/wallets 3.0.0-beta.2 → 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.
- package/dist/chunk-2aa1w78q.js +3 -0
- package/dist/chunk-2aa1w78q.js.map +10 -0
- package/dist/{chunk-p1kdg37m.js → chunk-38ztynv0.js} +1 -1
- package/dist/{chunk-p1kdg37m.js.map → chunk-38ztynv0.js.map} +1 -1
- package/dist/chunk-ebfkk1jn.js +4 -0
- package/dist/{chunk-czhtd6cy.js.map → chunk-ebfkk1jn.js.map} +3 -3
- package/dist/chunk-k9q04afa.js +3 -0
- package/dist/{chunk-qadd75nn.js.map → chunk-k9q04afa.js.map} +3 -3
- 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.cjs +2 -2
- package/dist/src/ctrl/index.cjs.map +3 -3
- package/dist/src/ctrl/index.js +2 -2
- package/dist/src/ctrl/index.js.map +3 -3
- 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 +4 -4
- package/dist/src/keystore/index.js +2 -2
- package/dist/src/keystore/index.js.map +4 -4
- package/dist/src/ledger/index.cjs +3 -3
- package/dist/src/ledger/index.cjs.map +16 -15
- package/dist/src/ledger/index.js +3 -3
- package/dist/src/ledger/index.js.map +16 -15
- 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 +2 -2
- package/dist/src/trezor/index.cjs.map +3 -3
- package/dist/src/trezor/index.js +2 -2
- package/dist/src/trezor/index.js.map +3 -3
- 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 +32 -27
- package/src/bitget/helpers.ts +4 -4
- package/src/coinbase/signer.ts +4 -4
- package/src/cosmostation/index.ts +142 -0
- package/src/ctrl/walletHelpers.ts +82 -70
- package/src/evm-extensions/index.ts +4 -3
- package/src/exodus/index.ts +8 -9
- package/src/keepkey/chains/cosmos.ts +44 -50
- package/src/keepkey/chains/evm.ts +16 -8
- package/src/keepkey/chains/mayachain.ts +3 -2
- package/src/keepkey/chains/thorchain.ts +3 -2
- 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/helpers.ts +2 -4
- package/src/keystore/index.ts +1 -0
- package/src/ledger/clients/cosmos.ts +5 -4
- package/src/ledger/clients/evm.ts +7 -6
- 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/clients/utxo.ts +3 -5
- package/src/ledger/clients/xrp.ts +66 -0
- package/src/ledger/cosmosTypes.ts +14 -10
- package/src/ledger/helpers/getLedgerAddress.ts +12 -3
- package/src/ledger/helpers/getLedgerClient.ts +56 -45
- package/src/ledger/helpers/getLedgerTransport.ts +5 -3
- package/src/ledger/index.ts +18 -7
- package/src/ledger/interfaces/CosmosLedgerInterface.ts +1 -2
- package/src/okx/helpers.ts +11 -9
- package/src/onekey/index.ts +3 -7
- package/src/radix/index.ts +4 -4
- package/src/trezor/evmSigner.ts +4 -4
- package/src/trezor/index.ts +14 -4
- package/src/types.ts +3 -0
- package/src/utils.ts +4 -0
- package/src/walletconnect/evmSigner.ts +6 -2
- package/src/walletconnect/index.ts +4 -4
- package/dist/chunk-bhfpfqc3.js +0 -3
- package/dist/chunk-bhfpfqc3.js.map +0 -10
- package/dist/chunk-czhtd6cy.js +0 -4
- package/dist/chunk-q81hzyra.js +0 -3
- package/dist/chunk-q81hzyra.js.map +0 -10
- package/dist/chunk-qadd75nn.js +0 -3
|
@@ -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";
|
|
@@ -44,11 +45,11 @@ export const mayachainWalletMethods = async ({
|
|
|
44
45
|
sender,
|
|
45
46
|
memo,
|
|
46
47
|
}: SignTransactionParams) => {
|
|
47
|
-
const { makeSignDoc } = await import("@cosmjs/amino");
|
|
48
|
+
const { makeSignDoc } = (await import("@cosmjs/amino")).default;
|
|
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";
|
|
@@ -31,7 +32,7 @@ export const thorchainWalletMethods = async ({
|
|
|
31
32
|
sdk: KeepKeySdk;
|
|
32
33
|
derivationPath?: DerivationPathArray;
|
|
33
34
|
}) => {
|
|
34
|
-
const { makeSignDoc } = await import("@cosmjs/amino");
|
|
35
|
+
const { makeSignDoc } = (await import("@cosmjs/amino")).default;
|
|
35
36
|
const { buildAminoMsg, getDefaultChainFee, createStargateClient, getCosmosToolbox } =
|
|
36
37
|
await import("@swapkit/toolboxes/cosmos");
|
|
37
38
|
|
|
@@ -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/helpers.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createCipheriv, createDecipheriv, pbkdf2Sync, randomBytes } from "node:crypto";
|
|
1
2
|
import { generateMnemonic, validateMnemonic } from "@scure/bip39";
|
|
2
3
|
import { wordlist } from "@scure/bip39/wordlists/english";
|
|
3
4
|
|
|
@@ -15,7 +16,7 @@ export type Keystore = {
|
|
|
15
16
|
};
|
|
16
17
|
|
|
17
18
|
async function blake256(initData: Buffer | string) {
|
|
18
|
-
const { blake2bFinal, blake2bInit, blake2bUpdate } = await import("blakejs");
|
|
19
|
+
const { blake2bFinal, blake2bInit, blake2bUpdate } = (await import("blakejs")).default;
|
|
19
20
|
let data = initData;
|
|
20
21
|
|
|
21
22
|
if (!(data instanceof Buffer)) {
|
|
@@ -32,8 +33,6 @@ async function blake256(initData: Buffer | string) {
|
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
export async function encryptToKeyStore(phrase: string, password: string) {
|
|
35
|
-
const { pbkdf2Sync, randomBytes, createCipheriv } = await import("node:crypto");
|
|
36
|
-
|
|
37
36
|
const cipher = "aes-128-ctr";
|
|
38
37
|
const iv = randomBytes(16);
|
|
39
38
|
const salt = randomBytes(32);
|
|
@@ -71,7 +70,6 @@ export function validatePhrase(phrase: string) {
|
|
|
71
70
|
}
|
|
72
71
|
|
|
73
72
|
export async function decryptFromKeystore(keystore: Keystore, password: string) {
|
|
74
|
-
const { createDecipheriv, pbkdf2Sync } = await import("node:crypto");
|
|
75
73
|
const { SwapKitError } = await import("@swapkit/helpers");
|
|
76
74
|
|
|
77
75
|
switch (keystore.version) {
|
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,11 +62,11 @@ 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
|
-
const { encodeSecp256k1Signature, serializeSignDoc } = await import("@cosmjs/amino");
|
|
68
|
-
const { Secp256k1Signature } = await import("@cosmjs/crypto");
|
|
68
|
+
const { encodeSecp256k1Signature, serializeSignDoc } = (await import("@cosmjs/amino")).default;
|
|
69
|
+
const { Secp256k1Signature } = (await import("@cosmjs/crypto")).default;
|
|
69
70
|
|
|
70
71
|
const message = serializeSignDoc(signDoc);
|
|
71
72
|
const signature = await this.ledgerApp.sign(this.derivationPath, message);
|
|
@@ -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";
|
|
@@ -51,14 +52,14 @@ class EVMLedgerInterface extends AbstractSigner {
|
|
|
51
52
|
|
|
52
53
|
createTransportAndLedger = async () => {
|
|
53
54
|
const transport = await getLedgerTransport();
|
|
54
|
-
const
|
|
55
|
+
const EthereumApp = (await import("@ledgerhq/hw-app-eth")).default;
|
|
55
56
|
|
|
56
57
|
this.ledgerApp = new EthereumApp(transport);
|
|
57
58
|
};
|
|
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);
|
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
import { base64 } from "@scure/base";
|
|
2
|
+
import { SwapKitError } from "@swapkit/helpers";
|
|
2
3
|
|
|
3
4
|
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: any: refactor
|
|
4
5
|
export const getSignature = (signatureArray: any) => {
|
|
5
6
|
// Check Type Length Value encoding
|
|
6
7
|
if (signatureArray.length < 64) {
|
|
7
|
-
throw new
|
|
8
|
+
throw new SwapKitError("wallet_ledger_invalid_signature", { reason: "Too short" });
|
|
8
9
|
}
|
|
9
10
|
if (signatureArray[0] !== 0x30) {
|
|
10
|
-
throw new
|
|
11
|
+
throw new SwapKitError("wallet_ledger_invalid_signature", {
|
|
12
|
+
reason: "TLV encoding: expected first byte 0x30",
|
|
13
|
+
});
|
|
11
14
|
}
|
|
12
15
|
if (signatureArray[1] + 2 !== signatureArray.length) {
|
|
13
|
-
throw new
|
|
16
|
+
throw new SwapKitError("wallet_ledger_invalid_signature", {
|
|
17
|
+
reason: "signature length does not match TLV",
|
|
18
|
+
});
|
|
14
19
|
}
|
|
15
20
|
if (signatureArray[2] !== 0x02) {
|
|
16
|
-
throw new
|
|
21
|
+
throw new SwapKitError("wallet_ledger_invalid_signature", {
|
|
22
|
+
reason: "TLV encoding: expected length type 0x02",
|
|
23
|
+
});
|
|
17
24
|
}
|
|
18
25
|
|
|
19
26
|
// r signature
|
|
@@ -24,7 +31,7 @@ export const getSignature = (signatureArray: any) => {
|
|
|
24
31
|
if (rSignature.length === 33 && rSignature[0] === 0) {
|
|
25
32
|
rSignature = rSignature.slice(1, 33);
|
|
26
33
|
} else if (rSignature.length === 33) {
|
|
27
|
-
throw new
|
|
34
|
+
throw new SwapKitError("wallet_ledger_invalid_signature", { reason: "r too long" });
|
|
28
35
|
}
|
|
29
36
|
|
|
30
37
|
// add leading zero's to pad to 32 bytes
|
|
@@ -34,13 +41,17 @@ export const getSignature = (signatureArray: any) => {
|
|
|
34
41
|
|
|
35
42
|
// s signature
|
|
36
43
|
if (signatureArray[rLength + 4] !== 0x02) {
|
|
37
|
-
throw new
|
|
44
|
+
throw new SwapKitError("wallet_ledger_invalid_signature", {
|
|
45
|
+
reason: "TLV encoding: expected length type 0x02 for s",
|
|
46
|
+
});
|
|
38
47
|
}
|
|
39
48
|
|
|
40
49
|
const sLength = signatureArray[rLength + 5];
|
|
41
50
|
|
|
42
51
|
if (4 + rLength + 2 + sLength !== signatureArray.length) {
|
|
43
|
-
throw new
|
|
52
|
+
throw new SwapKitError("wallet_ledger_invalid_signature", {
|
|
53
|
+
reason: "TLV byte lengths do not match message length",
|
|
54
|
+
});
|
|
44
55
|
}
|
|
45
56
|
|
|
46
57
|
let sSignature = signatureArray.slice(rLength + 6, signatureArray.length);
|
|
@@ -49,7 +60,7 @@ export const getSignature = (signatureArray: any) => {
|
|
|
49
60
|
if (sSignature.length === 33 && sSignature[0] === 0) {
|
|
50
61
|
sSignature = sSignature.slice(1, 33);
|
|
51
62
|
} else if (sSignature.length === 33) {
|
|
52
|
-
throw new
|
|
63
|
+
throw new SwapKitError("wallet_ledger_invalid_signature", { reason: "s too long" });
|
|
53
64
|
}
|
|
54
65
|
|
|
55
66
|
// add leading zero's to pad to 32 bytes
|
|
@@ -58,7 +69,7 @@ export const getSignature = (signatureArray: any) => {
|
|
|
58
69
|
}
|
|
59
70
|
|
|
60
71
|
if (rSignature.length !== 32 || sSignature.length !== 32) {
|
|
61
|
-
throw new
|
|
72
|
+
throw new SwapKitError("wallet_ledger_invalid_signature", { reason: "must be 32 bytes each" });
|
|
62
73
|
}
|
|
63
74
|
|
|
64
75
|
return base64.encode(Buffer.concat([rSignature, sSignature]));
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
getWalletFormatFor,
|
|
8
8
|
} from "@swapkit/helpers";
|
|
9
9
|
import type { UTXOType } from "@swapkit/toolboxes/utxo";
|
|
10
|
-
import type
|
|
10
|
+
import { type Psbt, Transaction } from "bitcoinjs-lib";
|
|
11
11
|
|
|
12
12
|
import { getLedgerTransport } from "../helpers/getLedgerTransport";
|
|
13
13
|
|
|
@@ -22,8 +22,6 @@ const signUTXOTransaction = async (
|
|
|
22
22
|
{ psbt, inputUtxos, btcApp, derivationPath }: Params,
|
|
23
23
|
options?: Partial<CreateTransactionArg>,
|
|
24
24
|
) => {
|
|
25
|
-
const { Transaction } = await import("bitcoinjs-lib");
|
|
26
|
-
|
|
27
25
|
const inputs = inputUtxos.map((item) => {
|
|
28
26
|
const utxoTx = Transaction.fromHex(item.txHex || "");
|
|
29
27
|
const splitTx = btcApp.splitTransaction(utxoTx.toHex(), utxoTx.hasWitnesses());
|
|
@@ -75,7 +73,7 @@ const BaseLedgerUTXO = ({
|
|
|
75
73
|
|
|
76
74
|
async function createTransportWebUSB() {
|
|
77
75
|
transport = await getLedgerTransport();
|
|
78
|
-
const
|
|
76
|
+
const BitcoinApp = (await import("@ledgerhq/hw-app-btc")).default;
|
|
79
77
|
|
|
80
78
|
btcApp = new BitcoinApp({ transport, currency: chain });
|
|
81
79
|
}
|
|
@@ -91,7 +89,7 @@ const BaseLedgerUTXO = ({
|
|
|
91
89
|
return {
|
|
92
90
|
connect: async () => {
|
|
93
91
|
await checkBtcAppAndCreateTransportWebUSB(false);
|
|
94
|
-
const
|
|
92
|
+
const BitcoinApp = (await import("@ledgerhq/hw-app-btc")).default;
|
|
95
93
|
|
|
96
94
|
btcApp = new BitcoinApp({ transport, currency: chain });
|
|
97
95
|
},
|