From: Chris Duncan Date: Sat, 11 Apr 2026 20:47:57 +0000 (-0700) Subject: Remove promises from account methods where possible. X-Git-Tag: v0.12.0~5^2~2 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=6b0615c895922ce0038fa9bedfb96b67f7b80390;p=libnemo.git Remove promises from account methods where possible. --- diff --git a/src/lib/account/index.ts b/src/lib/account/index.ts index 425458e..5c5e2ff 100644 --- a/src/lib/account/index.ts +++ b/src/lib/account/index.ts @@ -17,11 +17,11 @@ type KeyPair = { } /** -* Represents a single Nano address and the associated public key. To include the -* matching private key, it must be known at the time of object instantiation. -* The frontier, balance, and representative for the account can also be set or -* be fetched from the network. -*/ + * Represents a single Nano address and the associated public key. To include + * the matching private key, it must be known at the time of object + * instantiation. The frontier, balance, and representative for the account can + * also be set or be fetched from the network. + */ export class Account { [key: string]: any @@ -122,9 +122,9 @@ export class Account { } /** - * Releases variable references to allow garbage collection. - */ - async destroy (): Promise { + * Releases variable references to allow garbage collection. + */ + destroy (): void { this.#address = undefined this.#index = undefined this.#publicKey.fill(0) @@ -173,96 +173,67 @@ export class Account { } /** - * Instantiates an Account object from its Nano address. - * - * @param {string} address - Address of the account - * @returns {Account} A new Account object - */ + * Instantiates an Account object from its Nano address. + * @param {string} address - Address of the account + * @returns {Account} A new Account object + */ static load (address: string): Account /** - * Instantiates Account objects from their Nano addresses. - * - * @param {string[]} addresses - Addresses of the accounts - * @returns {Account[]} Array of new Account objects - */ + * Instantiates Account objects from their Nano addresses. + * @param {string[]} addresses - Addresses of the accounts + * @returns {Account[]} Array of new Account objects + */ static load (addresses: string[]): Account[] /** - * Instantiates an Account object from its public key. It is unable to sign - * blocks or messages since it has no private key. - * - * @param {string | Uint8Array} publicKey - Public key of the account - * @returns {Account} A new Account object - */ + * Instantiates an Account object from its public key. It is unable to sign + * blocks or messages since it has no private key. + * @param {string | Uint8Array} publicKey - Public key of the account + * @returns {Account} A new Account object + */ static load (publicKey: string | Uint8Array): Account /** - * Instantiates Account objects from their public keys. They are unable to sign - * blocks or messages since they have no private key. - * - * @param {string | Uint8Array[]} publicKeys - Public keys of the accounts - * @returns {Account[]} Array of new Account objects - */ + * Instantiates Account objects from their public keys. They are unable to sign + * blocks or messages since they have no private key. + * @param {string | Uint8Array[]} publicKeys - Public keys of the accounts + * @returns {Account[]} Array of new Account objects + */ static load (publicKeys: string | Uint8Array[]): Account[] /** - * Instantiates an Account object from its public key. It is unable to sign - * blocks or messages since it has no private key. - * - * @param {KeyPair} keypair - Index and keys of the account - * @returns {Account} A new Account object - */ + * Instantiates an Account object from its public key. It is unable to sign + * blocks or messages since it has no private key. + * @param {KeyPair} keypair - Index and keys of the account + * @returns {Account} A new Account object + */ static load (keypair: KeyPair): Account /** - * Instantiates Account objects from their public keys. They are unable to sign - * blocks or messages since they have no private key. - * - * @param {KeyPair[]} keypairs - Indexes and keys of the accounts - * @returns {Account[]} Array of new Account objects - */ + * Instantiates Account objects from their public keys. They are unable to sign + * blocks or messages since they have no private key. + * @param {KeyPair[]} keypairs - Indexes and keys of the accounts + * @returns {Account[]} Array of new Account objects + */ static load (keypairs: KeyPair[]): Account[] /** - * Instantiates an Account object from its private key which is used to derive - * a public key and then discarded. - * - * @param {KeyPair} keypair - Index and key of the account - * @param {string} type - Indicates a private key - * @returns {Promise} Promise for a new Account object - */ - static async load (keypair: KeyPair, type: 'private'): Promise - /** - * Instantiates Account objects from their private keys which are used to - * derive public keys and then discarded. - * - * @param {KeyPair[]} keypairs - Indexes and keys of the accounts - * @param {string} type - Indicates private keys - * @returns {Promise} Promise for array of new Account objects - */ - static async load (keypairs: KeyPair[], type: 'private'): Promise - /** - * Instantiates Account objects from their private keys which are used to - * derive public keys and then discarded. - * - * @param {(string | Uint8Array | KeyPair | (string | Uint8Array | KeyPair)[])} input - Indexes and keys of the accounts - * @param {'private'} [type] - Indicates private keys - * @returns {(Account | Account[] | Promise)} Promise for array of new Account objects - */ - static load (input: string | Uint8Array | KeyPair | (string | Uint8Array | KeyPair)[], type?: 'private'): Account | Account[] | Promise { + * Instantiates Account objects from their private keys which are used to + * derive public keys and then discarded. + * @param {(string | Uint8Array | KeyPair | (string | Uint8Array | KeyPair)[])} input - Indexes and keys of the accounts + * @returns {(Account | Account[])} Array of new Account objects + */ + static load (input: string | Uint8Array | KeyPair | (string | Uint8Array | KeyPair)[], type?: 'private'): Account | Account[] { const isInputArray = Array.isArray(input) const inputs = isInputArray ? input : [input] if (this.#isKeyPairs(inputs) && type === 'private') { - return this.#fromPrivate(inputs) - .then(r => isInputArray ? r : r[0]) + const r = this.#fromPrivate(inputs) + return isInputArray ? r : r[0] } else { return isInputArray ? this.#fromPublic(inputs) : this.#fromPublic(inputs)[0] } } /** - * Refreshes the account from its current state on the network. - * - * A successful response sets the balance, frontier, and representative - * properties. - * - * @param {(Rpc | string | URL)} rpc - RPC node information required to call `account_info` - */ + * Refreshes the account from its current state on the network. A successful + * response sets the balance, frontier, and representative properties. + * @param {(Rpc | string | URL)} rpc - RPC node information required to call `account_info` + */ async refresh (rpc: Rpc | string | URL): Promise { return await _refresh(this, rpc) } @@ -285,7 +256,7 @@ export class Account { * @param {KeyPair} keypairs - Indexes and keys of the accounts * @returns {Promise} Promise for new Account objects */ - static async #fromPrivate (keypairs: KeyPair[]): Promise { + static #fromPrivate (keypairs: KeyPair[]): Account[] { try { const accounts: Account[] = [] for (let keypair of keypairs) {