From bbe568a2f4af6b921e03ad1f6ed00c5b9198ff76 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Sun, 21 Sep 2025 14:33:34 -0700 Subject: [PATCH] Update account internal flag to enable removing self references. --- src/lib/account/index.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/lib/account/index.ts b/src/lib/account/index.ts index f6b70b3..850307b 100644 --- a/src/lib/account/index.ts +++ b/src/lib/account/index.ts @@ -25,13 +25,13 @@ type KeyPair = { export class Account { [key: string]: any + static #isInternal: boolean = false + static get isInternal (): boolean { return this.#isInternal } /** - * @returns - */ + * @returns {'Account'} + */ static get DB_NAME (): 'Account' { return 'Account' } - static #isInternal: boolean = false - #address?: Address #index?: number #publicKey: Uint8Array @@ -113,10 +113,9 @@ export class Account { set weight (v: bigint | number | string) { this.#weight = BigInt(v) } private constructor (address: Address, publicKey: Uint8Array, index?: number) { - if (!Account.#isInternal) { + if (!(this.constructor as typeof Account).isInternal) { throw new Error('Account cannot be instantiated directly. Use `load()` instead.') } - Account.#isInternal = false this.#address = address this.#publicKey = publicKey this.#index = index @@ -301,7 +300,9 @@ export class Account { const publicKey = await NanoNaCl.convert(privateKey) const address = new Address(publicKey) this.#isInternal = true - accounts.push(new this(address, publicKey, index)) + const account = new this(address, publicKey, index) + this.#isInternal = false + accounts.push(account) } return accounts } catch (err) { @@ -336,7 +337,9 @@ export class Account { const address = new Address(keypair.publicKey) const publicKey = address.toPublicKey() this.#isInternal = true - accounts.push(new this(address, publicKey, index)) + const account = new this(address, publicKey, index) + this.#isInternal = false + accounts.push(account) } return accounts } catch (err) { -- 2.47.3