]> git.codecow.com Git - libnemo.git/commitdiff
Replace account load nomenclature to avoid collision with keyword.
authorChris Duncan <chris@zoso.dev>
Mon, 11 Aug 2025 16:39:45 +0000 (09:39 -0700)
committerChris Duncan <chris@zoso.dev>
Mon, 11 Aug 2025 16:39:45 +0000 (09:39 -0700)
src/lib/account.ts
src/lib/block.ts
src/lib/rolodex.ts
src/lib/tools.ts
src/lib/wallet/index.ts
src/lib/wallet/ledger.ts
src/types.d.ts
test/test.tools.mjs

index f0b6e670f29eaa1e4d696055ac31b9428093917d..f58c7a5f5e9d23456a9df89b38b3023071e9197c 100644 (file)
@@ -43,7 +43,7 @@ export class Account {
                if (v instanceof Account) {\r
                        this.#representative = v\r
                } else if (typeof v === 'string') {\r
-                       this.#representative = Account.import(v)\r
+                       this.#representative = Account.load(v)\r
                } else {\r
                        throw new TypeError(`Invalid argument for account representative: ${v}`)\r
                }\r
@@ -82,14 +82,14 @@ export class Account {
        * @param {string} address - Address of the account\r
        * @returns {Account} A new Account object\r
        */\r
-       static import (address: string): Account\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
-       static import (addresses: string[]): Account[]\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
@@ -97,7 +97,7 @@ export class Account {
        * @param {Key} publicKey - Public key of the account\r
        * @returns {Account} A new Account object\r
        */\r
-       static import (publicKey: Key): Account\r
+       static load (publicKey: Key): 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
@@ -105,7 +105,7 @@ export class Account {
        * @param {Key[]} publicKeys - Public keys of the accounts\r
        * @returns {Account[]} Array of new Account objects\r
        */\r
-       static import (publicKeys: Key[]): Account[]\r
+       static load (publicKeys: Key[]): 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
@@ -113,7 +113,7 @@ export class Account {
        * @param {KeyPair} keypair - Index and keys of the account\r
        * @returns {Account} A new Account object\r
        */\r
-       static import (keypair: KeyPair): Account\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
@@ -121,7 +121,7 @@ export class Account {
        * @param {KeyPair[]} keypairs - Indexes and keys of the accounts\r
        * @returns {Account[]} Array of new Account objects\r
        */\r
-       static import (keypairs: KeyPair[]): Account[]\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
@@ -130,7 +130,7 @@ export class Account {
        * @param {string} type - Indicates a private key\r
        * @returns {Promise<Account>} Promise for a new Account object\r
        */\r
-       static async import (keypair: KeyPair, type: 'private'): Promise<Account>\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
@@ -139,8 +139,8 @@ export class Account {
        * @param {string} type - Indicates private keys\r
        * @returns {Promise<Account[]>} Promise for array of new Account objects\r
        */\r
-       static async import (keypairs: KeyPair[], type: 'private'): Promise<Account[]>\r
-       static import (input: Key | KeyPair | (Key | KeyPair)[], type?: 'private'): Account | Account[] | Promise<Account | Account[]> {\r
+       static async load (keypairs: KeyPair[], type: 'private'): Promise<Account[]>\r
+       static load (input: Key | KeyPair | (Key | KeyPair)[], type?: 'private'): Account | Account[] | Promise<Account | Account[]> {\r
                const isInputArray = Array.isArray(input)\r
                const inputs = isInputArray ? input : [input]\r
                if (this.#isKeyPairs(inputs) && type === 'private') {\r
@@ -182,7 +182,7 @@ export class Account {
                this.#balance = BigInt(balance)\r
                this.#frontier = frontier\r
                this.#receivable = BigInt(receivable)\r
-               this.#representative = await Account.import(representative)\r
+               this.#representative = await Account.load(representative)\r
                this.#weight = BigInt(weight)\r
        }\r
 \r
index b57946d95b5dc359ebe5f1f1c2371e40eb49c20c..12a1da41fb10dd113293cef8c4e2786d33b55cf3 100644 (file)
@@ -92,10 +92,10 @@ export class Block {
        constructor (account: unknown, balance: unknown, previous: unknown, representative: unknown) {
                try {
                        if (typeof account === 'string') {
-                               account = Account.import(account)
+                               account = Account.load(account)
                        }
                        if (typeof representative === 'string') {
-                               representative = Account.import(representative)
+                               representative = Account.load(representative)
                        }
                        if (!(account instanceof Account)) {
                                throw new TypeError('Invalid account')
@@ -209,7 +209,7 @@ export class Block {
                                throw new TypeError('Invalid account')
                        }
                        this.representative = (typeof representative === 'string')
-                               ? Account.import(representative)
+                               ? Account.load(representative)
                                : representative
 
                        this.link = hex.toBytes(BURN_PUBLIC_KEY)
@@ -363,7 +363,7 @@ export class Block {
                                throw new TypeError('Invalid account')
                        }
                        this.link = (typeof account === 'string')
-                               ? hex.toBytes(Account.import(account).publicKey)
+                               ? hex.toBytes(Account.load(account).publicKey)
                                : hex.toBytes(account.publicKey)
 
                        return this
index d9fd003faa90367028e3d82218b56294ae9abbd1..9be2e647e36ff558fc6de73b1579fa36cc0b77db 100644 (file)
@@ -44,7 +44,7 @@ export class Rolodex {
                        .replaceAll('<', '\\u003c')
                        .replaceAll('>', '\\u003e')
                        .replaceAll('\\', '\\u005c')
-               const account = Account.import(address)
+               const account = Account.load(address)
 
                try {
                        const existingName = await this.getName(account.address)
@@ -183,7 +183,7 @@ export class Rolodex {
        static async verify (name: string, signature: string, ...data: string[]): Promise<boolean> {
                const addresses = await this.getAddresses(name)
                for (const address of addresses) {
-                       const { publicKey } = Account.import(address)
+                       const { publicKey } = Account.load(address)
                        const verified = await verify(publicKey, signature, ...data)
                        if (verified) {
                                return true
index 744d6b806c3755b780e6471fe093d061179e3e5d..f9b08e988019ba980ec6be93c8cc01e4779332dd 100644 (file)
@@ -149,7 +149,7 @@ export async function sweep (
        const blockQueue: Promise<void>[] = []
        const results: { status: 'success' | 'error', address: string, message: string }[] = []
 
-       const recipientAccount = Account.import(recipient)
+       const recipientAccount = Account.load(recipient)
        const accounts = await wallet.refresh(rpc, from, to)
        for (const account of accounts) {
                if (account.representative?.address && account.frontier && account.index) {
index 56dbc28f70a879d7953b4eaa7335c8993f9d630c..f7439559066d4ec56d508123659987e0739516a7 100644 (file)
@@ -235,7 +235,7 @@ export class Wallet {
                        }\r
                        const publicKeys: KeyPair[] = await Promise.all(promises)\r
                        if (publicKeys.length > 0) {\r
-                               const publicAccounts = Account.import(publicKeys)\r
+                               const publicAccounts = Account.load(publicKeys)\r
                                for (const a of publicAccounts) {\r
                                        if (a.index == null) {\r
                                                throw new RangeError('Index missing for Account')\r
@@ -400,7 +400,7 @@ export class Wallet {
                for (const key of Object.keys(errors ?? {})) {\r
                        const value = errors[key]\r
                        if (value === 'Account not found') {\r
-                               return Account.import(key)\r
+                               return Account.load(key)\r
                        }\r
                }\r
                return await this.unopened(rpc, batchSize, from + batchSize)\r
index 4378c24c9b04ba95a370d29334c1f33201e12ec7..004c5df8c74a3e9198744ef128aa8d71be4f489b 100644 (file)
@@ -127,7 +127,7 @@ export class Ledger extends Wallet {
                if (status !== 'OK' || publicKey == null) {\r
                        throw new Error(`Error getting Ledger account: ${status}`)\r
                }\r
-               return Account.import({ index, publicKey })\r
+               return Account.load({ index, publicKey })\r
        }\r
 \r
        /**\r
index e5916dd9eda456a6e98b74fb8e26489a5622818f..c9165a126a83eaa8f6226becc888e048b37a2192 100644 (file)
@@ -38,14 +38,14 @@ export declare class Account {
        * @param {string} address - Address of the account
        * @returns {Account} A new Account object
        */
-       static import (address: string): Account
+       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
        */
-       static import (addresses: string[]): Account[]
+       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.
@@ -53,7 +53,7 @@ export declare class Account {
        * @param {Key} publicKey - Public key of the account
        * @returns {Account} A new Account object
        */
-       static import (publicKey: Key): Account
+       static load (publicKey: Key): Account
        /**
        * Instantiates Account objects from their public keys. They are unable to sign
        * blocks or messages since they have no private key.
@@ -61,7 +61,7 @@ export declare class Account {
        * @param {Key[]} publicKeys - Public keys of the accounts
        * @returns {Account[]} Array of new Account objects
        */
-       static import (publicKeys: Key[]): Account[]
+       static load (publicKeys: Key[]): Account[]
        /**
        * Instantiates an Account object from its public key. It is unable to sign
        * blocks or messages since it has no private key.
@@ -69,7 +69,7 @@ export declare class Account {
        * @param {KeyPair} keypair - Index and keys of the account
        * @returns {Account} A new Account object
        */
-       static import (keypair: KeyPair): Account
+       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.
@@ -77,7 +77,7 @@ export declare class Account {
        * @param {KeyPair[]} keypairs - Indexes and keys of the accounts
        * @returns {Account[]} Array of new Account objects
        */
-       static import (keypairs: KeyPair[]): Account[]
+       static load (keypairs: KeyPair[]): Account[]
        /**
        * Instantiates an Account object from its private key which is used to derive
        * a public key and then discarded.
@@ -86,7 +86,7 @@ export declare class Account {
        * @param {string} type - Indicates a private key
        * @returns {Promise<Account>} Promise for a new Account object
        */
-       static import (keypair: KeyPair, type: 'private'): Promise<Account>
+       static load (keypair: KeyPair, type: 'private'): Promise<Account>
        /**
        * Instantiates Account objects from their private keys which are used to
        * derive public keys and then discarded.
@@ -95,7 +95,7 @@ export declare class Account {
        * @param {string} type - Indicates private keys
        * @returns {Promise<Account[]>} Promise for array of new Account objects
        */
-       static import (keypairs: KeyPair[], type: 'private'): Promise<Account[]>
+       static load (keypairs: KeyPair[], type: 'private'): Promise<Account[]>
        /**
        * Refreshes the account from its current state on the network.
        *
index b9b1f5c65b9661dc6011a0fa5e808733e2edf32d..31c7d47662cdce3716f92999e1ae7469ffd0a118 100644 (file)
@@ -165,7 +165,7 @@ await Promise.all([
                                .sign(wallet, account.index)\r
                        assert.ok(await sendBlock.verify(account.publicKey))\r
 \r
-                       const wrongAccount = Account.import('nano_1q3hqecaw15cjt7thbtxu3pbzr1eihtzzpzxguoc37bj1wc5ffoh7w74gi6p')\r
+                       const wrongAccount = Account.load('nano_1q3hqecaw15cjt7thbtxu3pbzr1eihtzzpzxguoc37bj1wc5ffoh7w74gi6p')\r
                        assert.equal(await sendBlock.verify(wrongAccount.publicKey), false)\r
 \r
                        await assert.resolves(wallet.destroy())\r