forked from LedgerHQ/ledger-live-common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getBitcoinLikeInfo.ts
38 lines (35 loc) · 908 Bytes
/
getBitcoinLikeInfo.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
29
30
31
32
33
34
35
36
37
38
import Transport from "@ledgerhq/hw-transport";
// Returns null if getBitcoinLikeInfo is not supported. there are breaking changes in the version after firmware 1.2
const getBitcoinLikeInfo = (
transport: Transport
): Promise<
| {
P2PKH: number;
P2SH: number;
message: Buffer;
short: Buffer;
}
| null
| undefined
> =>
transport.send(0xe0, 0x16, 0x00, 0x00).then((res) => {
const P2PKH = res.readUInt16BE(0);
const P2SH = res.readUInt16BE(2);
try {
const message = res.slice(5, res.readUInt8(4));
const short = res.slice(
5 + message.length + 1,
res.readUInt8(5 + message.length)
);
return {
P2PKH,
P2SH,
message,
short,
};
} catch (e) {
// in such case, we are in an old firmware we no longer support
return null;
}
});
export default getBitcoinLikeInfo;