*/\r
async destroy (): Promise<void> {\r
await super.destroy()\r
- const { status } = await this.#close()\r
- if (status !== 'OK') {\r
- throw new Error('Failed to lock Ledger wallet', { cause: status })\r
+ if (!(await this.lock())) {\r
+ throw new Error('Failed to lock Ledger wallet')\r
}\r
}\r
\r
}\r
\r
/**\r
- * Attempts to close the current process on the Ledger device.\r
+ * Revokes permission granted by the user to access the Ledger device.\r
+ *\r
+ * The 'quit app' ADPU command has not passed testing, so this is the only way\r
+ * to ensure the connection is severed at this time. `setTimeout` is used to\r
+ * expire any lingering transient user activation.\r
*\r
* Overrides the default wallet `lock()` method since as a hardware wallet it\r
* does not need to be encrypted by software.\r
* @returns True if successfully locked\r
*/\r
async lock (): Promise<boolean> {\r
- const { status } = await this.#close()\r
- return status === 'OK'\r
+ try {\r
+ const devices = await globalThis.navigator.usb.getDevices()\r
+ for (const device of devices) {\r
+ if (device.vendorId === ledgerUSBVendorId) {\r
+ await 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
onConnectUsb = async (e: USBConnectionEvent): Promise<void> => {\r
})
await test('destroy wallet', async () => {
- await assert.resolves(wallet.destroy())
+ await wallet.destroy()
+ await assert.rejects(wallet.version())
})
await test('fail when using new', async () => {