From aa255ee2895c9341eae49e2daf3eacc9c0c0aeb4 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Fri, 29 Nov 2024 01:32:03 -0800 Subject: [PATCH] Normalize address prefix in constructor to fix duplicate prefix bug. --- src/lib/account.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/lib/account.ts b/src/lib/account.ts index d73189e..3320e6b 100644 --- a/src/lib/account.ts +++ b/src/lib/account.ts @@ -59,6 +59,8 @@ export class Account { throw new TypeError(`Invalid index ${index} when creating Account ${address}`) } this.#a = address + .replace(PREFIX, '') + .replace(PREFIX_LEGACY, '') this.#pub = publicKey this.#prv = privateKey ?? null this.#i = index @@ -76,9 +78,6 @@ export class Account { static fromAddress (address: string, index?: number): Account { Account.#isInternal = true Account.validate(address) - address = address - .replace(PREFIX, '') - .replace(PREFIX_LEGACY, '') const publicKey = Account.#addressToKey(address) const account = new this(address, publicKey, undefined, index) return account @@ -117,7 +116,7 @@ export class Account { } /** - * Asynchronously instantiates an Account object from its public and private + * Instantiates an Account object from its public and private * keys. * * WARNING: The validity of the keys is checked, but they are assumed to have @@ -129,7 +128,7 @@ export class Account { * @param {number} [index] - Account number used when deriving the key * @returns {Promise} The instantiated Account object */ - static fromKnownKeys (publicKey: string, privateKey: string, index?: number): Account { + static fromKeypair (publicKey: string, privateKey: string, index?: number): Account { Account.#isInternal = true Account.#validateKey(publicKey) Account.#validateKey(privateKey) -- 2.34.1