*/\r
export class Bip39Mnemonic {\r
static #isInternal: boolean = false\r
- #bip44Seed: Uint8Array<ArrayBuffer> | null = null\r
- #blake2bSeed: Uint8Array<ArrayBuffer> | null = null\r
+ #bip44Seed?: Uint8Array<ArrayBuffer>\r
+ #blake2bSeed?: Uint8Array<ArrayBuffer>\r
#phrase: string = ''\r
get phrase (): string { return this.#phrase.normalize('NFKD') }\r
\r
* @returns {string} Mnemonic phrase validated using the BIP-39 wordlist\r
*/\r
static async fromPhrase (phrase: string): Promise<Bip39Mnemonic> {\r
- Bip39Mnemonic.#isInternal = true\r
+ this.#isInternal = true\r
const self = new this()\r
- const isValid = await Bip39Mnemonic.validate(phrase)\r
+ const isValid = await this.validate(phrase)\r
if (isValid) {\r
self.#phrase = phrase.normalize('NFKD')\r
return self\r
concatenation = concatenation.substring(11)\r
}\r
const sentence = words.join(' ')\r
- return Bip39Mnemonic.fromPhrase(sentence)\r
+ return this.fromPhrase(sentence)\r
}\r
\r
/**\r
return checksum\r
}\r
\r
+ /**\r
+ * Erases seed bytes and releases variable references to allow garbage\r
+ * collection.\r
+ */\r
+ destroy () {\r
+ if (this.#bip44Seed != null) bytes.erase(this.#bip44Seed)\r
+ if (this.#blake2bSeed != null) bytes.erase(this.#blake2bSeed)\r
+ this.#bip44Seed = undefined\r
+ this.#blake2bSeed = undefined\r
+ this.#phrase = ''\r
+ }\r
+\r
/**\r
* Validates a mnemonic phrase.\r
*\r