import URL from "url";
import { version as livecommonversion } from "../../../package.json";
import { getEnv } from "@ledgerhq/live-env";
import { createMockSocket, resultMock, secureChannelMock } from "../../socket/socket.mock";
import { log } from "@ledgerhq/logs";
import { createDeviceSocket } from "../../socket";
import { map } from "rxjs/operators";
export function genuineCheckCommand(transport, { targetId, perso }) {
    if (getEnv("MOCK")) {
        return createMockSocket(secureChannelMock(false), resultMock("0000"));
    }
    log("device-command", "genuineCheck", {
        targetId,
        perso,
    });
    return createDeviceSocket(transport, {
        url: URL.format({
            pathname: `${getEnv("BASE_SOCKET_URL")}/genuine`,
            query: {
                targetId,
                perso,
                livecommonversion,
            },
        }),
    }).pipe(map(e => {
        if (e.type === "result") {
            return {
                type: "result",
                payload: String(e.payload || ""),
            };
        }
        return e;
    }));
}
//# sourceMappingURL=genuineCheck.js.map