]> git.codecow.com Git - libnemo.git/commitdiff
Rename private members and shorten getters.
authorChris Duncan <chris@zoso.dev>
Sun, 6 Jul 2025 05:00:59 +0000 (22:00 -0700)
committerChris Duncan <chris@zoso.dev>
Sun, 6 Jul 2025 05:00:59 +0000 (22:00 -0700)
src/lib/wallets/wallet.ts

index ed56b54151f7e84565427589fb60384ae3a746bc..7bbc335c93eeca6d63de33964361f6013cb29a59 100644 (file)
@@ -24,30 +24,22 @@ export type KeyPair = {
 * Blake2bWallet, LedgerWallet.\r
 */\r
 export abstract class Wallet {\r
+       abstract ckd (index: number[]): Promise<KeyPair[]>\r
+\r
        static #poolNanoNacl: Pool\r
        static #poolSafe: Pool\r
+\r
        #accounts: AccountList\r
        #id: Entropy\r
        #locked: boolean = true\r
-       #mnemonic: Bip39Mnemonic | null\r
-       #seed: string | null\r
+       #m: Bip39Mnemonic | null\r
+       #s: string | null\r
+\r
        get id () { return this.#id.hex }\r
        get isLocked () { return this.#locked }\r
        get isUnlocked () { return !this.#locked }\r
-       get mnemonic () {\r
-               if (this.#mnemonic instanceof Bip39Mnemonic) {\r
-                       return this.#mnemonic.phrase\r
-               }\r
-               return ''\r
-       }\r
-       get seed () {\r
-               if (typeof this.#seed === 'string') {\r
-                       return this.#seed\r
-               }\r
-               return ''\r
-       }\r
-\r
-       abstract ckd (index: number[]): Promise<KeyPair[]>\r
+       get mnemonic () { return this.#m instanceof Bip39Mnemonic ? this.#m.phrase : '' }\r
+       get seed () { return typeof this.#s === 'string' ? this.#s : '' }\r
 \r
        constructor (id: Entropy, seed?: string, mnemonic?: Bip39Mnemonic) {\r
                if (this.constructor === Wallet) {\r
@@ -55,8 +47,8 @@ export abstract class Wallet {
                }\r
                this.#accounts = new AccountList()\r
                this.#id = id\r
-               this.#mnemonic = mnemonic ?? null\r
-               this.#seed = seed ?? null\r
+               this.#m = mnemonic ?? null\r
+               this.#s = seed ?? null\r
                Wallet.#poolNanoNacl ??= new Pool(NanoNaClWorker)\r
                Wallet.#poolSafe ??= new Pool(SafeWorker)\r
        }\r
@@ -72,8 +64,8 @@ export abstract class Wallet {
                        delete this.#accounts[a]\r
                        i++\r
                }\r
-               this.#mnemonic = null\r
-               this.#seed = null\r
+               this.#m = null\r
+               this.#s = null\r
                await Wallet.#poolSafe.assign({\r
                        method: 'destroy',\r
                        name: this.id\r
@@ -236,11 +228,11 @@ export abstract class Wallet {
                                mnemonic: null,\r
                                seed: null\r
                        }\r
-                       if (this.#mnemonic instanceof Bip39Mnemonic) {\r
-                               data.mnemonic = this.#mnemonic.phrase\r
+                       if (this.#m instanceof Bip39Mnemonic) {\r
+                               data.mnemonic = this.#m.phrase\r
                        }\r
-                       if (typeof this.#seed === 'string') {\r
-                               data.seed = this.#seed\r
+                       if (typeof this.#s === 'string') {\r
+                               data.seed = this.#s\r
                        }\r
                        const response = (await Wallet.#poolSafe.assign({\r
                                method: 'put',\r
@@ -263,8 +255,8 @@ export abstract class Wallet {
                        password.fill(0)\r
                }\r
                this.#locked = true\r
-               this.#mnemonic = null\r
-               this.#seed = null\r
+               this.#m = null\r
+               this.#s = null\r
                return true\r
        }\r
 \r
@@ -292,10 +284,10 @@ export abstract class Wallet {
                                throw null\r
                        }\r
                        if (mnemonic != null) {\r
-                               this.#mnemonic = await Bip39Mnemonic.fromPhrase(mnemonic)\r
+                               this.#m = await Bip39Mnemonic.fromPhrase(mnemonic)\r
                        }\r
                        if (seed != null) {\r
-                               this.#seed = seed\r
+                               this.#s = seed\r
                        }\r
                        const promises = []\r
                        for (const account of this.#accounts) {\r