forked from LedgerHQ/ledger-live-common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
installFinalFirmware.ts
49 lines (49 loc) · 1.47 KB
/
installFinalFirmware.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
39
40
41
42
43
44
45
46
47
48
49
import Transport from "@ledgerhq/hw-transport";
import type { DeviceInfo, FinalFirmware } from "../types/manager";
import { Observable, from, concat, of } from "rxjs";
import { mergeMap } from "rxjs/operators";
import ManagerAPI from "../api/Manager";
import getDeviceInfo from "./getDeviceInfo";
import { getProviderId } from "../manager";
export const fetchNextFirmware = (
deviceInfo: DeviceInfo
): Observable<FinalFirmware> =>
from(
ManagerAPI.getDeviceVersion(deviceInfo.targetId, getProviderId(deviceInfo))
).pipe(
mergeMap((device) =>
from(
ManagerAPI.getCurrentOSU({
deviceId: device.id,
version: deviceInfo.version,
provider: getProviderId(deviceInfo),
})
)
),
mergeMap((firmware) =>
from(
ManagerAPI.getFinalFirmwareById(firmware.next_se_firmware_final_version)
)
)
);
export default (transport: Transport): Observable<any> =>
from(getDeviceInfo(transport)).pipe(
mergeMap((deviceInfo) =>
fetchNextFirmware(deviceInfo).pipe(
mergeMap((nextFirmware) =>
concat(
of({
type: "install",
step: "firmware",
}),
ManagerAPI.install(transport, "firmware", {
targetId: deviceInfo.targetId,
firmware: nextFirmware.firmware,
firmwareKey: nextFirmware.firmware_key,
perso: nextFirmware.perso,
})
)
)
)
)
);