// Copyright 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (g && (g = 0, op[0] && (_ = 0)), _) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
import { WalletMethodHandler } from './wallet-method-handler';
import { OutputData, TransactionWithMetadata, SignedTransactionData, PreparedTransaction, PreparedCreateNativeTokenTransactionData, } from '../types/wallet';
import { PreparedTransactionData } from '../client';
import { Output, PreparedCreateNativeTokenTransaction, } from '../types';
import { plainToInstance } from 'class-transformer';
import { bigIntToHex, hexToBigInt } from '../types/utils/hex-encoding';
import { PreparedCreateDelegationTransactionData, } from '../types/wallet';
import { PreparedCreateDelegationTransaction } from '../types/wallet/create-delegation-transaction';
/** The Wallet class. */
var Wallet = /** @class */ (function () {
    /**
     * @param methodHandler The Rust method handler created in `WalletMethodHandler.create()`.
     */
    function Wallet(methodHandler) {
        this.methodHandler = methodHandler;
    }
    /**
     * @param options The wallet options.
     */
    Wallet.create = function (options) {
        return __awaiter(this, void 0, void 0, function () {
            var _a;
            return __generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        _a = Wallet.bind;
                        return [4 /*yield*/, WalletMethodHandler.create(options)];
                    case 1: return [2 /*return*/, new (_a.apply(Wallet, [void 0, _b.sent()]))()];
                }
            });
        });
    };
    /**
     * Backup the data to a Stronghold snapshot.
     */
    Wallet.prototype.backupToStrongholdSnapshot = function (destination, password) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'backupToStrongholdSnapshot',
                            data: {
                                destination: destination,
                                password: password
                            }
                        })];
                    case 1:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    /**
     * Change the Stronghold password.
     */
    Wallet.prototype.changeStrongholdPassword = function (currentPassword, newPassword) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'changeStrongholdPassword',
                            data: {
                                currentPassword: currentPassword,
                                newPassword: newPassword
                            }
                        })];
                    case 1:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    /**
     * Clear the Stronghold password from memory.
     */
    Wallet.prototype.clearStrongholdPassword = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'clearStrongholdPassword'
                        })];
                    case 1:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    /**
     * Destroy the Wallet and drop its database connection.
     */
    Wallet.prototype.destroy = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, this.methodHandler.destroy()];
            });
        });
    };
    /**
     * Emit a provided event for testing of the event system.
     */
    Wallet.prototype.emitTestEvent = function (event) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'emitTestEvent',
                            data: { event: event }
                        })];
                    case 1:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    /**
     * Get client.
     */
    Wallet.prototype.getClient = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, this.methodHandler.getClient()];
            });
        });
    };
    /**
     * Get secret manager.
     */
    Wallet.prototype.getSecretManager = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, this.methodHandler.getSecretManager()];
            });
        });
    };
    /**
     * Get the status for a Ledger Nano.
     */
    Wallet.prototype.getLedgerNanoStatus = function () {
        return __awaiter(this, void 0, void 0, function () {
            var response;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'getLedgerNanoStatus'
                        })];
                    case 1:
                        response = _a.sent();
                        return [2 /*return*/, JSON.parse(response).payload];
                }
            });
        });
    };
    /**
     * Check if the Stronghold password has been set.
     */
    Wallet.prototype.isStrongholdPasswordAvailable = function () {
        return __awaiter(this, void 0, void 0, function () {
            var response;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'isStrongholdPasswordAvailable'
                        })];
                    case 1:
                        response = _a.sent();
                        return [2 /*return*/, JSON.parse(response).payload];
                }
            });
        });
    };
    /**
     * Listen to wallet events with a callback. An empty array will listen to all possible events.
     */
    Wallet.prototype.listen = function (eventTypes, callback) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, this.methodHandler.listen(eventTypes, callback)];
            });
        });
    };
    /**
     * Clear the callbacks for provided events. An empty array will clear all listeners.
     */
    Wallet.prototype.clearListeners = function (eventTypes) {
        return __awaiter(this, void 0, void 0, function () {
            var response;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'clearListeners',
                            data: { eventTypes: eventTypes }
                        })];
                    case 1:
                        response = _a.sent();
                        return [2 /*return*/, JSON.parse(response).payload];
                }
            });
        });
    };
    /**
     * Restore a backup from a Stronghold file
     * Replaces client_options, coin_type, secret_manager and accounts. Returns an error if accounts were already created
     * If Stronghold is used as secret_manager, the existing Stronghold file will be overwritten. If a mnemonic was
     * stored, it will be gone.
     * if ignore_if_coin_type_mismatch is provided client options will not be restored
     * if ignore_if_coin_type_mismatch == true, client options coin type and accounts will not be restored if the cointype doesn't match
     * If a bech32 hrp is provided to ignore_if_bech32_hrp_mismatch, that doesn't match the one of the current address, the wallet will not be restored.
     */
    Wallet.prototype.restoreFromStrongholdSnapshot = function (source, password, ignoreIfCoinTypeMismatch, ignoreIfBech32Mismatch) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'restoreFromStrongholdSnapshot',
                            data: {
                                source: source,
                                password: password,
                                ignoreIfCoinTypeMismatch: ignoreIfCoinTypeMismatch,
                                ignoreIfBech32Mismatch: ignoreIfBech32Mismatch
                            }
                        })];
                    case 1:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    /**
     * Set ClientOptions.
     */
    Wallet.prototype.setClientOptions = function (clientOptions) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'setClientOptions',
                            data: { clientOptions: clientOptions }
                        })];
                    case 1:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    /**
     * Set the Stronghold password.
     */
    Wallet.prototype.setStrongholdPassword = function (password) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'setStrongholdPassword',
                            data: { password: password }
                        })];
                    case 1:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    /**
     * Set the interval after which the Stronghold password gets cleared from memory.
     */
    Wallet.prototype.setStrongholdPasswordClearInterval = function (intervalInMilliseconds) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'setStrongholdPasswordClearInterval',
                            data: { intervalInMilliseconds: intervalInMilliseconds }
                        })];
                    case 1:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    /**
     * Start the background syncing process for all accounts.
     */
    Wallet.prototype.startBackgroundSync = function (options, intervalInMilliseconds) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'startBackgroundSync',
                            data: {
                                options: options,
                                intervalInMilliseconds: intervalInMilliseconds
                            }
                        })];
                    case 1:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    /**
     * Stop the background syncing process for all accounts.
     */
    Wallet.prototype.stopBackgroundSync = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'stopBackgroundSync'
                        })];
                    case 1:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    /**
     * Store a mnemonic in the Stronghold snapshot.
     */
    Wallet.prototype.storeMnemonic = function (mnemonic) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'storeMnemonic',
                            data: { mnemonic: mnemonic }
                        })];
                    case 1:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    /**
     * Update the authentication for the provided node.
     */
    Wallet.prototype.updateNodeAuth = function (url, auth) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'updateNodeAuth',
                            data: { url: url, auth: auth }
                        })];
                    case 1:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    /**
     * Returns the accounts of the wallet.
     *
     * @returns The accounts of the wallet.
     */
    Wallet.prototype.accounts = function () {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'accounts'
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, plainToInstance(OutputData, parsed.payload)];
                }
            });
        });
    };
    /**
     * A generic function that can be used to burn native tokens, nfts, foundries and accounts.
     * @param burn The outputs or native tokens to burn
     * @param transactionOptions Additional transaction options.
     * @returns The transaction.
     */
    Wallet.prototype.burn = function (burn, transactionOptions) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.prepareBurn(burn, transactionOptions)];
                    case 1: return [2 /*return*/, (_a.sent()).send()];
                }
            });
        });
    };
    /**
     * A generic function that can be used to prepare to burn native tokens, nfts, foundries and accounts.
     * @param burn The outputs or native tokens to burn
     * @param transactionOptions Additional transaction options
     * @returns The prepared transaction.
     */
    Wallet.prototype.prepareBurn = function (burn, transactionOptions) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'prepareBurn',
                            data: {
                                burn: burn,
                                options: transactionOptions
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, new PreparedTransaction(plainToInstance(PreparedTransactionData, parsed.payload), this)];
                }
            });
        });
    };
    /**
     * Burn native tokens. This doesn't require the foundry output which minted them, but will not increase
     * the foundries `melted_tokens` field, which makes it impossible to destroy the foundry output. Therefore it's
     * recommended to use melting, if the foundry output is available.
     * @param tokenId The native token id.
     * @param burnAmount The to be burned amount.
     * @param transactionOptions Additional transaction options.
     * @returns The prepared transaction.
     */
    Wallet.prototype.prepareBurnNativeToken = function (tokenId, burnAmount, transactionOptions) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'prepareBurn',
                            data: {
                                burn: {
                                    nativeTokens: new Map([[tokenId, burnAmount]])
                                },
                                options: transactionOptions
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, new PreparedTransaction(plainToInstance(PreparedTransactionData, parsed.payload), this)];
                }
            });
        });
    };
    /**
     * Burn an nft output.
     * @param nftId The NftId.
     * @param transactionOptions Additional transaction options.
     * @returns The prepared transaction.
     */
    Wallet.prototype.prepareBurnNft = function (nftId, transactionOptions) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'prepareBurn',
                            data: {
                                burn: {
                                    nfts: [nftId]
                                },
                                options: transactionOptions
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, new PreparedTransaction(plainToInstance(PreparedTransactionData, parsed.payload), this)];
                }
            });
        });
    };
    /**
     * Claim basic or nft outputs that have additional unlock conditions
     * to their `AddressUnlockCondition` from the wallet.
     * @param outputIds The outputs to claim.
     * @returns The resulting transaction.
     */
    Wallet.prototype.claimOutputs = function (outputIds) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.prepareClaimOutputs(outputIds)];
                    case 1: return [2 /*return*/, (_a.sent()).send()];
                }
            });
        });
    };
    /**
     * Claim basic or nft outputs that have additional unlock conditions
     * to their `AddressUnlockCondition` from the wallet.
     * @param outputIds The outputs to claim.
     * @returns The prepared transaction.
     */
    Wallet.prototype.prepareClaimOutputs = function (outputIds) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'prepareClaimOutputs',
                            data: {
                                outputIdsToClaim: outputIds
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, new PreparedTransaction(plainToInstance(PreparedTransactionData, parsed.payload), this)];
                }
            });
        });
    };
    /**
     * Consolidate basic outputs with only an `AddressUnlockCondition` from a wallet
     * by sending them to an own address again if the output amount is greater or
     * equal to the output consolidation threshold.
     * @param params Consolidation options.
     * @returns The consolidation transaction.
     */
    Wallet.prototype.consolidateOutputs = function (params) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.prepareConsolidateOutputs(params)];
                    case 1: return [2 /*return*/, (_a.sent()).send()];
                }
            });
        });
    };
    /**
     * Consolidate basic outputs with only an `AddressUnlockCondition` from a wallet
     * by sending them to an own address again if the output amount is greater or
     * equal to the output consolidation threshold.
     * @param params Consolidation options.
     * @returns The prepared consolidation transaction.
     */
    Wallet.prototype.prepareConsolidateOutputs = function (params) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'prepareConsolidateOutputs',
                            data: {
                                params: params
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, new PreparedTransaction(plainToInstance(PreparedTransactionData, parsed.payload), this)];
                }
            });
        });
    };
    /**
     * Creates an account output.
     * @param params The account output options.
     * @param transactionOptions Additional transaction options.
     * @returns The transaction.
     */
    Wallet.prototype.createAccountOutput = function (params, transactionOptions) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.prepareCreateAccountOutput(params, transactionOptions)];
                    case 1: return [2 /*return*/, (_a.sent()).send()];
                }
            });
        });
    };
    /**
     * Creates an account output.
     * @param params The account output options.
     * @param transactionOptions Additional transaction options.
     * @returns The prepared transaction.
     */
    Wallet.prototype.prepareCreateAccountOutput = function (params, transactionOptions) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'prepareCreateAccountOutput',
                            data: {
                                params: params,
                                options: transactionOptions
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, new PreparedTransaction(plainToInstance(PreparedTransactionData, parsed.payload), this)];
                }
            });
        });
    };
    /**
     * Melt native tokens. This happens with the foundry output which minted them, by increasing its
     * `melted_tokens` field.
     * @param tokenId The native token id.
     * @param meltAmount To be melted amount.
     * @param transactionOptions Additional transaction options.
     * @returns The transaction.
     */
    Wallet.prototype.meltNativeToken = function (tokenId, meltAmount, transactionOptions) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.prepareMeltNativeToken(tokenId, meltAmount, transactionOptions)];
                    case 1: return [2 /*return*/, (_a.sent()).send()];
                }
            });
        });
    };
    /**
     * Melt native tokens. This happens with the foundry output which minted them, by increasing its
     * `melted_tokens` field.
     * @param tokenId The native token id.
     * @param meltAmount To be melted amount.
     * @param transactionOptions Additional transaction options.
     * @returns The prepared transaction.
     */
    Wallet.prototype.prepareMeltNativeToken = function (tokenId, meltAmount, transactionOptions) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'prepareMeltNativeToken',
                            data: {
                                tokenId: tokenId,
                                meltAmount: bigIntToHex(meltAmount),
                                options: transactionOptions
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, new PreparedTransaction(plainToInstance(PreparedTransactionData, parsed.payload), this)];
                }
            });
        });
    };
    /**
     * Deregister a participation event.
     *
     * @param eventId The id of the participation event to deregister.
     */
    Wallet.prototype.deregisterParticipationEvent = function (eventId) {
        return __awaiter(this, void 0, void 0, function () {
            var response;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'deregisterParticipationEvent',
                            data: {
                                eventId: eventId
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        return [2 /*return*/, JSON.parse(response).payload];
                }
            });
        });
    };
    /**
     * Destroy an account output.
     *
     * @param accountId The AccountId.
     * @param transactionOptions Additional transaction options.
     * @returns The prepared transaction.
     */
    Wallet.prototype.prepareDestroyAccount = function (accountId, transactionOptions) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'prepareBurn',
                            data: {
                                burn: {
                                    accounts: [accountId]
                                },
                                options: transactionOptions
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, new PreparedTransaction(plainToInstance(PreparedTransactionData, parsed.payload), this)];
                }
            });
        });
    };
    /**
     * Function to destroy a foundry output with a circulating supply of 0.
     * Native tokens in the foundry (minted by other foundries) will be transacted to the controlling account.
     * @param foundryId The FoundryId.
     * @param transactionOptions Additional transaction options.
     * @returns The prepared transaction.
     */
    Wallet.prototype.prepareDestroyFoundry = function (foundryId, transactionOptions) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'prepareBurn',
                            data: {
                                burn: {
                                    foundries: [foundryId]
                                },
                                options: transactionOptions
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, new PreparedTransaction(plainToInstance(PreparedTransactionData, parsed.payload), this)];
                }
            });
        });
    };
    /**
     * Get the account balance.
     *
     * @returns The account balance.
     */
    Wallet.prototype.getBalance = function () {
        return __awaiter(this, void 0, void 0, function () {
            var response, payload;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'getBalance'
                        })];
                    case 1:
                        response = _a.sent();
                        payload = JSON.parse(response).payload;
                        return [2 /*return*/, this.adjustBalancePayload(payload)];
                }
            });
        });
    };
    /**
     * Converts hex encoded or decimal strings of amounts to `bigint`
     * for the balance payload.
     */
    Wallet.prototype.adjustBalancePayload = function (payload) {
        for (var i = 0; i < payload.nativeTokens.length; i++) {
            payload.nativeTokens[i].total = hexToBigInt(payload.nativeTokens[i].total);
            payload.nativeTokens[i].available = hexToBigInt(payload.nativeTokens[i].available);
        }
        payload.baseCoin.total = BigInt(payload.baseCoin.total);
        payload.baseCoin.available = BigInt(payload.baseCoin.available);
        payload.requiredStorageDeposit.account = BigInt(payload.requiredStorageDeposit.account);
        payload.requiredStorageDeposit.basic = BigInt(payload.requiredStorageDeposit.basic);
        payload.requiredStorageDeposit.foundry = BigInt(payload.requiredStorageDeposit.foundry);
        payload.requiredStorageDeposit.nft = BigInt(payload.requiredStorageDeposit.nft);
        return payload;
    };
    /**
     * Get the data for an output.
     * @param outputId The output to get.
     * @returns The `OutputData`.
     */
    Wallet.prototype.getOutput = function (outputId) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'getOutput',
                            data: {
                                outputId: outputId
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, plainToInstance(OutputData, parsed.payload)];
                }
            });
        });
    };
    /**
     * Get a participation event.
     *
     * @param eventId The ID of the event to get.
     */
    Wallet.prototype.getParticipationEvent = function (eventId) {
        return __awaiter(this, void 0, void 0, function () {
            var response;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'getParticipationEvent',
                            data: {
                                eventId: eventId
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        return [2 /*return*/, JSON.parse(response).payload];
                }
            });
        });
    };
    /**
     * Get IDs of participation events of a certain type.
     *
     * @param node The node to get events from.
     * @param eventType The type of events to get.
     */
    Wallet.prototype.getParticipationEventIds = function (node, eventType) {
        return __awaiter(this, void 0, void 0, function () {
            var response;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'getParticipationEventIds',
                            data: {
                                node: node,
                                eventType: eventType
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        return [2 /*return*/, JSON.parse(response).payload];
                }
            });
        });
    };
    /**
     * Get all participation events.
     */
    Wallet.prototype.getParticipationEvents = function () {
        return __awaiter(this, void 0, void 0, function () {
            var response;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'getParticipationEvents'
                        })];
                    case 1:
                        response = _a.sent();
                        return [2 /*return*/, JSON.parse(response).payload];
                }
            });
        });
    };
    /**
     * Get the participation event status by its ID.
     *
     * @param eventId The ID of the event status to get.
     */
    Wallet.prototype.getParticipationEventStatus = function (eventId) {
        return __awaiter(this, void 0, void 0, function () {
            var response;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'getParticipationEventStatus',
                            data: {
                                eventId: eventId
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        return [2 /*return*/, JSON.parse(response).payload];
                }
            });
        });
    };
    /**
     * Get a `FoundryOutput` by native token ID. It will try to get the foundry from
     * the account, if it isn't in the wallet it will try to get it from the node.
     *
     * @param tokenId The native token ID to get the foundry for.
     * @returns The `FoundryOutput` that minted the token.
     */
    Wallet.prototype.getFoundryOutput = function (tokenId) {
        return __awaiter(this, void 0, void 0, function () {
            var response;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'getFoundryOutput',
                            data: {
                                tokenId: tokenId
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        return [2 /*return*/, Output.parse(JSON.parse(response).payload)];
                }
            });
        });
    };
    /**
     * Get outputs with additional unlock conditions.
     *
     * @param outputs The type of outputs to claim.
     * @returns The output IDs of the unlockable outputs.
     */
    Wallet.prototype.claimableOutputs = function (outputs) {
        return __awaiter(this, void 0, void 0, function () {
            var response;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'claimableOutputs',
                            data: {
                                outputsToClaim: outputs
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        return [2 /*return*/, JSON.parse(response).payload];
                }
            });
        });
    };
    /**
     * Get a transaction stored in the wallet.
     *
     * @param transactionId The ID of the transaction to get.
     * @returns The transaction.
     */
    Wallet.prototype.getTransaction = function (transactionId) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'getTransaction',
                            data: {
                                transactionId: transactionId
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, plainToInstance(TransactionWithMetadata, parsed.payload)];
                }
            });
        });
    };
    /**
     * Get the transaction with inputs of an incoming transaction stored in the wallet
     * List might not be complete, if the node pruned the data already
     *
     * @param transactionId The ID of the transaction to get.
     * @returns The transaction.
     */
    Wallet.prototype.getIncomingTransaction = function (transactionId) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'getIncomingTransaction',
                            data: {
                                transactionId: transactionId
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, plainToInstance(TransactionWithMetadata, parsed.payload)];
                }
            });
        });
    };
    /**
     * Get the address of the wallet.
     *
     * @returns The address.
     */
    Wallet.prototype.address = function () {
        return __awaiter(this, void 0, void 0, function () {
            var response;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'getAddress'
                        })];
                    case 1:
                        response = _a.sent();
                        return [2 /*return*/, JSON.parse(response).payload];
                }
            });
        });
    };
    /**
     * List all outputs of the wallet.
     *
     * @param filterOptions Options to filter the to be returned outputs.
     * @returns The outputs with metadata.
     */
    Wallet.prototype.outputs = function (filterOptions) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'outputs',
                            data: { filterOptions: filterOptions }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, plainToInstance(OutputData, parsed.payload)];
                }
            });
        });
    };
    /**
     * List all the pending transactions of the wallet.
     *
     * @returns The transactions.
     */
    Wallet.prototype.pendingTransactions = function () {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'pendingTransactions'
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, plainToInstance(TransactionWithMetadata, parsed.payload)];
                }
            });
        });
    };
    /**
     * Returns the implicit account creation address of the wallet if it is Ed25519 based.
     *
     * @returns The implicit account creation address.
     */
    Wallet.prototype.implicitAccountCreationAddress = function () {
        return __awaiter(this, void 0, void 0, function () {
            var response;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'implicitAccountCreationAddress'
                        })];
                    case 1:
                        response = _a.sent();
                        return [2 /*return*/, JSON.parse(response).payload];
                }
            });
        });
    };
    /**
     * Transitions an implicit account to an account.
     *
     * @param outputId Identifier of the implicit account output.
     * @returns The created transaction.
     */
    Wallet.prototype.implicitAccountTransition = function (outputId) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.prepareImplicitAccountTransition(outputId)];
                    case 1: return [2 /*return*/, (_a.sent()).send()];
                }
            });
        });
    };
    /**
     * Prepares to transition an implicit account to an account.
     *
     * @param outputId Identifier of the implicit account output.
     * @returns The prepared transaction.
     */
    Wallet.prototype.prepareImplicitAccountTransition = function (outputId) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'prepareImplicitAccountTransition',
                            data: { outputId: outputId }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, new PreparedTransaction(plainToInstance(PreparedTransactionData, parsed.payload), this)];
                }
            });
        });
    };
    /**
     * Returns the implicit accounts of the wallet.
     *
     * @returns The implicit accounts of the wallet.
     */
    Wallet.prototype.implicitAccounts = function () {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'implicitAccounts'
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, plainToInstance(OutputData, parsed.payload)];
                }
            });
        });
    };
    /**
     * List all incoming transactions of the wallet.
     *
     * @returns The incoming transactions with their inputs.
     */
    Wallet.prototype.incomingTransactions = function () {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'incomingTransactions'
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, plainToInstance(TransactionWithMetadata, parsed.payload)];
                }
            });
        });
    };
    /**
     * List all the transactions of the wallet.
     *
     * @returns The transactions.
     */
    Wallet.prototype.transactions = function () {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'transactions'
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, plainToInstance(TransactionWithMetadata, parsed.payload)];
                }
            });
        });
    };
    /**
     * List all the unspent outputs of the wallet.
     *
     * @param filterOptions Options to filter the to be returned outputs.
     * @returns The outputs with metadata.
     */
    Wallet.prototype.unspentOutputs = function (filterOptions) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'unspentOutputs',
                            data: { filterOptions: filterOptions }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, plainToInstance(OutputData, parsed.payload)];
                }
            });
        });
    };
    /**
     * Mint additional native tokens.
     *
     * @param tokenId The native token id.
     * @param mintAmount To be minted amount.
     * @param transactionOptions Additional transaction options.
     * @returns The minting transaction.
     */
    Wallet.prototype.mintNativeToken = function (tokenId, mintAmount, transactionOptions) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.prepareMintNativeToken(tokenId, mintAmount, transactionOptions)];
                    case 1: return [2 /*return*/, (_a.sent()).send()];
                }
            });
        });
    };
    /**
     * Mint additional native tokens.
     *
     * @param tokenId The native token id.
     * @param mintAmount To be minted amount.
     * @param transactionOptions Additional transaction options.
     * @returns The prepared minting transaction.
     */
    Wallet.prototype.prepareMintNativeToken = function (tokenId, mintAmount, transactionOptions) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'prepareMintNativeToken',
                            data: {
                                tokenId: tokenId,
                                mintAmount: bigIntToHex(mintAmount),
                                options: transactionOptions
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, new PreparedTransaction(plainToInstance(PreparedTransactionData, parsed.payload), this)];
                }
            });
        });
    };
    /**
     * Create a native token.
     *
     * @param params The options for creating a native token.
     * @param transactionOptions Additional transaction options.
     * @returns The created transaction.
     */
    Wallet.prototype.createNativeToken = function (params, transactionOptions) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.prepareCreateNativeToken(params, transactionOptions)];
                    case 1: return [2 /*return*/, (_a.sent()).send()];
                }
            });
        });
    };
    /**
     * Create a native token.
     *
     * @param params The options for creating a native token.
     * @param transactionOptions Additional transaction options.
     * @returns The created transaction and the token ID.
     */
    Wallet.prototype.prepareCreateNativeToken = function (params, transactionOptions) {
        return __awaiter(this, void 0, void 0, function () {
            var adjustedParams, response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        adjustedParams = params;
                        adjustedParams.circulatingSupply = bigIntToHex(params.circulatingSupply);
                        adjustedParams.maximumSupply = bigIntToHex(params.maximumSupply);
                        return [4 /*yield*/, this.methodHandler.callMethod({
                                name: 'prepareCreateNativeToken',
                                data: {
                                    params: adjustedParams,
                                    options: transactionOptions
                                }
                            })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, new PreparedCreateNativeTokenTransaction(plainToInstance(PreparedCreateNativeTokenTransactionData, parsed.payload), this)];
                }
            });
        });
    };
    /**
     * Mint NFTs.
     *
     * @param params The options for minting nfts.
     * @param transactionOptions Additional transaction options.
     * @returns The minting transaction.
     */
    Wallet.prototype.mintNfts = function (params, transactionOptions) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.prepareMintNfts(params, transactionOptions)];
                    case 1: return [2 /*return*/, (_a.sent()).send()];
                }
            });
        });
    };
    /**
     * Mint NFTs.
     *
     * @param params The options for minting nfts.
     * @param transactionOptions Additional transaction options.
     * @returns The prepared minting transaction.
     */
    Wallet.prototype.prepareMintNfts = function (params, transactionOptions) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'prepareMintNfts',
                            data: {
                                params: params,
                                options: transactionOptions
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, new PreparedTransaction(plainToInstance(PreparedTransactionData, parsed.payload), this)];
                }
            });
        });
    };
    /**
     * Prepare an output for sending, useful for offline signing.
     *
     * @param options The options for preparing an output. If the amount is
     * below the minimum required storage deposit, by default the remaining
     * amount will automatically be added with a `StorageDepositReturn` `UnlockCondition`,
     * when setting the `ReturnStrategy` to `gift`, the full minimum required
     * storage deposit will be sent to the recipient. When the assets contain
     * an nft id, the data from the existing `NftOutput` will be used, just with
     * the address unlock conditions replaced.
     * @param transactionOptions Additional transaction options.
     * @returns The prepared output.
     */
    Wallet.prototype.prepareOutput = function (params, transactionOptions) {
        return __awaiter(this, void 0, void 0, function () {
            var response;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        if (typeof params.amount === 'bigint') {
                            params.amount = params.amount.toString(10);
                        }
                        return [4 /*yield*/, this.methodHandler.callMethod({
                                name: 'prepareOutput',
                                data: {
                                    params: params,
                                    transactionOptions: transactionOptions
                                }
                            })];
                    case 1:
                        response = _a.sent();
                        return [2 /*return*/, Output.parse(JSON.parse(response).payload)];
                }
            });
        });
    };
    /**
     * Prepare to send base coins, useful for offline signing.
     *
     * @param params Address with amounts to send.
     * @param options Additional transaction options.
     * @returns The prepared transaction data.
     */
    Wallet.prototype.prepareSend = function (params, options) {
        return __awaiter(this, void 0, void 0, function () {
            var i, response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        for (i = 0; i < params.length; i++) {
                            if (typeof params[i].amount === 'bigint') {
                                params[i].amount = params[i].amount.toString(10);
                            }
                        }
                        return [4 /*yield*/, this.methodHandler.callMethod({
                                name: 'prepareSend',
                                data: {
                                    params: params,
                                    options: options
                                }
                            })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, new PreparedTransaction(plainToInstance(PreparedTransactionData, parsed.payload), this)];
                }
            });
        });
    };
    /**
     * Create a delegation.
     *
     * @param params The options for creating a delegation.
     * @param transactionOptions Additional transaction options.
     * @returns The created transaction and the delegation ID.
     */
    Wallet.prototype.createDelegation = function (params, transactionOptions) {
        return __awaiter(this, void 0, void 0, function () {
            var tx, delegationId, transaction;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.prepareCreateDelegation(params, transactionOptions)];
                    case 1:
                        tx = _a.sent();
                        delegationId = tx.delegationId();
                        return [4 /*yield*/, tx.send()];
                    case 2:
                        transaction = _a.sent();
                        return [2 /*return*/, {
                                delegationId: delegationId,
                                transaction: transaction
                            }];
                }
            });
        });
    };
    /**
     * Prepare a transaction to create a delegation.
     *
     * @param params The options for creating a delegation.
     * @param transactionOptions Additional transaction options.
     * @returns The prepared transaction and the delegation ID.
     */
    Wallet.prototype.prepareCreateDelegation = function (params, transactionOptions) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'prepareCreateDelegation',
                            data: {
                                params: params,
                                options: transactionOptions
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, new PreparedCreateDelegationTransaction(plainToInstance(PreparedCreateDelegationTransactionData, parsed.payload), this)];
                }
            });
        });
    };
    /**
     * Delay a delegation's claiming.
     *
     * @param delegationId The id of the delegation to delay.
     * @param reclaimExcess Indicates whether excess value over the minimum storage requirements
     * will be moved to a basic output that is unlockable by the same address which controls the delegation.
     * Otherwise it will be added to a new delegation. In this manner, one can delegate for one epoch at a time and
     * never lose out on any rewards.
     * @returns The created transaction.
     */
    Wallet.prototype.delayDelegationClaiming = function (delegationId, reclaimExcess) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.prepareDelayDelegationClaiming(delegationId, reclaimExcess)];
                    case 1: return [2 /*return*/, (_a.sent()).send()];
                }
            });
        });
    };
    /**
     * Prepare a transaction to delay a delegation's claiming.
     *
     * @param delegationId The id of the delegation to delay.
     * @param reclaimExcess Whether any excess funds should be reclaimed, or put into a new delegation.
     * @returns The prepared transaction.
     */
    Wallet.prototype.prepareDelayDelegationClaiming = function (delegationId, reclaimExcess) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'prepareDelayDelegationClaiming',
                            data: {
                                delegationId: delegationId,
                                reclaimExcess: reclaimExcess
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, new PreparedTransaction(plainToInstance(PreparedTransactionData, parsed.payload), this)];
                }
            });
        });
    };
    /**
     * Begin staking.
     *
     * @param params The options for beginning staking.
     * @param transactionOptions Additional transaction options.
     * @returns The created transaction.
     */
    Wallet.prototype.beginStaking = function (params, transactionOptions) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.prepareBeginStaking(params, transactionOptions)];
                    case 1: return [4 /*yield*/, (_a.sent()).send()];
                    case 2: return [2 /*return*/, _a.sent()];
                }
            });
        });
    };
    /**
     * Prepare a transaction to begin staking.
     *
     * @param params The options for beginning staking.
     * @param transactionOptions Additional transaction options.
     * @returns The prepared transaction.
     */
    Wallet.prototype.prepareBeginStaking = function (params, transactionOptions) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'prepareBeginStaking',
                            data: {
                                params: params,
                                options: transactionOptions
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, new PreparedTransaction(plainToInstance(PreparedTransactionData, parsed.payload), this)];
                }
            });
        });
    };
    /**
     * Extend staking period.
     *
     * @param accountId The ID of the staking account.
     * @param additionalEpochs The number of epochs to add to the staking period.
     * @returns The created transaction.
     */
    Wallet.prototype.extendStaking = function (accountId, additionalEpochs) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.prepareExtendStaking(accountId, additionalEpochs)];
                    case 1: return [4 /*yield*/, (_a.sent()).send()];
                    case 2: return [2 /*return*/, _a.sent()];
                }
            });
        });
    };
    /**
     * Prepare a transaction to extend a staking period.
     *
     * @param accountId The ID of the staking account.
     * @param additionalEpochs The number of epochs to add to the staking period.
     * @returns The prepared transaction.
     */
    Wallet.prototype.prepareExtendStaking = function (accountId, additionalEpochs) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'prepareExtendStaking',
                            data: {
                                accountId: accountId,
                                additionalEpochs: additionalEpochs
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, new PreparedTransaction(plainToInstance(PreparedTransactionData, parsed.payload), this)];
                }
            });
        });
    };
    /**
     * End staking and claim rewards.
     *
     * @param accountId The ID of the staking account.
     * @returns The created transaction.
     */
    Wallet.prototype.endStaking = function (accountId) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.prepareEndStaking(accountId)];
                    case 1: return [4 /*yield*/, (_a.sent()).send()];
                    case 2: return [2 /*return*/, _a.sent()];
                }
            });
        });
    };
    /**
     * Prepare a transaction to end staking and claim rewards.
     *
     * @param accountId The ID of the staking account.
     * @returns The prepared transaction.
     */
    Wallet.prototype.prepareEndStaking = function (accountId) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'prepareEndStaking',
                            data: {
                                accountId: accountId
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, new PreparedTransaction(plainToInstance(PreparedTransactionData, parsed.payload), this)];
                }
            });
        });
    };
    /**
     * Announce a staking account's candidacy for the staking period.
     *
     * @param accountId The ID of the account to announce candidacy.
     * @returns The submitted block ID.
     */
    Wallet.prototype.announceCandidacy = function (accountId) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'announceCandidacy',
                            data: {
                                accountId: accountId
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, parsed.payload];
                }
            });
        });
    };
    /**
     * Send outputs in a transaction.
     *
     * @param outputs The outputs to send.
     * @param transactionOptions Additional transaction options.
     * @returns The sent transaction.
     */
    Wallet.prototype.sendOutputs = function (outputs, options) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.prepareSendOutputs(outputs, options)];
                    case 1: return [2 /*return*/, (_a.sent()).send()];
                }
            });
        });
    };
    /**
     * Prepare a transaction, useful for offline signing.
     *
     * @param outputs Outputs to use in the transaction.
     * @param options Additional transaction options.
     * @returns The prepared transaction data.
     */
    Wallet.prototype.prepareSendOutputs = function (outputs, options) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'prepareSendOutputs',
                            data: {
                                outputs: outputs,
                                options: options
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, new PreparedTransaction(plainToInstance(PreparedTransactionData, parsed.payload), this)];
                }
            });
        });
    };
    /**
     * Register participation events.
     *
     * @param options Options to register participation events.
     * @returns A mapping between event IDs and their corresponding event data.
     */
    Wallet.prototype.registerParticipationEvents = function (options) {
        return __awaiter(this, void 0, void 0, function () {
            var response;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'registerParticipationEvents',
                            data: {
                                options: options
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        return [2 /*return*/, JSON.parse(response).payload];
                }
            });
        });
    };
    /**
     * Checks the transaction state for a provided transaction id until it's accepted. Interval in milliseconds.
     */
    Wallet.prototype.waitForTransactionAcceptance = function (transactionId, interval, maxAttempts) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'waitForTransactionAcceptance',
                            data: {
                                transactionId: transactionId,
                                interval: interval,
                                maxAttempts: maxAttempts
                            }
                        })];
                    case 1:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    /**
     * Send base coins to an address.
     *
     * @param amount Amount of coins.
     * @param address Receiving address.
     * @param transactionOptions Additional transaction options.
     * @returns The sent transaction.
     */
    Wallet.prototype.send = function (amount, address, transactionOptions) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        if (typeof amount === 'bigint') {
                            amount = amount.toString(10);
                        }
                        return [4 /*yield*/, this.prepareSend([{ address: address, amount: amount }], transactionOptions)];
                    case 1: return [2 /*return*/, (_a.sent()).send()];
                }
            });
        });
    };
    /**
     * Send base coins with amounts from input addresses.
     *
     * @param params Addresses with amounts.
     * @param transactionOptions Additional transaction options.
     * @returns The sent transaction.
     */
    Wallet.prototype.sendWithParams = function (params, transactionOptions) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.prepareSend(params, transactionOptions)];
                    case 1: return [2 /*return*/, (_a.sent()).send()];
                }
            });
        });
    };
    /**
     * Send native tokens.
     *
     * @param params Addresses amounts and native tokens.
     * @param transactionOptions Additional transaction options.
     * @returns The transaction.
     */
    Wallet.prototype.sendNativeTokens = function (params, transactionOptions) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.prepareSendNativeTokens(params, transactionOptions)];
                    case 1: return [2 /*return*/, (_a.sent()).send()];
                }
            });
        });
    };
    /**
     * Send native tokens.
     *
     * @param params Addresses amounts and native tokens.
     * @param transactionOptions Additional transaction options.
     * @returns The prepared transaction.
     */
    Wallet.prototype.prepareSendNativeTokens = function (params, transactionOptions) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'prepareSendNativeTokens',
                            data: {
                                params: params,
                                options: transactionOptions
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, new PreparedTransaction(plainToInstance(PreparedTransactionData, parsed.payload), this)];
                }
            });
        });
    };
    /**
     * Send NFT.
     *
     * @param params Addresses and nft ids.
     * @param transactionOptions Additional transaction options.
     * @returns The transaction.
     */
    Wallet.prototype.sendNft = function (params, transactionOptions) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.prepareSendNft(params, transactionOptions)];
                    case 1: return [2 /*return*/, (_a.sent()).send()];
                }
            });
        });
    };
    /**
     * Send NFT.
     *
     * @param params Addresses and nft ids.
     * @param transactionOptions Additional transaction options.
     * @returns The prepared transaction.
     */
    Wallet.prototype.prepareSendNft = function (params, transactionOptions) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'prepareSendNft',
                            data: {
                                params: params,
                                options: transactionOptions
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, new PreparedTransaction(plainToInstance(PreparedTransactionData, parsed.payload), this)];
                }
            });
        });
    };
    /**
     * Send mana.
     *
     * @param params Amount, Address, and Return Strategy.
     * @param transactionOptions Additional transaction options.
     * @returns The sent transaction.
     */
    Wallet.prototype.sendMana = function (params, transactionOptions) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.prepareSendMana(params, transactionOptions)];
                    case 1: return [2 /*return*/, (_a.sent()).send()];
                }
            });
        });
    };
    /**
     * Prepare to send mana.
     *
     * @param params Amount, Address, and Return Strategy.
     * @param transactionOptions Additional transaction options.
     * @returns The prepared transaction.
     */
    Wallet.prototype.prepareSendMana = function (params, transactionOptions) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'prepareSendMana',
                            data: {
                                params: params,
                                options: transactionOptions
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, new PreparedTransaction(plainToInstance(PreparedTransactionData, parsed.payload), this)];
                }
            });
        });
    };
    /**
     * Set the alias for the account
     *
     * @param alias The account alias to set.
     */
    Wallet.prototype.setAlias = function (alias) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'setAlias',
                            data: {
                                alias: alias
                            }
                        })];
                    case 1:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    /**
     * Set the fallback SyncOptions for account syncing.
     * If storage is enabled, will persist during restarts.
     *
     * @param options The sync options to set.
     */
    Wallet.prototype.setDefaultSyncOptions = function (options) {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'setDefaultSyncOptions',
                            data: {
                                options: options
                            }
                        })];
                    case 1:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    /**
     * Sign a prepared transaction, useful for offline signing.
     *
     * @param preparedTransactionData The prepared transaction data to sign.
     * @returns The signed transaction.
     */
    Wallet.prototype.signTransaction = function (preparedTransactionData) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'signTransaction',
                            data: {
                                preparedTransactionData: preparedTransactionData
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, plainToInstance(SignedTransactionData, parsed.payload)];
                }
            });
        });
    };
    /**
     * Sign a prepared transaction, and send it.
     *
     * @param preparedTransactionData The prepared transaction data to sign and submit.
     * @returns The transaction.
     */
    Wallet.prototype.signAndSubmitTransaction = function (preparedTransactionData) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'signAndSubmitTransaction',
                            data: {
                                preparedTransactionData: preparedTransactionData
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, plainToInstance(TransactionWithMetadata, parsed.payload)];
                }
            });
        });
    };
    /**
     * Validate the transaction, submit it to a node and store it in the wallet.
     *
     * @param signedTransactionData A signed transaction to submit and store.
     * @returns The sent transaction.
     */
    Wallet.prototype.submitAndStoreTransaction = function (signedTransactionData) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'submitAndStoreTransaction',
                            data: {
                                signedTransactionData: signedTransactionData
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, plainToInstance(TransactionWithMetadata, parsed.payload)];
                }
            });
        });
    };
    /**
     * Sync the account by fetching new information from the nodes.
     * Will also reissue pending transactions if necessary.
     * A custom default can be set using setDefaultSyncOptions.
     *
     * @param options Optional synchronization options.
     * @returns The account balance.
     */
    Wallet.prototype.sync = function (options) {
        return __awaiter(this, void 0, void 0, function () {
            var response, payload;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'sync',
                            data: {
                                options: options
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        payload = JSON.parse(response).payload;
                        return [2 /*return*/, this.adjustBalancePayload(payload)];
                }
            });
        });
    };
    /**
     * Prepare a vote.
     *
     * @param eventId The participation event ID.
     * @param answers Answers for a voting event, can be empty.
     * @returns An instance of `PreparedTransaction`.
     */
    Wallet.prototype.prepareVote = function (eventId, answers) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'prepareVote',
                            data: {
                                eventId: eventId,
                                answers: answers
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, new PreparedTransaction(plainToInstance(PreparedTransactionData, parsed.payload), this)];
                }
            });
        });
    };
    /**
     * Prepare stop participating in an event.
     *
     * @param eventId The event ID to stop participating in.
     * @returns An instance of `PreparedTransaction`.
     */
    Wallet.prototype.prepareStopParticipating = function (eventId) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'prepareStopParticipating',
                            data: {
                                eventId: eventId
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, new PreparedTransaction(plainToInstance(PreparedTransactionData, parsed.payload), this)];
                }
            });
        });
    };
    /**
     * Calculates the voting overview of a wallet.
     *
     * @param eventIds Optional, filters participations only for provided events.
     * @returns An instance of `ParticipationOverview`
     */
    Wallet.prototype.getParticipationOverview = function (eventIds) {
        return __awaiter(this, void 0, void 0, function () {
            var response;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'getParticipationOverview',
                            data: {
                                eventIds: eventIds
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        return [2 /*return*/, JSON.parse(response).payload];
                }
            });
        });
    };
    /**
     * Prepare to increase the voting power.
     *
     * @param amount The amount to increase the voting power by.
     * @returns An instance of `PreparedTransaction`.
     */
    Wallet.prototype.prepareIncreaseVotingPower = function (amount) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'prepareIncreaseVotingPower',
                            data: {
                                amount: amount
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, new PreparedTransaction(plainToInstance(PreparedTransactionData, parsed.payload), this)];
                }
            });
        });
    };
    /**
     * Prepare to decrease the voting power.
     *
     * @param amount The amount to decrease the voting power by.
     * @returns An instance of `PreparedTransaction`.
     */
    Wallet.prototype.prepareDecreaseVotingPower = function (amount) {
        return __awaiter(this, void 0, void 0, function () {
            var response, parsed;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, this.methodHandler.callMethod({
                            name: 'prepareDecreaseVotingPower',
                            data: {
                                amount: amount
                            }
                        })];
                    case 1:
                        response = _a.sent();
                        parsed = JSON.parse(response);
                        return [2 /*return*/, new PreparedTransaction(plainToInstance(PreparedTransactionData, parsed.payload), this)];
                }
            });
        });
    };
    return Wallet;
}());
export { Wallet };
//# sourceMappingURL=wallet.js.map