if (password == null || password.constructor.name !== 'Uint8Array') {\r
throw new Error('Failed to unlock wallet')\r
}\r
- let success = true\r
try {\r
const data: { id: string, mnemonic: string | null, seed: string | null } = {\r
id: this.id,\r
if (typeof this.#seed === 'string') {\r
data.seed = this.#seed\r
}\r
- success &&= await this.#poolSafe.assign({\r
+ const res = await this.#poolSafe.assign({\r
method: 'put',\r
name: this.id,\r
password,\r
data\r
})\r
+ const success = res[0].result\r
+ if (!success) {\r
+ throw null\r
+ }\r
const promises = []\r
for (const account of this.#accounts) {\r
promises.push(account.lock(password))\r
}\r
await Promise.all(promises)\r
- password.fill(0)\r
- if (!success) {\r
- throw null\r
- }\r
} catch (err) {\r
throw new Error('Failed to lock wallet')\r
+ } finally {\r
+ password.fill(0)\r
}\r
this.#locked = true\r
this.#mnemonic = null\r
throw new Error('Failed to unlock wallet')\r
}\r
try {\r
- const data = await this.#poolSafe.assign({\r
+ const res = await this.#poolSafe.assign({\r
method: 'get',\r
name: this.id,\r
password\r
})\r
- console.log(data[0].result)\r
- const { id, mnemonic, seed } = data[0].result\r
+ const { id, mnemonic, seed } = res[0].result\r
if (id !== this.id) {\r
throw null\r
}\r
- const promises = []\r
- for (const account of this.#accounts) {\r
- promises.push(account.unlock(password))\r
- }\r
- await Promise.all(promises)\r
- password.fill(0)\r
if (mnemonic != null) {\r
this.#mnemonic = await Bip39Mnemonic.fromPhrase(mnemonic)\r
}\r
if (seed != null) {\r
this.#seed = seed\r
}\r
+ const promises = []\r
+ for (const account of this.#accounts) {\r
+ promises.push(account.unlock(password))\r
+ }\r
+ await Promise.all(promises)\r
this.#locked = false\r
} catch (err) {\r
throw new Error('Failed to unlock wallet')\r
+ } finally {\r
+ password.fill(0)\r
}\r
return true\r
}\r