]> git.codecow.com Git - libnemo.git/commitdiff
Close devices instead of forgetting them.
authorChris Duncan <chris@zoso.dev>
Fri, 19 Sep 2025 21:06:51 +0000 (14:06 -0700)
committerChris Duncan <chris@zoso.dev>
Fri, 19 Sep 2025 21:06:51 +0000 (14:06 -0700)
src/lib/ledger.ts
test/test.ledger.mjs

index 869c45204242ee11af0760b0349c3059bf6f9803..4f7d989c2f40d369ebc4c29c5f14c151b2a1dfb4 100644 (file)
@@ -221,26 +221,16 @@ export class Ledger {
        }
 
        /**
-       * Clears Ledger connections from all device interfaces.
+       * Clears Ledger connections from HID and USB interfaces.
        */
        static disconnect (): void {
                setTimeout(async () => {
-                       const hidDevices = await globalThis.navigator?.hid?.getDevices?.() ?? []
-                       for (const device of hidDevices) {
-                               if (device.vendorId === this.ledgerVendorId) {
-                                       device.forget()
-                               }
-                       }
-                       const bleDevices = await globalThis.navigator?.bluetooth?.getDevices?.() ?? []
-                       for (const device of bleDevices) {
-                               TransportBLE.disconnect(device.id).catch(() => { })
-                       }
-                       const usbDevices = await globalThis.navigator?.usb?.getDevices?.() ?? []
-                       for (const device of usbDevices) {
-                               if (device.vendorId === this.ledgerVendorId) {
-                                       device.forget()
-                               }
-                       }
+                       const hidDevices = (await navigator?.hid?.getDevices?.())
+                               .filter(device => device.vendorId === this.ledgerVendorId)
+                               .map(device => device.close())
+                       const usbDevices = (await navigator?.usb?.getDevices?.())
+                               .filter(device => device.vendorId === this.ledgerVendorId)
+                               .map(device => device.close())
                        this.#status = 'DISCONNECTED'
                })
        }
index e3a918831e0731733b4747bb2ad5b78d8f7ca3b6..a33991258a30690183aa8ccfe524c5ee41b55517 100644 (file)
@@ -53,7 +53,7 @@ await Promise.all([
                })
        }),
 
-       suite('Ledger hardware wallet', { skip: false || isNode || navigator?.usb == null }, async () => {
+       suite('Ledger hardware wallet', { skip: isNode || navigator?.usb == null }, async () => {
 
                const { LEDGER_MNEMONIC, LEDGER_SEED, LEDGER_PUBLIC_0, LEDGER_ADDRESS_0 } = CUSTOM_TEST_VECTORS
                const { OPEN_BLOCK, RECEIVE_BLOCK, SEND_BLOCK } = NANO_TEST_VECTORS
@@ -139,9 +139,18 @@ await Promise.all([
                                        resolve(null)
                                }, 90000)
                        })
+
+                       await assert.resolves(async () => {
+                               await click(
+                                       'Unlock device again, then click to continue',
+                                       async () => {}
+                               )
+                       })
+                       assert.equal(wallet.isLocked, false)
+                       assert.equal(Ledger.status, 'CONNECTED')
                })
 
-               await test('switch between interfaces', { skip: false }, async () => {
+               await test('switch between interfaces', { skip: false || isNode || navigator?.usb == null }, async () => {
                        await assert.resolves(async () => {
                                await click(
                                        'Verify current interface is HID, switch to unlocked Bluetooth device, then click to continue',