"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const errors_1 = require("@atomicfinance/errors");
const lodash_1 = require("lodash");
class Wallet {
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    constructor(client) {
        this.client = client;
    }
    /**
     * Get addresses/accounts of the user.
     * @param {number} [startingIndex] - Index to start
     * @param {number} [numAddresses] - Number of addresses to retrieve
     * @param {boolean} [change] - True for change addresses
     * @return {Promise<Address[], InvalidProviderResponseError>} Resolves with a list
     *  of addresses.
     *  Rejects with InvalidProviderResponseError if provider's response is invalid.
     */
    async getAddresses(startingIndex, numAddresses, change) {
        const addresses = await this.client.getMethod('getAddresses')(startingIndex, numAddresses, change);
        if (!(0, lodash_1.isArray)(addresses)) {
            throw new errors_1.InvalidProviderResponseError('Provider returned an invalid response');
        }
        return addresses;
    }
    /**
     * Get used addresses/accounts of the user.
     * @param {number} [numAddressPerCall] - Number of addresses to retrieve per call
     * @return {Promise<Address[], InvalidProviderResponseError>} Resolves with a list
     *  of addresses.
     *  Rejects with InvalidProviderResponseError if provider's response is invalid.
     */
    async getUsedAddresses(numAddressPerCall) {
        return this.client.getMethod('getUsedAddresses')(numAddressPerCall);
    }
    /**
     * Get unused address/account of the user.
     * @param {boolean} [change] - True for change addresses
     * @param {number} [numAddressPerCall] - Number of addresses to retrieve per call
     * @return {Promise<Address, InvalidProviderResponseError>} Resolves with a address
     *  object.
     *  Rejects with InvalidProviderResponseError if provider's response is invalid.
     */
    async getUnusedAddress(change, numAddressPerCall) {
        return this.client.getMethod('getUnusedAddress')(change, numAddressPerCall);
    }
    /**
     * Sign a message.
     * @param {!string} message - Message to be signed.
     * @param {!string} from - The address from which the message is signed.
     * @return {Promise<string>} Resolves with a signed message.
     */
    async signMessage(message, from) {
        return this.client.getMethod('signMessage')(message, from);
    }
    /**
     * Retrieve the network connected to by the wallet
     * @return {Promise<any>} Resolves with the network object
     */
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    async getConnectedNetwork() {
        return this.client.getMethod('getConnectedNetwork')();
    }
    /**
     * Retrieve the availability status of the wallet
     * @return {Promise<Boolean>} True if the wallet is available to use
     */
    async isWalletAvailable() {
        return this.client.getMethod('isWalletAvailable')();
    }
    /**
     * Flag indicating if the wallet allows apps to update transaction fees
     * @return {Promise<Boolean>} True if wallet accepts fee updating
     */
    get canUpdateFee() {
        try {
            return this.client.getMethod('canUpdateFee')();
        }
        catch (e) {
            if (!(e instanceof errors_1.UnimplementedMethodError))
                throw e;
        }
        return true;
    }
    /**
     * Retrieve the private key for the account
     * @return {Promise<string>} Resolves with the key as a string
     */
    exportPrivateKey() {
        return this.client.getMethod('exportPrivateKey')();
    }
    async findAddress(addresses, change = null) {
        return this.client.getMethod('findAddress')(addresses, change);
    }
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    setUnusedAddressesBlacklist(unusedAddressesBlacklist) {
        return this.client.getMethod('setUnusedAddressesBlacklist')(unusedAddressesBlacklist);
    }
    getUnusedAddressesBlacklist() {
        return this.client.getMethod('getUnusedAddressesBlacklist')();
    }
    createMultisig(m, pubkeys) {
        return this.client.getMethod('createMultisig')(m, pubkeys);
    }
    buildMultisigPSBT(m, pubkeys, inputs, outputs) {
        return this.client.getMethod('buildMultisigPSBT')(m, pubkeys, inputs, outputs);
    }
    walletProcessPSBT(psbtString) {
        return this.client.getMethod('walletProcessPSBT')(psbtString);
    }
    finalizePSBT(psbtString) {
        return this.client.getMethod('finalizePSBT')(psbtString);
    }
    async buildSweepTransactionWithSetOutputs(externalChangeAddress, feePerByte, outputs, fixedInputs) {
        return this.client.getMethod('buildSweepTransactionWithSetOutputs')(externalChangeAddress, feePerByte, outputs, fixedInputs);
    }
    async sendSweepTransactionWithSetOutputs(externalChangeAddress, feePerByte, outputs, fixedInputs) {
        return this.client.getMethod('sendSweepTransactionWithSetOutputs')(externalChangeAddress, feePerByte, outputs, fixedInputs);
    }
    async getInputsForAmount(_targets, feePerByte, fixedInputs = [], numAddressPerCall = 100, sweep = false) {
        return this.client.getMethod('getInputsForAmount')(_targets, feePerByte, fixedInputs, numAddressPerCall, sweep);
    }
    async getInputsForDualFunding(collaterals, feePerByte, fixedInputs = [], numAddressPerCall = 100) {
        return this.client.getMethod('getInputsForDualFunding')(collaterals, feePerByte, fixedInputs, numAddressPerCall);
    }
}
exports.default = Wallet;
//# sourceMappingURL=Wallet.js.map