import { getSwapProvider, getAvailableProviders } from "./swap";
import { getSellProvider } from "./sell";
import { getFundProvider } from "./fund";
import { getEnv } from "@ledgerhq/live-env";
export { getSwapProvider, getAvailableProviders };
export function convertToAppExchangePartnerKey(provider) {
    return {
        name: provider.name,
        curve: provider.publicKey.curve,
        publicKey: provider.publicKey.data,
    };
}
export const getProviderConfig = async (exchangeType, provider) => {
    if (getEnv("MOCK_EXCHANGE_TEST_CONFIG") && testProvider) {
        return testProvider;
    }
    const ledgerSignatureEnv = getEnv("MOCK_EXCHANGE_TEST_CONFIG") ? "test" : "prod";
    const partnerSignatureEnv = getEnv("MOCK_EXCHANGE_TEST_PARTNER") ? "test" : "prod";
    switch (exchangeType) {
        case 2 /* ExchangeTypes.Fund */:
        case 5 /* ExchangeTypes.FundNg */:
            return getFundProvider(provider.toLowerCase());
        case 1 /* ExchangeTypes.Sell */:
        case 4 /* ExchangeTypes.SellNg */:
            return await getSellProvider({
                providerId: provider.toLowerCase(),
                ledgerSignatureEnv,
                partnerSignatureEnv,
            });
        default:
            throw new Error(`Unknown partner ${provider} type`);
    }
};
let testProvider;
export 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,
    };
}
export function getTestProviderInfo() {
    return testProvider;
}
export function removeTestProviderInfo() {
    return (testProvider = undefined);
}
//# sourceMappingURL=index.js.map