"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCurrencyExchangeConfig = exports.isExchangeSupportedByApp = void 0;
const semver_1 = require("semver");
const live_env_1 = require("@ledgerhq/live-env");
const ledger_cal_service_1 = __importDefault(require("@ledgerhq/ledger-cal-service"));
// Minimum version of a currency app which has exchange capabilities, meaning it can be used
// for sell/swap, and do silent signing.
const exchangeSupportAppVersions = {
    bitcoin_cash: "1.5.0",
    bitcoin_gold: "1.5.0",
    bitcoin: "1.5.0",
    dash: "1.5.0",
    digibyte: "1.5.0",
    dogecoin: "1.5.0",
    ethereum: "1.4.0",
    litecoin: "1.5.0",
    polkadot: "24.9430.3",
    qtum: "1.5.0",
    ripple: "2.1.0",
    solana: "1.4.0",
    stellar: "3.3.0",
    stratis: "1.5.0",
    tezos: "2.2.13",
    tron: "0.4.100",
    zcash: "1.5.0",
    zencash: "1.5.0",
    sui: "1.2.0",
};
const isExchangeSupportedByApp = (appName, appVersion) => {
    const minVersion = exchangeSupportAppVersions[appName];
    return !!((0, semver_1.valid)(minVersion) && (0, semver_1.valid)(appVersion) && (0, semver_1.gte)(appVersion, minVersion));
};
exports.isExchangeSupportedByApp = isExchangeSupportedByApp;
const getCurrencyExchangeConfig = async (currency) => {
    const env = (0, live_env_1.getEnv)("MOCK_EXCHANGE_TEST_CONFIG") ? "test" : "prod";
    const res = await ledger_cal_service_1.default.findCurrencyData(currency.id, { env });
    if (!res) {
        throw new Error(`Exchange, missing configuration for ${currency.id}`);
    }
    return {
        config: Buffer.from(res.config, "hex"),
        signature: Buffer.from(res.signature, "hex"),
    };
};
exports.getCurrencyExchangeConfig = getCurrencyExchangeConfig;
//# sourceMappingURL=index.js.map