forked from LedgerHQ/ledger-live-common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckAccountApp.ts
28 lines (27 loc) · 932 Bytes
/
checkAccountApp.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import Transport from "@ledgerhq/hw-transport";
import { WrongDeviceForAccount } from "@ledgerhq/errors";
import getAddress from "./getAddress";
import checkCurrencyApp from "./checkCurrencyApp";
import type { Account, CryptoCurrency } from "../types";
import { isSegwitDerivationMode } from "../derivation";
export default async (
transport: Transport,
account: Account,
currency: CryptoCurrency,
devicePath: string
): Promise<void> => {
await checkCurrencyApp(transport, currency, devicePath);
const { address } = await getAddress(transport, {
derivationMode: account.derivationMode,
devicePath,
currency,
path: account.freshAddressPath,
segwit: isSegwitDerivationMode(account.derivationMode),
});
const { freshAddress } = account;
if (freshAddress !== address) {
throw new WrongDeviceForAccount(`WrongDeviceForAccount ${account.name}`, {
accountName: account.name,
});
}
};