UNPKG

@aeternity/aepp-sdk

Version:

SDK for the æternity blockchain

76 lines (72 loc) 2.11 kB
import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty"; import AeSdkBase from './AeSdkBase.js'; import { decode } from './utils/encoder.js'; import { UnavailableAccountError } from './utils/errors.js'; export default class AeSdk extends AeSdkBase { /** * @param options - Options */ constructor({ accounts, ...options } = {}) { super(options); _defineProperty(this, "accounts", {}); accounts?.forEach((account, idx) => this.addAccount(account, { select: idx === 0 })); } _resolveAccount(account = this.selectedAddress) { if (typeof account === 'string') { const address = account; decode(address); if (this.accounts[address] == null) throw new UnavailableAccountError(account); account = this.accounts[address]; } return super._resolveAccount(account); } /** * Get accounts addresses * @example addresses() */ addresses() { return Object.keys(this.accounts); } /** * Add specific account * @param account - Account instance * @param options - Options * @param options.select - Select account * @example addAccount(account) */ addAccount(account, { select } = {}) { const { address } = account; this.accounts[address] = account; if (select === true) this.selectAccount(address); } /** * Remove specific account * @param address - Address of account to remove * @example removeAccount(address) */ removeAccount(address) { if (this.accounts[address] == null) throw new UnavailableAccountError(address); delete this.accounts[address]; // eslint-disable-line @typescript-eslint/no-dynamic-delete if (this.selectedAddress === address) delete this.selectedAddress; } /** * Select specific account * @param address - Address of account to select * @example selectAccount('ak_xxxxxxxx') */ selectAccount(address) { decode(address); if (this.accounts[address] == null) throw new UnavailableAccountError(address); this.selectedAddress = address; } } //# sourceMappingURL=AeSdk.js.map