// Goal of this file is to inject all necessary device/signer dependency to coin-modules
import { firstValueFrom, from } from "rxjs";
import Btc from "@ledgerhq/hw-app-btc";
import { createBridges } from "@ledgerhq/coin-bitcoin/bridge/js";
import makeCliTools from "@ledgerhq/coin-bitcoin/cli-transaction";
import bitcoinResolver from "@ledgerhq/coin-bitcoin/hw-getAddress";
import { signMessage } from "@ledgerhq/coin-bitcoin/hw-signMessage";
import { withDevice } from "../../hw/deviceAccess";
import { getCurrencyConfiguration } from "../../config";
const createSigner = (transport, currency) => {
    return new Btc({ transport, currency: currency.id });
};
const signerContext = (deviceId, crypto, fn) => firstValueFrom(withDevice(deviceId)((transport) => from(fn(createSigner(transport, crypto)))));
const getCurrencyConfig = (currency) => {
    return { info: getCurrencyConfiguration(currency) };
};
const bridge = createBridges(signerContext, getCurrencyConfig);
export function createMessageSigner() {
    return (transport, account, messageData) => {
        const signerContext = (_, crypto, fn) => fn(createSigner(transport, crypto));
        return signMessage(signerContext)("", account, messageData);
    };
}
const messageSigner = {
    signMessage: createMessageSigner(),
};
const resolver = (transport, addressOpt) => {
    const signerContext = (_, crypto, fn) => fn(createSigner(transport, crypto));
    return bitcoinResolver(signerContext)("", addressOpt);
};
const cliTools = makeCliTools();
export { bridge, cliTools, resolver, messageSigner, signerContext };
//# sourceMappingURL=setup.js.map