throw new Error('Failed to unlock wallet')\r
}\r
try {\r
+ const data: { id: string, privateKey: string | null } = {\r
+ id: this.#pub,\r
+ privateKey: null\r
+ }\r
if (this.#prv != null) {\r
- await Account.#poolSafe.assign({\r
- method: 'put',\r
- name: this.#prv,\r
- password\r
- })\r
+ data.privateKey = this.#prv\r
+ }\r
+ console.log(this.#prv)\r
+ const response = (await Account.#poolSafe.assign({\r
+ method: 'put',\r
+ name: this.#pub,\r
+ password,\r
+ data\r
+ }))[0]\r
+ const success = response.result\r
+ if (!success) {\r
+ throw null\r
}\r
} catch (err) {\r
console.error(`Failed to lock account ${this.address}`, err)\r
throw new Error('Failed to unlock wallet')\r
}\r
try {\r
- this.#prv = await Account.#poolSafe.assign({\r
+ const response = (await Account.#poolSafe.assign({\r
method: 'get',\r
name: this.#pub,\r
password\r
- })\r
+ }))[0]\r
+ console.log(response)\r
+ const { id, privateKey } = response.result\r
+ if (id !== this.#pub) {\r
+ throw null\r
+ }\r
+ if (privateKey != null) {\r
+ this.#prv = privateKey\r
+ }\r
} catch (err) {\r
console.error(`Failed to unlock account ${this.address}`, err)\r
return false\r
await wallet.destroy()\r
})\r
\r
+ await test('locking and unlocking a Bip44Wallet Account with a password', async () => {\r
+ const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
+ await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
+ const account = await wallet.account()\r
+ const lockResult = await account.lock(NANO_TEST_VECTORS.PASSWORD)\r
+\r
+ assert.equals(lockResult, true)\r
+ assert.ok('privateKey' in account)\r
+ assert.nullish(account.privateKey)\r
+\r
+ const unlockResult = await account.unlock(NANO_TEST_VECTORS.PASSWORD)\r
+\r
+ assert.equals(unlockResult, true)\r
+ assert.ok('privateKey' in account)\r
+ assert.equals(account.privateKey, NANO_TEST_VECTORS.PRIVATE_0)\r
+\r
+ await wallet.destroy()\r
+ })\r
+\r
await test('fail to unlock a Bip44Wallet with different passwords', async () => {\r
const wallet = await Bip44Wallet.fromMnemonic(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
await wallet.destroy()\r
})\r
\r
+ await test('locking and unlocking a Blake2bWallet Account with a password', async () => {\r
+ const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_0)\r
+ await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
+ const account = await wallet.account()\r
+ const lockResult = await account.lock(NANO_TEST_VECTORS.PASSWORD)\r
+\r
+ assert.equals(lockResult, true)\r
+ assert.ok('privateKey' in account)\r
+ assert.nullish(account.privateKey)\r
+\r
+ const unlockResult = await account.unlock(NANO_TEST_VECTORS.PASSWORD)\r
+\r
+ assert.equals(unlockResult, true)\r
+ assert.ok('privateKey' in account)\r
+ assert.equals(account.privateKey, NANO_TEST_VECTORS.PRIVATE_0)\r
+\r
+ await wallet.destroy()\r
+ })\r
+\r
await test('fail to unlock a Blake2bWallet with different passwords', async () => {\r
const wallet = await Blake2bWallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, TREZOR_TEST_VECTORS.ENTROPY_1)\r
\r