UNPKG

@ledgerhq/live-common

Version:
44 lines 1.99 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.flashMcuOrBootloaderCommand = void 0; const url_1 = __importDefault(require("url")); const package_json_1 = require("../../../../package.json"); const live_env_1 = require("@ledgerhq/live-env"); const logs_1 = require("@ledgerhq/logs"); const socket_1 = require("../../../socket"); const operators_1 = require("rxjs/operators"); const core_1 = require("../core"); const filterProgressEvent = (e) => e.type === "bulk-progress"; /** * Creates a scriptrunner connection with the /mcu API endpoint of the HSM in order to flash the MCU * or the Bootloader of a device (both use the same endpoint with version different parameters) * @param transport The transport object to contact the device * @param param1 The versions details of the MCU or Bootloader to be installed * @returns An observable that emits the events according to the progression of the firmware installation */ function flashMcuOrBootloaderCommand(transport, { targetId, version }) { const tracer = new logs_1.LocalTracer(core_1.LOG_TYPE, { function: "flashMcuOrBootloaderCommand" }); tracer.trace("Starting", { targetId, version, }); return (0, socket_1.createDeviceSocket)(transport, { url: url_1.default.format({ pathname: `${(0, live_env_1.getEnv)("BASE_SOCKET_URL")}/mcu`, query: { targetId, livecommonversion: package_json_1.version, version, }, }), context: tracer.getContext(), }).pipe((0, operators_1.filter)(filterProgressEvent), (0, operators_1.map)(e => ({ type: "progress", progress: e.progress, }))); } exports.flashMcuOrBootloaderCommand = flashMcuOrBootloaderCommand; //# sourceMappingURL=flashMcuOrBootloader.js.map