async destroy (): Promise<void> {\r
await SafeWorker.assign({\r
method: 'destroy',\r
- [this.publicKey]: this.publicKey,\r
- store: 'Account'\r
+ store: 'Account',\r
+ [this.publicKey]: this.publicKey\r
})\r
this.#frontier = undefined\r
this.#balance = undefined\r
#id: Entropy\r
#locked: boolean = true\r
#m: Bip39Mnemonic | null\r
- #s: Uint8Array<ArrayBuffer>\r
+ #s: Uint8Array<ArrayBuffer> | null\r
\r
get id () { return `libnemo_${this.#id.hex}` }\r
get isLocked () { return this.#locked }\r
get isUnlocked () { return !this.#locked }\r
get mnemonic () { return this.#m instanceof Bip39Mnemonic ? this.#m.phrase : null }\r
- get seed () { return 0 === +(bytes.toHex(this.#s)) ? null : bytes.toHex(this.#s) }\r
+ get seed () { return this.#s == null ? this.#s : bytes.toHex(this.#s) }\r
\r
constructor (id: Entropy, seed?: Uint8Array<ArrayBuffer>, mnemonic?: Bip39Mnemonic) {\r
if (this.constructor === Wallet) {\r
this.#accounts = new AccountList()\r
this.#id = id\r
this.#m = mnemonic ?? null\r
- this.#s = seed ?? new Uint8Array(0)\r
+ this.#s = seed ?? null\r
}\r
\r
/**\r
}\r
this.#m = null\r
bytes.erase(this.#s)\r
+ this.#s = null\r
await SafeWorker.assign({\r
store: 'Wallet',\r
method: 'destroy',\r
bytes.erase(password)\r
}\r
bytes.erase(this.#s)\r
+ this.#s = null\r
this.#m = null\r
this.#locked = true\r
return true\r
}
const decryptionKeys: { [salt: string]: CryptoKey } = {}
for (const record of records) {
- const salt = bytes.toHex(new Uint8Array(record.salt))
- decryptionKeys[salt] ??= await this.#createAesKey('decrypt', password, record.salt)
+ const salt = await Entropy.import(record.salt)
+ decryptionKeys[salt.hex] ??= await this.#createAesKey('decrypt', password, salt.buffer)
const iv = await Entropy.import(record.iv)
- const decrypted = await globalThis.crypto.subtle.decrypt({ name: 'AES-GCM', iv: iv.buffer }, decryptionKeys[salt], record.encrypted)
+ const decrypted = await globalThis.crypto.subtle.decrypt({ name: 'AES-GCM', iv: iv.buffer }, decryptionKeys[salt.hex], record.encrypted)
results[record.label] = decrypted
}
return results