* 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
}\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
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
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
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
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