@swapkit/wallet-hardware 4.2.10 → 4.6.0

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 (96) hide show
  1. package/dist/LICENSE +246 -0
  2. package/dist/{chunk-7fsaymh4.js → chunk-1jexf7qt.js} +3 -3
  3. package/dist/{chunk-7fsaymh4.js.map → chunk-1jexf7qt.js.map} +1 -1
  4. package/dist/chunk-1jpcb30j.js +5 -0
  5. package/dist/{chunk-fazw0jvt.js.map → chunk-1jpcb30j.js.map} +1 -1
  6. package/dist/chunk-4fapcrj9.js +5 -0
  7. package/dist/chunk-4fapcrj9.js.map +10 -0
  8. package/dist/chunk-d54qkn5p.js +4 -0
  9. package/dist/chunk-d54qkn5p.js.map +10 -0
  10. package/dist/chunk-jj2v7mke.js +4 -0
  11. package/dist/chunk-jj2v7mke.js.map +10 -0
  12. package/dist/chunk-p94hfx8x.js +4 -0
  13. package/dist/{chunk-zzfbcc7e.js.map → chunk-p94hfx8x.js.map} +1 -1
  14. package/dist/chunk-skvfn1dg.js +4 -0
  15. package/dist/chunk-skvfn1dg.js.map +10 -0
  16. package/dist/{chunk-37bgpz1y.js → chunk-ybje7f3s.js} +3 -3
  17. package/dist/{chunk-37bgpz1y.js.map → chunk-ybje7f3s.js.map} +1 -1
  18. package/dist/keepkey/index.cjs +2 -2
  19. package/dist/keepkey/index.cjs.map +5 -5
  20. package/dist/keepkey/index.js +2 -2
  21. package/dist/keepkey/index.js.map +5 -5
  22. package/dist/ledger/index.cjs +3 -3
  23. package/dist/ledger/index.cjs.map +11 -10
  24. package/dist/ledger/index.js +3 -3
  25. package/dist/ledger/index.js.map +11 -10
  26. package/dist/trezor/index.cjs +2 -2
  27. package/dist/trezor/index.cjs.map +3 -3
  28. package/dist/trezor/index.js +2 -2
  29. package/dist/trezor/index.js.map +3 -3
  30. package/dist/types/core.d.ts +18 -0
  31. package/dist/types/core.d.ts.map +1 -0
  32. package/dist/types/keepkey/chains/evm.d.ts +2 -2
  33. package/dist/types/keepkey/chains/evm.d.ts.map +1 -1
  34. package/dist/types/keepkey/chains/ripple.d.ts +15 -8
  35. package/dist/types/keepkey/chains/ripple.d.ts.map +1 -1
  36. package/dist/types/keepkey/chains/utxo.d.ts +331 -5
  37. package/dist/types/keepkey/chains/utxo.d.ts.map +1 -1
  38. package/dist/types/keepkey/index.d.ts +3 -3
  39. package/dist/types/keepkey/index.d.ts.map +1 -1
  40. package/dist/types/ledger/clients/evm.d.ts +3 -2
  41. package/dist/types/ledger/clients/evm.d.ts.map +1 -1
  42. package/dist/types/ledger/clients/sui.d.ts +27 -0
  43. package/dist/types/ledger/clients/sui.d.ts.map +1 -0
  44. package/dist/types/ledger/clients/thorchain/lib.d.ts.map +1 -1
  45. package/dist/types/ledger/clients/utxo.d.ts +43 -7
  46. package/dist/types/ledger/clients/utxo.d.ts.map +1 -1
  47. package/dist/types/ledger/clients/xrp.d.ts +2 -2
  48. package/dist/types/ledger/clients/xrp.d.ts.map +1 -1
  49. package/dist/types/ledger/helpers/getLedgerAddress.d.ts.map +1 -1
  50. package/dist/types/ledger/helpers/getLedgerClient.d.ts +4 -1
  51. package/dist/types/ledger/helpers/getLedgerClient.d.ts.map +1 -1
  52. package/dist/types/ledger/index.d.ts +3 -3
  53. package/dist/types/ledger/index.d.ts.map +1 -1
  54. package/dist/types/ledger/types.d.ts +2 -0
  55. package/dist/types/ledger/types.d.ts.map +1 -1
  56. package/dist/types/trezor/evmSigner.d.ts +2 -2
  57. package/dist/types/trezor/evmSigner.d.ts.map +1 -1
  58. package/dist/types/trezor/index.d.ts +3 -3
  59. package/dist/types/trezor/index.d.ts.map +1 -1
  60. package/package.json +51 -40
  61. package/dist/chunk-4k7gb7ss.js +0 -4
  62. package/dist/chunk-4k7gb7ss.js.map +0 -10
  63. package/dist/chunk-93cj7bky.js +0 -4
  64. package/dist/chunk-93cj7bky.js.map +0 -10
  65. package/dist/chunk-fazw0jvt.js +0 -4
  66. package/dist/chunk-zzfbcc7e.js +0 -5
  67. package/src/index.ts +0 -1
  68. package/src/keepkey/chains/cosmos.ts +0 -69
  69. package/src/keepkey/chains/evm.ts +0 -114
  70. package/src/keepkey/chains/mayachain.ts +0 -98
  71. package/src/keepkey/chains/ripple.ts +0 -88
  72. package/src/keepkey/chains/thorchain.ts +0 -93
  73. package/src/keepkey/chains/utxo.ts +0 -137
  74. package/src/keepkey/coins.ts +0 -67
  75. package/src/keepkey/index.ts +0 -155
  76. package/src/ledger/clients/cosmos.ts +0 -84
  77. package/src/ledger/clients/evm.ts +0 -141
  78. package/src/ledger/clients/near.ts +0 -63
  79. package/src/ledger/clients/thorchain/common.ts +0 -93
  80. package/src/ledger/clients/thorchain/helpers.ts +0 -120
  81. package/src/ledger/clients/thorchain/index.ts +0 -87
  82. package/src/ledger/clients/thorchain/lib.ts +0 -278
  83. package/src/ledger/clients/thorchain/utils.ts +0 -69
  84. package/src/ledger/clients/tron.ts +0 -85
  85. package/src/ledger/clients/utxo.ts +0 -154
  86. package/src/ledger/clients/xrp.ts +0 -50
  87. package/src/ledger/cosmosTypes.ts +0 -98
  88. package/src/ledger/helpers/getLedgerAddress.ts +0 -69
  89. package/src/ledger/helpers/getLedgerClient.ts +0 -117
  90. package/src/ledger/helpers/getLedgerTransport.ts +0 -102
  91. package/src/ledger/helpers/index.ts +0 -3
  92. package/src/ledger/index.ts +0 -299
  93. package/src/ledger/interfaces/CosmosLedgerInterface.ts +0 -54
  94. package/src/ledger/types.ts +0 -40
  95. package/src/trezor/evmSigner.ts +0 -177
  96. package/src/trezor/index.ts +0 -349
