]> git.codecow.com Git - libnemo.git/commitdiff
Remove promises from account methods where possible.
authorChris Duncan <chris@zoso.dev>
Sat, 11 Apr 2026 20:47:57 +0000 (13:47 -0700)
committerChris Duncan <chris@zoso.dev>
Sat, 11 Apr 2026 20:47:57 +0000 (13:47 -0700)
src/lib/account/index.ts

index 425458e64d40fa96c89843c28b923bf5f3e39dfa..5c5e2ffb1e38b030a740e290b56146f6095dc1e8 100644 (file)
@@ -17,11 +17,11 @@ type KeyPair = {
 }\r
 \r
 /**\r
-* Represents a single Nano address and the associated public key. To include the\r
-* matching private key, it must be known at the time of object instantiation.\r
-* The frontier, balance, and representative for the account can also be set or\r
-* be fetched from the network.\r
-*/\r
+ * Represents a single Nano address and the associated public key. To include\r
+ * the matching private key, it must be known at the time of object\r
+ * instantiation. The frontier, balance, and representative for the account can\r
+ * also be set or be fetched from the network.\r
+ */\r
 export class Account {\r
        [key: string]: any\r
 \r
@@ -122,9 +122,9 @@ export class Account {
        }\r
 \r
        /**\r
-       * Releases variable references to allow garbage collection.\r
-       */\r
-       async destroy (): Promise<void> {\r
+        * Releases variable references to allow garbage collection.\r
+        */\r
+       destroy (): void {\r
                this.#address = undefined\r
                this.#index = undefined\r
                this.#publicKey.fill(0)\r
@@ -173,96 +173,67 @@ export class Account {
        }\r
 \r
        /**\r
-       * Instantiates an Account object from its Nano address.\r
-       *\r
-       * @param {string} address - Address of the account\r
-       * @returns {Account} A new Account object\r
-       */\r
+        * Instantiates an Account object from its Nano address.\r
+        * @param {string} address - Address of the account\r
+        * @returns {Account} A new Account object\r
+        */\r
        static load (address: string): Account\r
        /**\r
-       * Instantiates Account objects from their Nano addresses.\r
-       *\r
-       * @param {string[]} addresses - Addresses of the accounts\r
-       * @returns {Account[]} Array of new Account objects\r
-       */\r
+        * Instantiates Account objects from their Nano addresses.\r
+        * @param {string[]} addresses - Addresses of the accounts\r
+        * @returns {Account[]} Array of new Account objects\r
+        */\r
        static load (addresses: string[]): Account[]\r
        /**\r
-       * Instantiates an Account object from its public key. It is unable to sign\r
-       * blocks or messages since it has no private key.\r
-       *\r
-       * @param {string | Uint8Array<ArrayBuffer>} publicKey - Public key of the account\r
-       * @returns {Account} A new Account object\r
-       */\r
+        * Instantiates an Account object from its public key. It is unable to sign\r
+        * blocks or messages since it has no private key.\r
+        * @param {string | Uint8Array<ArrayBuffer>} publicKey - Public key of the account\r
+        * @returns {Account} A new Account object\r
+        */\r
        static load (publicKey: string | Uint8Array<ArrayBuffer>): Account\r
        /**\r
-       * Instantiates Account objects from their public keys. They are unable to sign\r
-       * blocks or messages since they have no private key.\r
-       *\r
-       * @param {string | Uint8Array<ArrayBuffer>[]} publicKeys - Public keys of the accounts\r
-       * @returns {Account[]} Array of new Account objects\r
-       */\r
+        * Instantiates Account objects from their public keys. They are unable to sign\r
+        * blocks or messages since they have no private key.\r
+        * @param {string | Uint8Array<ArrayBuffer>[]} publicKeys - Public keys of the accounts\r
+        * @returns {Account[]} Array of new Account objects\r
+        */\r
        static load (publicKeys: string | Uint8Array<ArrayBuffer>[]): Account[]\r
        /**\r
-       * Instantiates an Account object from its public key. It is unable to sign\r
-       * blocks or messages since it has no private key.\r
-       *\r
-       * @param {KeyPair} keypair - Index and keys of the account\r
-       * @returns {Account} A new Account object\r
-       */\r
+        * Instantiates an Account object from its public key. It is unable to sign\r
+        * blocks or messages since it has no private key.\r
+        * @param {KeyPair} keypair - Index and keys of the account\r
+        * @returns {Account} A new Account object\r
+        */\r
        static load (keypair: KeyPair): Account\r
        /**\r
-       * Instantiates Account objects from their public keys. They are unable to sign\r
-       * blocks or messages since they have no private key.\r
-       *\r
-       * @param {KeyPair[]} keypairs - Indexes and keys of the accounts\r
-       * @returns {Account[]} Array of new Account objects\r
-       */\r
+        * Instantiates Account objects from their public keys. They are unable to sign\r
+        * blocks or messages since they have no private key.\r
+        * @param {KeyPair[]} keypairs - Indexes and keys of the accounts\r
+        * @returns {Account[]} Array of new Account objects\r
+        */\r
        static load (keypairs: KeyPair[]): Account[]\r
        /**\r
-       * Instantiates an Account object from its private key which is used to derive\r
-       * a public key and then discarded.\r
-       *\r
-       * @param {KeyPair} keypair - Index and key of the account\r
-       * @param {string} type - Indicates a private key\r
-       * @returns {Promise<Account>} Promise for a new Account object\r
-       */\r
-       static async load (keypair: KeyPair, type: 'private'): Promise<Account>\r
-       /**\r
-       * Instantiates Account objects from their private keys which are used to\r
-       * derive public keys and then discarded.\r
-       *\r
-       * @param {KeyPair[]} keypairs - Indexes and keys of the accounts\r
-       * @param {string} type - Indicates private keys\r
-       * @returns {Promise<Account[]>} Promise for array of new Account objects\r
-       */\r
-       static async load (keypairs: KeyPair[], type: 'private'): Promise<Account[]>\r
-       /**\r
-       * Instantiates Account objects from their private keys which are used to\r
-       * derive public keys and then discarded.\r
-       *\r
-       * @param {(string | Uint8Array<ArrayBuffer> | KeyPair | (string | Uint8Array<ArrayBuffer> | KeyPair)[])} input - Indexes and keys of the accounts\r
-       * @param {'private'} [type] - Indicates private keys\r
-       * @returns {(Account | Account[] | Promise<Account | Account[]>)} Promise for array of new Account objects\r
-       */\r
-       static load (input: string | Uint8Array<ArrayBuffer> | KeyPair | (string | Uint8Array<ArrayBuffer> | KeyPair)[], type?: 'private'): Account | Account[] | Promise<Account | Account[]> {\r
+        * Instantiates Account objects from their private keys which are used to\r
+        * derive public keys and then discarded.\r
+        * @param {(string | Uint8Array<ArrayBuffer> | KeyPair | (string | Uint8Array<ArrayBuffer> | KeyPair)[])} input - Indexes and keys of the accounts\r
+        * @returns {(Account | Account[])} Array of new Account objects\r
+        */\r
+       static load (input: string | Uint8Array<ArrayBuffer> | KeyPair | (string | Uint8Array<ArrayBuffer> | KeyPair)[], type?: 'private'): Account | Account[] {\r
                const isInputArray = Array.isArray(input)\r
                const inputs = isInputArray ? input : [input]\r
                if (this.#isKeyPairs(inputs) && type === 'private') {\r
-                       return this.#fromPrivate(inputs)\r
-                               .then(r => isInputArray ? r : r[0])\r
+                       const r = this.#fromPrivate(inputs)\r
+                       return isInputArray ? r : r[0]\r
                } else {\r
                        return isInputArray ? this.#fromPublic(inputs) : this.#fromPublic(inputs)[0]\r
                }\r
        }\r
 \r
        /**\r
-       * Refreshes the account from its current state on the network.\r
-       *\r
-       * A successful response sets the balance, frontier, and representative\r
-       * properties.\r
-       *\r
-       * @param {(Rpc | string | URL)} rpc - RPC node information required to call `account_info`\r
-       */\r
+        * Refreshes the account from its current state on the network. A successful\r
+        * response sets the balance, frontier, and representative properties.\r
+        * @param {(Rpc | string | URL)} rpc - RPC node information required to call `account_info`\r
+        */\r
        async refresh (rpc: Rpc | string | URL): Promise<void> {\r
                return await _refresh(this, rpc)\r
        }\r
@@ -285,7 +256,7 @@ export class Account {
        * @param {KeyPair} keypairs - Indexes and keys of the accounts\r
        * @returns {Promise<Account[]>} Promise for new Account objects\r
        */\r
-       static async #fromPrivate (keypairs: KeyPair[]): Promise<Account[]> {\r
+       static #fromPrivate (keypairs: KeyPair[]): Account[] {\r
                try {\r
                        const accounts: Account[] = []\r
                        for (let keypair of keypairs) {\r