From f523ec2dc16af71a1214d9f002563b1610e82c05 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Sat, 5 Jul 2025 22:00:59 -0700 Subject: [PATCH] Rename private members and shorten getters. --- src/lib/wallets/wallet.ts | 48 ++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/src/lib/wallets/wallet.ts b/src/lib/wallets/wallet.ts index ed56b54..7bbc335 100644 --- a/src/lib/wallets/wallet.ts +++ b/src/lib/wallets/wallet.ts @@ -24,30 +24,22 @@ export type KeyPair = { * Blake2bWallet, LedgerWallet. */ export abstract class Wallet { + abstract ckd (index: number[]): Promise + static #poolNanoNacl: Pool static #poolSafe: Pool + #accounts: AccountList #id: Entropy #locked: boolean = true - #mnemonic: Bip39Mnemonic | null - #seed: string | null + #m: Bip39Mnemonic | null + #s: string | null + get id () { return this.#id.hex } get isLocked () { return this.#locked } get isUnlocked () { return !this.#locked } - get mnemonic () { - if (this.#mnemonic instanceof Bip39Mnemonic) { - return this.#mnemonic.phrase - } - return '' - } - get seed () { - if (typeof this.#seed === 'string') { - return this.#seed - } - return '' - } - - abstract ckd (index: number[]): Promise + get mnemonic () { return this.#m instanceof Bip39Mnemonic ? this.#m.phrase : '' } + get seed () { return typeof this.#s === 'string' ? this.#s : '' } constructor (id: Entropy, seed?: string, mnemonic?: Bip39Mnemonic) { if (this.constructor === Wallet) { @@ -55,8 +47,8 @@ export abstract class Wallet { } this.#accounts = new AccountList() this.#id = id - this.#mnemonic = mnemonic ?? null - this.#seed = seed ?? null + this.#m = mnemonic ?? null + this.#s = seed ?? null Wallet.#poolNanoNacl ??= new Pool(NanoNaClWorker) Wallet.#poolSafe ??= new Pool(SafeWorker) } @@ -72,8 +64,8 @@ export abstract class Wallet { delete this.#accounts[a] i++ } - this.#mnemonic = null - this.#seed = null + this.#m = null + this.#s = null await Wallet.#poolSafe.assign({ method: 'destroy', name: this.id @@ -236,11 +228,11 @@ export abstract class Wallet { mnemonic: null, seed: null } - if (this.#mnemonic instanceof Bip39Mnemonic) { - data.mnemonic = this.#mnemonic.phrase + if (this.#m instanceof Bip39Mnemonic) { + data.mnemonic = this.#m.phrase } - if (typeof this.#seed === 'string') { - data.seed = this.#seed + if (typeof this.#s === 'string') { + data.seed = this.#s } const response = (await Wallet.#poolSafe.assign({ method: 'put', @@ -263,8 +255,8 @@ export abstract class Wallet { password.fill(0) } this.#locked = true - this.#mnemonic = null - this.#seed = null + this.#m = null + this.#s = null return true } @@ -292,10 +284,10 @@ export abstract class Wallet { throw null } if (mnemonic != null) { - this.#mnemonic = await Bip39Mnemonic.fromPhrase(mnemonic) + this.#m = await Bip39Mnemonic.fromPhrase(mnemonic) } if (seed != null) { - this.#seed = seed + this.#s = seed } const promises = [] for (const account of this.#accounts) { -- 2.47.3