"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeTestProviderInfo = exports.getTestProviderInfo = exports.setTestProviderInfo = exports.getProviderConfig = exports.convertToAppExchangePartnerKey = exports.getAvailableProviders = exports.getSwapProvider = void 0;
const swap_1 = require("./swap");
Object.defineProperty(exports, "getSwapProvider", { enumerable: true, get: function () { return swap_1.getSwapProvider; } });
Object.defineProperty(exports, "getAvailableProviders", { enumerable: true, get: function () { return swap_1.getAvailableProviders; } });
const sell_1 = require("./sell");
const fund_1 = require("./fund");
const live_env_1 = require("@ledgerhq/live-env");
function convertToAppExchangePartnerKey(provider) {
    return {
        name: provider.name,
        curve: provider.publicKey.curve,
        publicKey: provider.publicKey.data,
    };
}
exports.convertToAppExchangePartnerKey = convertToAppExchangePartnerKey;
const getProviderConfig = async (exchangeType, provider) => {
    if ((0, live_env_1.getEnv)("MOCK_EXCHANGE_TEST_CONFIG") && testProvider) {
        return testProvider;
    }
    const ledgerSignatureEnv = (0, live_env_1.getEnv)("MOCK_EXCHANGE_TEST_CONFIG") ? "test" : "prod";
    const partnerSignatureEnv = (0, live_env_1.getEnv)("MOCK_EXCHANGE_TEST_PARTNER") ? "test" : "prod";
    switch (exchangeType) {
        case 2 /* ExchangeTypes.Fund */:
        case 5 /* ExchangeTypes.FundNg */:
            return (0, fund_1.getFundProvider)(provider.toLowerCase());
        case 1 /* ExchangeTypes.Sell */:
        case 4 /* ExchangeTypes.SellNg */:
            return await (0, sell_1.getSellProvider)({
                providerId: provider.toLowerCase(),
                ledgerSignatureEnv,
                partnerSignatureEnv,
            });
        default:
            throw new Error(`Unknown partner ${provider} type`);
    }
};
exports.getProviderConfig = getProviderConfig;
let testProvider;
function setTestProviderInfo(provider) {
    const { name, publicKey, signature, service } = JSON.parse(provider);
    testProvider = {
        name,
        publicKey: {
            curve: publicKey.curve,
            data: Buffer.from(publicKey.data, "hex"),
        },
        signature: Buffer.from(signature, "hex"),
        version: service.appVersion,
    };
}
exports.setTestProviderInfo = setTestProviderInfo;
function getTestProviderInfo() {
    return testProvider;
}
exports.getTestProviderInfo = getTestProviderInfo;
function removeTestProviderInfo() {
    return (testProvider = undefined);
}
exports.removeTestProviderInfo = removeTestProviderInfo;
//# sourceMappingURL=index.js.map