"use strict";
// Goal of this file is to inject all necessary device/signer dependency to coin-modules
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.resolver = exports.messageSigner = exports.cliTools = exports.bridge = exports.getSolanaSignerInstance = exports.setSolanaLdmkEnabled = void 0;
const js_1 = require("@ledgerhq/coin-solana/bridge/js");
const cli_transaction_1 = __importDefault(require("@ledgerhq/coin-solana/cli-transaction"));
const hw_getAddress_1 = __importDefault(require("@ledgerhq/coin-solana/hw-getAddress"));
const setup_1 = require("../../bridge/setup");
const config_1 = require("../../config");
const currencies_1 = require("../../currencies");
const hw_signMessage_1 = require("@ledgerhq/coin-solana/hw-signMessage");
const live_signer_solana_1 = require("@ledgerhq/live-signer-solana");
const device_management_kit_1 = require("@ledgerhq/device-management-kit");
let _solanaLdmkFFEnabled = false;
let _dmkSignerInstance = null;
// temporary solution to dynamically enable/disable the Solana DMK signer,
// waiting for LIVE-20250 to be implemented
// to be removed together with useFeature("ldmkSolanaSigner")
function setSolanaLdmkEnabled(enabled) {
    _solanaLdmkFFEnabled = enabled;
}
exports.setSolanaLdmkEnabled = setSolanaLdmkEnabled;
const canDMKSignerBeUsed = (transport) => _solanaLdmkFFEnabled &&
    transport.dmk instanceof device_management_kit_1.DeviceManagementKit &&
    typeof transport.sessionId === "string";
// get the same instance if FF gets flipped
function getSolanaSignerInstance(transport) {
    if (canDMKSignerBeUsed(transport)) {
        if (!_dmkSignerInstance) {
            _dmkSignerInstance = new live_signer_solana_1.DmkSignerSol(transport.dmk, transport.sessionId);
        }
        return _dmkSignerInstance;
    }
    else {
        return new live_signer_solana_1.LegacySignerSolana(transport);
    }
}
exports.getSolanaSignerInstance = getSolanaSignerInstance;
const getCurrencyConfig = () => (0, config_1.getCurrencyConfiguration)((0, currencies_1.getCryptoCurrencyById)("solana"));
const bridge = (0, js_1.createBridges)((0, setup_1.executeWithSigner)(getSolanaSignerInstance), getCurrencyConfig);
exports.bridge = bridge;
const messageSigner = {
    signMessage: (0, setup_1.createMessageSigner)(getSolanaSignerInstance, hw_signMessage_1.signMessage),
};
exports.messageSigner = messageSigner;
const resolver = (0, setup_1.createResolver)(getSolanaSignerInstance, hw_getAddress_1.default);
exports.resolver = resolver;
const cliTools = (0, cli_transaction_1.default)();
exports.cliTools = cliTools;
//# sourceMappingURL=setup.js.map