*/\r
export class Bip44Wallet extends Wallet {\r
static #isInternal: boolean = false\r
- #poolBip44Ckd: Pool\r
+ static #poolBip44Ckd: Pool\r
\r
constructor (id: Entropy, seed: string, mnemonic?: Bip39Mnemonic) {\r
if (!Bip44Wallet.#isInternal) {\r
}\r
Bip44Wallet.#isInternal = false\r
super(id, seed, mnemonic)\r
- this.#poolBip44Ckd = new Pool(Bip44CkdWorker)\r
- }\r
-\r
- /**\r
- * Removes encrypted secrets in storage and releases variable references to\r
- * allow garbage collection.\r
- */\r
- async destroy (): Promise<void> {\r
- await super.destroy()\r
- this.#poolBip44Ckd.terminate()\r
+ Bip44Wallet.#poolBip44Ckd ??= new Pool(Bip44CkdWorker)\r
}\r
\r
/**\r
async ckd (indexes: number[]): Promise<KeyPair[]> {\r
const data: any = []\r
indexes.forEach(i => data.push({ seed: this.seed, index: i }))\r
- const privateKeys: KeyPair[] = await this.#poolBip44Ckd.assign(data)\r
+ const privateKeys: KeyPair[] = await Bip44Wallet.#poolBip44Ckd.assign(data)\r
for (let i = 0; i < privateKeys.length; i++) {\r
if (privateKeys[i].privateKey == null) {\r
throw new Error('Failed to derive private keys')\r
* Blake2bWallet, LedgerWallet.\r
*/\r
export abstract class Wallet {\r
+ static #poolNanoNacl: Pool\r
+ static #poolSafe: Pool\r
#accounts: AccountList\r
#id: Entropy\r
#locked: boolean = true\r
#mnemonic: Bip39Mnemonic | null\r
- #poolNanoNacl: Pool\r
- #poolSafe: Pool\r
#seed: string | null\r
get id () { return this.#id.hex }\r
get isLocked () { return this.#locked }\r
this.#accounts = new AccountList()\r
this.#id = id\r
this.#mnemonic = mnemonic ?? null\r
- this.#poolNanoNacl = new Pool(NanoNaClWorker)\r
- this.#poolSafe = new Pool(SafeWorker)\r
this.#seed = seed ?? null\r
+ Wallet.#poolNanoNacl ??= new Pool(NanoNaClWorker)\r
+ Wallet.#poolSafe ??= new Pool(SafeWorker)\r
}\r
\r
/**\r
}\r
this.#mnemonic = null\r
this.#seed = null\r
- this.#poolNanoNacl.terminate()\r
- await this.#poolSafe.assign({\r
+ await Wallet.#poolSafe.assign({\r
method: 'destroy',\r
name: this.id\r
})\r
- this.#poolSafe.terminate()\r
}\r
\r
/**\r
privateKey: r.privateKey,\r
index: r.index\r
}))\r
- const keypairs: KeyPair[] = await this.#poolNanoNacl.assign(data)\r
+ const keypairs: KeyPair[] = await Wallet.#poolNanoNacl.assign(data)\r
for (const keypair of keypairs) {\r
if (keypair.privateKey == null) throw new RangeError('Account private key missing')\r
if (keypair.publicKey == null) throw new RangeError('Account public key missing')\r
if (typeof this.#seed === 'string') {\r
data.seed = this.#seed\r
}\r
- const response = (await this.#poolSafe.assign({\r
+ const response = (await Wallet.#poolSafe.assign({\r
method: 'put',\r
name: this.id,\r
password,\r
throw new Error('Failed to unlock wallet')\r
}\r
try {\r
- const response = (await this.#poolSafe.assign({\r
+ const response = (await Wallet.#poolSafe.assign({\r
method: 'get',\r
name: this.id,\r
password\r