@@ -1,88 +0,0 @@
1
- import type { KeepKeySdk } from "@keepkey/keepkey-sdk";
2
- import {
3
- Chain,
4
- DerivationPath,
5
- type DerivationPathArray,
6
- derivationPathToString,
7
- type GenericTransferParams,
8
- } from "@swapkit/helpers";
9
- import { getRippleToolbox } from "@swapkit/toolboxes/ripple";
10
- import { bip32ToAddressNList } from "../coins";
11
-
12
- export const rippleWalletMethods = async ({
13
- sdk,
14
- derivationPath,
15
- }: {
16
- sdk: KeepKeySdk;
17
- derivationPath?: DerivationPathArray;
18
- }) => {
19
- // Derivation path handling (default to standard XRP 44'/144'/0'/0/0)
20
- const derivationPathString = derivationPath
21
- ? derivationPathToString(derivationPath)
22
- : `${DerivationPath[Chain.Ripple]}/0`;
23
-
24
- // Fetch address from KeepKey
25
- const { address } = await (sdk as any).address.xrpGetAddress({
26
- address_n: bip32ToAddressNList(derivationPathString),
27
- });
28
-
29
- // Inject minimal signer so toolbox's address helpers work
30
- const signer = {
31
- getAddress: () => Promise.resolve(address),
32
- signTransaction: () => {
33
- throw new Error("signTransaction not supported via toolbox");
34
- },
35
- };
36
-
37
- const toolbox = await getRippleToolbox({ signer });
38
-
39
- const transfer = async ({ recipient, assetValue, memo }: GenericTransferParams) => {
40
- // Build XRPL Payment tx using toolbox helper
41
- const tx = await toolbox.createTransaction({ assetValue, memo, recipient, sender: address });
42
-
43
- // Convert toolbox Payment tx into KeepKey StdTx wrapper (KeepKey-specific format)
44
- const stdTx = {
45
- type: "auth/StdTx",
46
- value: {
47
- fee: { amount: [{ amount: "1000", denom: "drop" }], gas: "28000" },
48
- memo: memo && memo.length > 0 ? memo : "",
49
- msg: [
50
- {
51
- type: "ripple-sdk/MsgSend",
52
- value: { amount: [{ amount: tx.Amount, denom: "drop" }], from_address: address, to_address: recipient },
53
- },
54
- ],
55
- signatures: null,
56
- },
57
- };
58
-
59
- const unsignedTx = {
60
- addressNList: bip32ToAddressNList(derivationPathString),
61
- flags: tx.Flags === 0 ? undefined : tx.Flags,
62
- lastLedgerSequence: tx.LastLedgerSequence?.toString(),
63
- payment: {
64
- amount: tx.Amount,
65
- destination: tx.Destination,
66
- destinationTag: (tx.DestinationTag ?? "0").toString(),
67
- },
68
- sequence: (tx.Sequence ?? 0).toString(),
69
- tx: stdTx,
70
- } as any;
71
-
72
- // Sign with KeepKey
73
- const responseSign = JSON.parse(await (sdk as any).xrp.xrpSignTransaction(unsignedTx));
74
-
75
- // keepkey-sdk may return either { tx_blob } or StdTx with Base64 serializedTx
76
- const txBlob: string | undefined =
77
- (responseSign as any).tx_blob ?? (responseSign as any).value?.signatures?.[0]?.serializedTx;
78
- if (!txBlob) throw new Error("KeepKey XRP sign failed");
79
-
80
- const buffer = Buffer.from(txBlob, "base64");
81
- const txBlobHex = buffer.toString("hex");
82
-
83
- // Broadcast signed tx via toolbox
84
- return toolbox.broadcastTransaction(txBlobHex);
85
- };
86
-
87
- return { ...toolbox, address, getAddress: () => address, transfer };
88
- };
@@ -1,93 +0,0 @@
1
- import type { KeepKeySdk, TypesThorchainSignDocDeposit, TypesThorchainSignDocTransfer } from "@keepkey/keepkey-sdk";
2
- import {
3
- type AssetValue,
4
- Chain,
5
- DerivationPath,
6
- type DerivationPathArray,
7
- derivationPathToString,
8
- type GenericTransferParams,
9
- getRPCUrl,
10
- SwapKitError,
11
- THORConfig,
12
- } from "@swapkit/helpers";
13
- import type { ThorchainDepositParams } from "@swapkit/toolboxes/cosmos";
14
-
15
- import { bip32ToAddressNList } from "../coins";
16
-
17
- type SignTransactionParams = { assetValue: AssetValue; recipient?: string; sender: string; memo: string | undefined };
18
-
19
- export async function thorchainWalletMethods({
20
- sdk,
21
- derivationPath,
22
- }: {
23
- sdk: KeepKeySdk;
24
- derivationPath?: DerivationPathArray;
25
- }): Promise<any> {
26
- const importedAmino = await import("@cosmjs/amino");
27
- const makeSignDoc = importedAmino.makeSignDoc ?? importedAmino.default?.makeSignDoc;
28
- const { buildAminoMsg, getDefaultChainFee, createStargateClient, getCosmosToolbox } = await import(
29
- "@swapkit/toolboxes/cosmos"
30
- );
31
-
32
- const toolbox = await getCosmosToolbox(Chain.THORChain);
33
- const derivationPathString = derivationPath ? derivationPathToString(derivationPath) : `${DerivationPath.THOR}/0`;
34
-
35
- const { address: fromAddress } = (await sdk.address.thorchainGetAddress({
36
- address_n: bip32ToAddressNList(derivationPathString),
37
- })) as { address: string };
38
-
39
- const signTransaction = async ({ assetValue, recipient, sender, memo }: SignTransactionParams) => {
40
- const account = await toolbox.getAccount(sender);
41
- if (!account) throw new SwapKitError("wallet_keepkey_account_not_found");
42
- const { accountNumber, sequence = 0 } = account;
43
-
44
- const isTransfer = recipient && recipient !== "";
45
- const msg = buildAminoMsg({ assetValue, memo, recipient, sender });
46
-
47
- const signDoc = makeSignDoc(
48
- [msg],
49
- getDefaultChainFee(Chain.THORChain),
50
- THORConfig.chainId,
51
- memo,
52
- accountNumber?.toString(),
53
- sequence,
54
- );
55
-
56
- const signedTx = isTransfer
57
- ? await sdk.thorchain.thorchainSignAminoTransfer({
58
- signDoc: signDoc as TypesThorchainSignDocTransfer,
59
- signerAddress: sender,
60
- })
61
- : await sdk.thorchain.thorchainSignAminoDeposit({
62
- signDoc: signDoc as TypesThorchainSignDocDeposit,
63
- signerAddress: sender,
64
- });
65
- const decodedBytes = atob(signedTx.serialized);
66
- return new Uint8Array(decodedBytes.length).map((_, i) => decodedBytes.charCodeAt(i));
67
- };
68
-
69
- const transfer = async ({ assetValue, recipient, memo }: GenericTransferParams) => {
70
- const rpcUrl = await getRPCUrl(Chain.THORChain);
71
- const stargateClient = await createStargateClient(rpcUrl);
72
- const signedTransaction = await signTransaction({ assetValue, memo, recipient, sender: fromAddress });
73
- const { transactionHash } = await stargateClient.broadcastTx(signedTransaction);
74
-
75
- return transactionHash;
76
- };
77
-
78
- const deposit = async ({ assetValue, memo }: ThorchainDepositParams) => {
79
- const rpcUrl = await getRPCUrl(Chain.THORChain);
80
- const stargateClient = await createStargateClient(rpcUrl);
81
- const signedTransaction = await signTransaction({ assetValue, memo, sender: fromAddress });
82
- const { transactionHash } = await stargateClient.broadcastTx(signedTransaction);
83
-
84
- return transactionHash;
85
- };
86
-
87
- // const signMessage = async (message: string) => {
88
- // const stargateClient = await createStargateClient(RPCUrl.THORChain);
89
- // // return signedTx;
90
- // };
91
-
92
- return { ...toolbox, address: fromAddress, deposit, transfer };
93
- }
@@ -1,137 +0,0 @@
1
- import type { KeepKeySdk } from "@keepkey/keepkey-sdk";
2
- import {
3
- Chain,
4
- DerivationPath,
5
- type DerivationPathArray,
6
- derivationPathToString,
7
- FeeOption,
8
- type GenericTransferParams,
9
- SwapKitError,
10
- type UTXOChain,
11
- } from "@swapkit/helpers";
12
- import type { UTXOToolboxes } from "@swapkit/toolboxes/utxo";
13
- import type { Psbt } from "bitcoinjs-lib";
14
- import { bip32ToAddressNList, ChainToKeepKeyName } from "../coins";
15
-
16
- interface KeepKeyInputObject {
17
- addressNList: number[];
18
- scriptType: string;
19
- amount: string;
20
- vout: number;
21
- txid: string;
22
- hex: string;
23
- }
24
-
25
- export async function utxoWalletMethods({
26
- sdk,
27
- chain,
28
- derivationPath,
29
- }: {
30
- sdk: KeepKeySdk;
31
- chain: Exclude<UTXOChain, typeof Chain.Zcash>;
32
- derivationPath?: DerivationPathArray;
33
- }): Promise<
34
- UTXOToolboxes[UTXOChain] & {
35
- address: string;
36
- signTransaction: (psbt: Psbt, inputs: KeepKeyInputObject[], memo?: string) => Promise<string>;
37
- }
38
- > {
39
- const { getUtxoToolbox } = await import("@swapkit/toolboxes/utxo");
40
- // This might not work for BCH
41
- const toolbox = await getUtxoToolbox(chain);
42
- const scriptType = [Chain.Bitcoin, Chain.Litecoin].includes(chain as typeof Chain.Bitcoin)
43
- ? ("p2wpkh" as const)
44
- : ("p2pkh" as const);
45
-
46
- const derivationPathString = derivationPath ? derivationPathToString(derivationPath) : `${DerivationPath[chain]}/0`;
47
-
48
- const addressInfo = {
49
- address_n: bip32ToAddressNList(derivationPathString),
50
- coin: ChainToKeepKeyName[chain],
51
- script_type: scriptType,
52
- };
53
-
54
- const walletAddress: string = (await sdk.address.utxoGetAddress(addressInfo)).address;
55
-
56
- const signTransaction = async (psbt: Psbt, inputs: KeepKeyInputObject[], memo = "") => {
57
- const outputs = psbt.txOutputs
58
- .map((output) => {
59
- const { value, address, change } = output as {
60
- address: string;
61
- script: Buffer;
62
- value: number;
63
- change?: boolean;
64
- };
65
-
66
- const outputAddress =
67
- // @ts-expect-error - stripToCashAddress is not defined in the UTXO toolbox just only on BCH
68
- chain === Chain.BitcoinCash ? toolbox.stripToCashAddress(address) : address;
69
-
70
- if (change || address === walletAddress) {
71
- return {
72
- addressNList: addressInfo.address_n,
73
- addressType: "change",
74
- amount: value,
75
- isChange: true,
76
- scriptType,
77
- };
78
- }
79
-
80
- if (outputAddress) {
81
- return { address: outputAddress, addressType: "spend", amount: value };
82
- }
83
-
84
- return null;
85
- })
86
- .filter(Boolean);
87
-
88
- const removeNullAndEmptyObjectsFromArray = (arr: any[]) => {
89
- return arr.filter((item) => item !== null && typeof item === "object" && Object.keys(item).length > 0);
90
- };
91
-
92
- const responseSign = await sdk.utxo.utxoSignTransaction({
93
- coin: ChainToKeepKeyName[chain],
94
- inputs,
95
- opReturnData: memo,
96
- outputs: removeNullAndEmptyObjectsFromArray(outputs),
97
- });
98
-
99
- return responseSign.serializedTx?.toString();
100
- };
101
-
102
- const transfer = async ({ recipient, feeOptionKey, feeRate, memo, ...rest }: GenericTransferParams) => {
103
- if (!walletAddress)
104
- throw new SwapKitError("wallet_keepkey_invalid_params", { reason: "From address must be provided" });
105
- if (!recipient)
106
- throw new SwapKitError("wallet_keepkey_invalid_params", { reason: "Recipient address must be provided" });
107
-
108
- const createTxMethod =
109
- chain === Chain.BitcoinCash
110
- ? (toolbox as UTXOToolboxes["BCH"]).buildTx
111
- : (toolbox as UTXOToolboxes["BTC"]).createTransaction;
112
-
113
- const { psbt, inputs: rawInputs } = await createTxMethod({
114
- ...rest,
115
- feeRate: feeRate || (await toolbox.getFeeRates())[feeOptionKey || FeeOption.Fast],
116
- fetchTxHex: true,
117
- memo,
118
- recipient,
119
- sender: walletAddress,
120
- });
121
-
122
- const inputs = rawInputs.map(({ value, index, hash, txHex }) => ({
123
- //@TODO don't hardcode master, lookup on blockbook what input this is for and what path that address is!
124
- addressNList: addressInfo.address_n,
125
- amount: value.toString(),
126
- hex: txHex || "",
127
- scriptType,
128
- txid: hash,
129
- vout: index,
130
- }));
131
-
132
- const txHex = await signTransaction(psbt, inputs, memo);
133
- return toolbox.broadcastTx(txHex);
134
- };
135
-
136
- return { ...toolbox, address: walletAddress, signTransaction, transfer };
137
- }
@@ -1,67 +0,0 @@
1
- /*
2
- KeepKey Specific bip32 path conventions
3
- */
4
-
5
- import { SwapKitError } from "@swapkit/helpers";
6
-
7
- const HARDENED = 0x80000000;
8
-
9
- export enum ChainToKeepKeyName {
10
- BTC = "Bitcoin",
11
- BCH = "BitcoinCash",
12
- DOGE = "Dogecoin",
13
- LTC = "Litecoin",
14
- DASH = "Dash",
15
- XRP = "Ripple",
16
- }
17
-
18
- export function addressNListToBIP32(address: number[]) {
19
- return `m/${address.map((num) => (num >= HARDENED ? `${num - HARDENED}'` : num)).join("/")}`;
20
- }
21
-
22
- export function bip32Like(path: string) {
23
- if (path === "m/") return true;
24
-
25
- return /^m(((\/[0-9]+h)+|(\/[0-9]+H)+|(\/[0-9]+')*)((\/[0-9]+)*))$/.test(path);
26
- }
27
-
28
- export function bip32ToAddressNList(initPath: string): number[] {
29
- let path = initPath;
30
-
31
- if (!bip32Like(path)) {
32
- throw new SwapKitError("wallet_keepkey_invalid_params", { reason: `Not a bip32 path: '${path}'` });
33
- }
34
-
35
- if (/^m\//i.test(path)) {
36
- path = path.slice(2);
37
- }
38
- const segments = path.split("/");
39
-
40
- if (segments.length === 1 && segments[0] === "") return [];
41
-
42
- const ret = new Array(segments.length);
43
-
44
- for (let i = 0; i < segments.length; i++) {
45
- // TODO: Check for better way instead of exec
46
- const segment = segments[i];
47
- if (segment) {
48
- const tmp = /(\d+)([hH']?)/.exec(segment);
49
- if (tmp === null) throw new SwapKitError("wallet_keepkey_invalid_params", { reason: "Invalid input" });
50
-
51
- const [, num = "", modifier = ""] = tmp;
52
-
53
- ret[i] = Number.parseInt(num, 10);
54
-
55
- if (ret[i] >= HARDENED)
56
- throw new SwapKitError("wallet_keepkey_invalid_params", { reason: "Invalid child index" });
57
-
58
- if (modifier === "h" || modifier === "H" || modifier === "'") {
59
- ret[i] += HARDENED;
60
- } else if (modifier.length > 0) {
61
- throw new SwapKitError("wallet_keepkey_invalid_params", { reason: "Invalid modifier" });
62
- }
63
- }
64
- }
65
-
66
- return ret;
67
- }
@@ -1,155 +0,0 @@
1
- import { KeepKeySdk } from "@keepkey/keepkey-sdk";
2
- import {
3
- Chain,
4
- type DerivationPathArray,
5
- filterSupportedChains,
6
- NetworkDerivationPath,
7
- SKConfig,
8
- SwapKitError,
9
- WalletOption,
10
- } from "@swapkit/helpers";
11
-
12
- export type { PairingInfo } from "@keepkey/keepkey-sdk";
13
-
14
- import { createWallet, getWalletSupportedChains } from "@swapkit/wallet-core";
15
- import { cosmosWalletMethods } from "./chains/cosmos";
16
- import { KeepKeySigner } from "./chains/evm";
17
- import { mayachainWalletMethods } from "./chains/mayachain";
18
- import { thorchainWalletMethods } from "./chains/thorchain";
19
- import { utxoWalletMethods } from "./chains/utxo";
20
-
21
- export const keepkeyWallet = createWallet({
22
- connect: ({ addChain, supportedChains, walletType }) =>
23
- async function connectKeepkey(chains: Chain[], derivationPathMap?: Record<Chain, DerivationPathArray>) {
24
- const filteredChains = filterSupportedChains({ chains, supportedChains, walletType });
25
- const pairingInfo = SKConfig.get("integrations").keepKey;
26
- if (!pairingInfo) throw new Error("KeepKey config not found");
27
-
28
- const initialApiKey = SKConfig.get("apiKeys").keepKey || "1234";
29
-
30
- await checkAndLaunch();
31
-
32
- // Conform to the expected { apiKey, pairingInfo } structure
33
- const keepkeyConfig = { apiKey: initialApiKey, pairingInfo };
34
- const keepKeySdk = await KeepKeySdk.create(keepkeyConfig);
35
-
36
- // Persist the new API key via SKConfig after pairing
37
- if (keepkeyConfig.apiKey && keepkeyConfig.apiKey !== initialApiKey) {
38
- SKConfig.setApiKey("keepKey", keepkeyConfig.apiKey);
39
- }
40
-
41
- await Promise.all(
42
- filteredChains.map(async (chain) => {
43
- const walletMethods = await getWalletMethods({
44
- chain,
45
- derivationPath: derivationPathMap?.[chain] || NetworkDerivationPath[chain],
46
- sdk: keepKeySdk,
47
- });
48
- const address = (await walletMethods.getAddress()) || "";
49
-
50
- addChain({ ...walletMethods, address, chain, walletType: WalletOption.KEEPKEY });
51
- }),
52
- );
53
- return true;
54
- },
55
- name: "connectKeepkey",
56
- supportedChains: [
57
- Chain.Arbitrum,
58
- Chain.Avalanche,
59
- Chain.Base,
60
- Chain.BinanceSmartChain,
61
- Chain.Bitcoin,
62
- Chain.BitcoinCash,
63
- Chain.Cosmos,
64
- Chain.Dogecoin,
65
- Chain.Dash,
66
- Chain.Ethereum,
67
- Chain.Litecoin,
68
- Chain.Monad,
69
- Chain.Ripple,
70
- Chain.Optimism,
71
- Chain.Polygon,
72
- Chain.THORChain,
73
- Chain.Maya,
74
- Chain.XLayer,
75
- ],
76
- walletType: WalletOption.KEEPKEY,
77
- });
78
-
79
- export const KEEPKEY_SUPPORTED_CHAINS = getWalletSupportedChains(keepkeyWallet);
80
-
81
- async function getWalletMethods({
82
- sdk,
83
- chain,
84
- derivationPath,
85
- }: {
86
- sdk: KeepKeySdk;
87
- chain: Chain;
88
- derivationPath?: DerivationPathArray;
89
- }) {
90
- const { getProvider, getEvmToolbox } = await import("@swapkit/toolboxes/evm");
91
-
92
- switch (chain) {
93
- case Chain.BinanceSmartChain:
94
- case Chain.Arbitrum:
95
- case Chain.Optimism:
96
- case Chain.Polygon:
97
- case Chain.Avalanche:
98
- case Chain.Base:
99
- case Chain.Ethereum:
100
- case Chain.Monad:
101
- case Chain.XLayer: {
102
- const provider = await getProvider(chain);
103
- const signer = new KeepKeySigner({ chain, derivationPath, provider, sdk });
104
- const toolbox = await getEvmToolbox(chain, { provider, signer });
105
-
106
- return toolbox;
107
- }
108
- case Chain.Cosmos: {
109
- return cosmosWalletMethods({ derivationPath, sdk });
110
- }
111
- case Chain.THORChain: {
112
- return thorchainWalletMethods({ derivationPath, sdk });
113
- }
114
- case Chain.Maya: {
115
- return mayachainWalletMethods({ derivationPath, sdk });
116
- }
117
- case Chain.Bitcoin:
118
- case Chain.BitcoinCash:
119
- case Chain.Dash:
120
- case Chain.Dogecoin:
121
- case Chain.Litecoin: {
122
- return utxoWalletMethods({ chain, derivationPath, sdk });
123
- }
124
- case Chain.Ripple: {
125
- const { rippleWalletMethods } = await import("./chains/ripple");
126
- return rippleWalletMethods({ derivationPath, sdk });
127
- }
128
- default:
129
- throw new SwapKitError("wallet_keepkey_chain_not_supported", { chain });
130
- }
131
- }
132
-
133
- // kk-sdk docs: https://keepkey.com/blog/building_on_the_keepkey_sdk
134
- // test spec: if offline, launch keepkey-bridge
135
- async function checkAndLaunch(attempts = 0) {
136
- if (attempts >= 3) {
137
- alert("KeepKey desktop is required for keepkey-sdk, please go to https://keepkey.com/get-started");
138
- }
139
- const isAvailable = await checkKeepkeyAvailability();
140
-
141
- if (!isAvailable) {
142
- window.location.assign("keepkey://launch");
143
- await new Promise((resolve) => setTimeout(resolve, 30000));
144
- await checkAndLaunch(attempts + 1);
145
- }
146
- }
147
-
148
- async function checkKeepkeyAvailability(spec = "http://localhost:1646/spec/swagger.json") {
149
- try {
150
- const response = await fetch(spec);
151
- return response.status === 200;
152
- } catch {
153
- return false;
154
- }
155
- }
@@ -1,84 +0,0 @@
1
- import {
2
- type DerivationPathArray,
3
- derivationPathToString,
4
- NetworkDerivationPath,
5
- SwapKitError,
6
- } from "@swapkit/helpers";
7
- import { CosmosLedgerInterface } from "../interfaces/CosmosLedgerInterface";
8
-
9
- export class CosmosLedger extends CosmosLedgerInterface {
10
- private pubKey: string | null = null;
11
-
12
- derivationPath: string;
13
-
14
- constructor(derivationPath: DerivationPathArray = NetworkDerivationPath.GAIA) {
15
- super();
16
- this.chain = "cosmos";
17
- this.derivationPath = derivationPathToString(derivationPath);
18
- }
19
-
20
- connect = async () => {
21
- await this.checkOrCreateTransportAndLedger(true);
22
- const { publicKey, address } = await this.getAddressAndPubKey();
23
-
24
- this.pubKey = Buffer.from(publicKey, "hex").toString("base64");
25
-
26
- return address;
27
- };
28
-
29
- getAddressAndPubKey = async () => {
30
- await this.checkOrCreateTransportAndLedger(true);
31
-
32
- const response = await this.ledgerApp.getAddress(this.derivationPath, this.chain);
33
-
34
- return response;
35
- };
36
-
37
- signTransaction = async (rawTx: string, sequence = "0") => {
38
- await this.checkOrCreateTransportAndLedger(true);
39
-
40
- const { return_code, error_message, signature } = await this.ledgerApp.sign(this.derivationPath, rawTx);
41
-
42
- if (!this.pubKey) throw new SwapKitError("wallet_ledger_pubkey_not_found");
43
-
44
- this.validateResponse(return_code, error_message);
45
-
46
- return [{ pub_key: { type: "tendermint/PubKeySecp256k1", value: this.pubKey }, sequence, signature }];
47
- };
48
-
49
- signAmino = async (signerAddress: string, signDoc: any): Promise<any> => {
50
- await this.checkOrCreateTransportAndLedger(true);
51
-
52
- const accounts = await this.getAccounts();
53
- const accountIndex = accounts.findIndex((account) => account.address === signerAddress);
54
-
55
- if (accountIndex === -1) {
56
- throw new SwapKitError("wallet_ledger_address_not_found", { address: signerAddress });
57
- }
58
-
59
- const importedAmino = await import("@cosmjs/amino");
60
- const encodeSecp256k1Signature =
61
- importedAmino.encodeSecp256k1Signature ?? importedAmino.default?.encodeSecp256k1Signature;
62
- const serializeSignDoc = importedAmino.serializeSignDoc ?? importedAmino.default?.serializeSignDoc;
63
- const importedCrypto = await import("@cosmjs/crypto");
64
- const Secp256k1Signature = importedCrypto.Secp256k1Signature ?? importedCrypto.default?.Secp256k1Signature;
65
-
66
- const message = serializeSignDoc(signDoc);
67
- const signature = await this.ledgerApp.sign(this.derivationPath, message);
68
-
69
- this.validateResponse(signature.return_code, signature.error_message);
70
-
71
- const secpSignature = Secp256k1Signature.fromDer(signature.signature).toFixedLength();
72
-
73
- return { signature: encodeSecp256k1Signature(accounts[0].pubkey, secpSignature), signed: signDoc };
74
- };
75
-
76
- getAccounts = async () => {
77
- await this.checkOrCreateTransportAndLedger(true);
78
-
79
- const addressAndPubKey = await this.getAddressAndPubKey();
80
- return [
81
- { address: addressAndPubKey.address, algo: "secp256k1", pubkey: Buffer.from(addressAndPubKey.publicKey, "hex") },
82
- ] as any[];
83
- };
84
- }