From: Chris Duncan Date: Mon, 11 Aug 2025 16:39:45 +0000 (-0700) Subject: Replace account load nomenclature to avoid collision with keyword. X-Git-Tag: v0.10.5~41^2~114 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=6cf0173c6d572087ca9b74044b01ad62d9b3df8e;p=libnemo.git Replace account load nomenclature to avoid collision with keyword. --- diff --git a/src/lib/account.ts b/src/lib/account.ts index f0b6e67..f58c7a5 100644 --- a/src/lib/account.ts +++ b/src/lib/account.ts @@ -43,7 +43,7 @@ export class Account { if (v instanceof Account) { this.#representative = v } else if (typeof v === 'string') { - this.#representative = Account.import(v) + this.#representative = Account.load(v) } else { throw new TypeError(`Invalid argument for account representative: ${v}`) } @@ -82,14 +82,14 @@ export 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. @@ -97,7 +97,7 @@ export 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. @@ -105,7 +105,7 @@ export 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. @@ -113,7 +113,7 @@ export 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. @@ -121,7 +121,7 @@ export 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. @@ -130,7 +130,7 @@ export class Account { * @param {string} type - Indicates a private key * @returns {Promise} Promise for a new Account object */ - static async import (keypair: KeyPair, type: 'private'): Promise + 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. @@ -139,8 +139,8 @@ export class Account { * @param {string} type - Indicates private keys * @returns {Promise} Promise for array of new Account objects */ - static async import (keypairs: KeyPair[], type: 'private'): Promise - static import (input: Key | KeyPair | (Key | KeyPair)[], type?: 'private'): Account | Account[] | Promise { + static async load (keypairs: KeyPair[], type: 'private'): Promise + static load (input: Key | KeyPair | (Key | KeyPair)[], type?: 'private'): Account | Account[] | Promise { const isInputArray = Array.isArray(input) const inputs = isInputArray ? input : [input] if (this.#isKeyPairs(inputs) && type === 'private') { @@ -182,7 +182,7 @@ export class Account { this.#balance = BigInt(balance) this.#frontier = frontier this.#receivable = BigInt(receivable) - this.#representative = await Account.import(representative) + this.#representative = await Account.load(representative) this.#weight = BigInt(weight) } diff --git a/src/lib/block.ts b/src/lib/block.ts index b57946d..12a1da4 100644 --- a/src/lib/block.ts +++ b/src/lib/block.ts @@ -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 diff --git a/src/lib/rolodex.ts b/src/lib/rolodex.ts index d9fd003..9be2e64 100644 --- a/src/lib/rolodex.ts +++ b/src/lib/rolodex.ts @@ -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 { 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 diff --git a/src/lib/tools.ts b/src/lib/tools.ts index 744d6b8..f9b08e9 100644 --- a/src/lib/tools.ts +++ b/src/lib/tools.ts @@ -149,7 +149,7 @@ export async function sweep ( const blockQueue: Promise[] = [] 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) { diff --git a/src/lib/wallet/index.ts b/src/lib/wallet/index.ts index 56dbc28..f743955 100644 --- a/src/lib/wallet/index.ts +++ b/src/lib/wallet/index.ts @@ -235,7 +235,7 @@ export class Wallet { } const publicKeys: KeyPair[] = await Promise.all(promises) if (publicKeys.length > 0) { - const publicAccounts = Account.import(publicKeys) + const publicAccounts = Account.load(publicKeys) for (const a of publicAccounts) { if (a.index == null) { throw new RangeError('Index missing for Account') @@ -400,7 +400,7 @@ export class Wallet { for (const key of Object.keys(errors ?? {})) { const value = errors[key] if (value === 'Account not found') { - return Account.import(key) + return Account.load(key) } } return await this.unopened(rpc, batchSize, from + batchSize) diff --git a/src/lib/wallet/ledger.ts b/src/lib/wallet/ledger.ts index 4378c24..004c5df 100644 --- a/src/lib/wallet/ledger.ts +++ b/src/lib/wallet/ledger.ts @@ -127,7 +127,7 @@ export class Ledger extends Wallet { if (status !== 'OK' || publicKey == null) { throw new Error(`Error getting Ledger account: ${status}`) } - return Account.import({ index, publicKey }) + return Account.load({ index, publicKey }) } /** diff --git a/src/types.d.ts b/src/types.d.ts index e5916dd..c9165a1 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -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} Promise for a new Account object */ - static import (keypair: KeyPair, type: 'private'): Promise + static load (keypair: KeyPair, type: 'private'): Promise /** * 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} Promise for array of new Account objects */ - static import (keypairs: KeyPair[], type: 'private'): Promise + static load (keypairs: KeyPair[], type: 'private'): Promise /** * Refreshes the account from its current state on the network. * diff --git a/test/test.tools.mjs b/test/test.tools.mjs index b9b1f5c..31c7d47 100644 --- a/test/test.tools.mjs +++ b/test/test.tools.mjs @@ -165,7 +165,7 @@ await Promise.all([ .sign(wallet, account.index) assert.ok(await sendBlock.verify(account.publicKey)) - const wrongAccount = Account.import('nano_1q3hqecaw15cjt7thbtxu3pbzr1eihtzzpzxguoc37bj1wc5ffoh7w74gi6p') + const wrongAccount = Account.load('nano_1q3hqecaw15cjt7thbtxu3pbzr1eihtzzpzxguoc37bj1wc5ffoh7w74gi6p') assert.equal(await sendBlock.verify(wrongAccount.publicKey), false) await assert.resolves(wallet.destroy())