break
}
case 'lock': {
- result = await this.lock()
+ result = this.lock()
break
}
case 'sign': {
import { Database } from '../database'\r
import { _get } from './get'\r
import { _load } from './load'\r
+import { _lock } from './lock'\r
import { _restore } from './restore'\r
import { Rpc } from '../rpc'\r
import { _sign } from './sign'\r
}\r
\r
/**\r
- * Locks the wallet and all currently derived accounts with a password that\r
- * will be needed to unlock it later.\r
- *\r
- * @returns True if successfully locked\r
+ * Clears the seed and mnemonic from the vault.\r
*/\r
- async lock (): Promise<boolean> {\r
- try {\r
- const { isLocked } = await this.#vault.request<boolean>({\r
- action: 'lock'\r
- })\r
- if (!isLocked) {\r
- throw new Error('Lock request to Vault failed')\r
- }\r
- clearTimeout(this.#lockTimer)\r
- return isLocked\r
- } catch (err) {\r
- throw new Error('Failed to lock wallet', { cause: err })\r
- }\r
+ lock (): void {\r
+ _lock(this.#vault)\r
+ clearTimeout(this.#lockTimer)\r
}\r
\r
/**\r
* Unlocks the wallet using the same password as used prior to lock it.\r
*\r
* @param {string} password Used previously to lock the wallet\r
- * @returns True if successfully unlocked\r
*/\r
async unlock (password: string): Promise<void> {\r
await _unlock(this, this.#vault, password)\r
*/\r
async destroy (): Promise<void> {\r
await super.destroy()\r
- if (!(await this.lock())) {\r
- throw new Error('Failed to lock Ledger wallet')\r
- }\r
+ this.lock()\r
}\r
\r
/**\r
*\r
* Overrides the default wallet `lock()` method since as a hardware wallet it\r
* does not need to be encrypted by software.\r
- *\r
- * @returns True if successfully locked\r
*/\r
- async lock (): Promise<boolean> {\r
- try {\r
+ lock (): void {\r
+ setTimeout(async () => {\r
const devices = await globalThis.navigator.usb.getDevices()\r
for (const device of devices) {\r
if (device.vendorId === ledgerUSBVendorId) {\r
- await device.forget()\r
+ device.forget()\r
}\r
}\r
- return new Promise(r => setTimeout(r, 0, true))\r
- } catch (err) {\r
- console.log(err)\r
- return new Promise(r => setTimeout(r, 0, false))\r
- }\r
+ })\r
}\r
\r
/**\r
--- /dev/null
+//! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>
+//! SPDX-License-Identifier: GPL-3.0-or-later
+
+import { WorkerQueue } from '../vault/worker-queue'
+
+export async function _lock (vault: WorkerQueue): Promise<void>
+export async function _lock (vault: WorkerQueue): Promise<void> {
+ try {
+ const { isLocked } = await vault.request<boolean>({
+ action: 'lock'
+ })
+ if (!isLocked) {
+ throw new Error('Lock request to Vault failed')
+ }
+ } catch (err) {
+ throw new Error('Failed to lock wallet', { cause: err })
+ }
+}
await test('fail to unlock a Bip44Wallet with different passwords', async () => {\r
const wallet = await Wallet.load('BIP-44', NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.MNEMONIC, NANO_TEST_VECTORS.PASSWORD)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
- const lockResult = await wallet.lock()\r
+ wallet.lock()\r
+\r
+ await assert.rejects(wallet.verify(NANO_TEST_VECTORS.MNEMONIC))\r
+ await assert.rejects(wallet.verify(NANO_TEST_VECTORS.BIP39_SEED))\r
+ assert.ok('mnemonic' in wallet)\r
+ assert.ok('seed' in wallet)\r
+ assert.ok(wallet.mnemonic === undefined)\r
+ assert.ok(wallet.seed === undefined)\r
\r
await assert.rejects(wallet.unlock(TREZOR_TEST_VECTORS.PASSWORD), { message: 'Failed to unlock wallet' })\r
- assert.equal(lockResult, true)\r
assert.ok('mnemonic' in wallet)\r
assert.ok('seed' in wallet)\r
assert.ok(wallet.mnemonic === undefined)\r