]> zoso.dev Git - libnemo.git/commitdiff
Normalize address prefix in constructor to fix duplicate prefix bug.
authorChris Duncan <chris@zoso.dev>
Fri, 29 Nov 2024 09:32:03 +0000 (01:32 -0800)
committerChris Duncan <chris@zoso.dev>
Fri, 29 Nov 2024 09:32:03 +0000 (01:32 -0800)
src/lib/account.ts

index d73189e0341fd9dbfbd9b0e5e09463937831f0be..3320e6b1a95cea1c281a663946b67d68bb9e5efe 100644 (file)
@@ -59,6 +59,8 @@ export class Account {
                        throw new TypeError(`Invalid index ${index} when creating Account ${address}`)\r
                }\r
                this.#a = address\r
+                       .replace(PREFIX, '')\r
+                       .replace(PREFIX_LEGACY, '')\r
                this.#pub = publicKey\r
                this.#prv = privateKey ?? null\r
                this.#i = index\r
@@ -76,9 +78,6 @@ export class Account {
        static fromAddress (address: string, index?: number): Account {\r
                Account.#isInternal = true\r
                Account.validate(address)\r
-               address = address\r
-                       .replace(PREFIX, '')\r
-                       .replace(PREFIX_LEGACY, '')\r
                const publicKey = Account.#addressToKey(address)\r
                const account = new this(address, publicKey, undefined, index)\r
                return account\r
@@ -117,7 +116,7 @@ export class Account {
        }\r
 \r
        /**\r
-       * Asynchronously instantiates an Account object from its public and private\r
+       * Instantiates an Account object from its public and private\r
        * keys.\r
        *\r
        * WARNING: The validity of the keys is checked, but they are assumed to have\r
@@ -129,7 +128,7 @@ export class Account {
        * @param {number} [index] - Account number used when deriving the key\r
        * @returns {Promise<Account>} The instantiated Account object\r
        */\r
-       static fromKnownKeys (publicKey: string, privateKey: string, index?: number): Account {\r
+       static fromKeypair (publicKey: string, privateKey: string, index?: number): Account {\r
                Account.#isInternal = true\r
                Account.#validateKey(publicKey)\r
                Account.#validateKey(privateKey)\r