"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.genuineCheckCommand = void 0;
const url_1 = __importDefault(require("url"));
const package_json_1 = require("../../../package.json");
const live_env_1 = require("@ledgerhq/live-env");
const socket_mock_1 = require("../../socket/socket.mock");
const logs_1 = require("@ledgerhq/logs");
const socket_1 = require("../../socket");
const operators_1 = require("rxjs/operators");
function genuineCheckCommand(transport, { targetId, perso }) {
    if ((0, live_env_1.getEnv)("MOCK")) {
        return (0, socket_mock_1.createMockSocket)((0, socket_mock_1.secureChannelMock)(false), (0, socket_mock_1.resultMock)("0000"));
    }
    (0, logs_1.log)("device-command", "genuineCheck", {
        targetId,
        perso,
    });
    return (0, socket_1.createDeviceSocket)(transport, {
        url: url_1.default.format({
            pathname: `${(0, live_env_1.getEnv)("BASE_SOCKET_URL")}/genuine`,
            query: {
                targetId,
                perso,
                livecommonversion: package_json_1.version,
            },
        }),
    }).pipe((0, operators_1.map)(e => {
        if (e.type === "result") {
            return {
                type: "result",
                payload: String(e.payload || ""),
            };
        }
        return e;
    }));
}
exports.genuineCheckCommand = genuineCheckCommand;
//# sourceMappingURL=genuineCheck.js.map