From: Chris Duncan Date: Sun, 14 Sep 2025 20:41:51 +0000 (-0700) Subject: Move Ledger disconnect function out of wallet lock method and into Ledger class.... X-Git-Tag: v0.10.5~14^2~27 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=dbef0f45ac34a74ca3f9649525e5172ca28f884f;p=libnemo.git Move Ledger disconnect function out of wallet lock method and into Ledger class. Add disconnect loops for HID and BLE in addition to USB. --- diff --git a/src/lib/wallet/ledger.ts b/src/lib/wallet/ledger.ts index af7b93f..3b7e3ea 100644 --- a/src/lib/wallet/ledger.ts +++ b/src/lib/wallet/ledger.ts @@ -3,8 +3,8 @@ import { ledgerUSBVendorId } from '@ledgerhq/devices' import { default as TransportBLE } from '@ledgerhq/hw-transport-web-ble' -import { default as TransportUSB } from '@ledgerhq/hw-transport-webusb' import { default as TransportHID } from '@ledgerhq/hw-transport-webhid' +import { default as TransportUSB } from '@ledgerhq/hw-transport-webusb' import { DeviceStatus, LedgerAccountResponse, LedgerResponse, LedgerSignResponse, LedgerVersionResponse } from '#types' import { Account } from '../account' import { Block } from '../block' @@ -135,7 +135,7 @@ export class Ledger { if (version.status !== 'OK') { this.#status = 'DISCONNECTED' } else if (version.name === 'Nano') { - const { status } = await Ledger.account() + const { status } = await this.account() if (status === 'OK') { this.#status = 'CONNECTED' } else if (status === 'SECURITY_STATUS_NOT_SATISFIED') { @@ -149,6 +149,30 @@ export class Ledger { return this.#status } + /** + * + */ + static disconnect (): void { + setTimeout(async () => { + const hidDevices = await globalThis.navigator.hid.getDevices() + for (const device of hidDevices) { + if (device.vendorId === this.UsbVendorId) { + device.forget() + } + } + const bleDevices = await globalThis.navigator.bluetooth.getDevices() + for (const device of bleDevices) { + TransportBLE.disconnect(device.id) + } + const usbDevices = await globalThis.navigator.usb.getDevices() + for (const device of usbDevices) { + if (device.vendorId === this.UsbVendorId) { + device.forget() + } + } + }) + } + /** * Sign a block with the Ledger device. * diff --git a/src/lib/wallet/lock.ts b/src/lib/wallet/lock.ts index 7d09220..a65773f 100644 --- a/src/lib/wallet/lock.ts +++ b/src/lib/wallet/lock.ts @@ -8,14 +8,7 @@ export async function _lock (wallet: Wallet, vault: Vault): Promise { try { if (wallet.type === 'Ledger') { const { Ledger } = await import('./ledger') - setTimeout(async () => { - const devices = await globalThis.navigator.usb.getDevices() - for (const device of devices) { - if (device.vendorId === Ledger.UsbVendorId) { - device.forget() - } - } - }) + Ledger.disconnect() } else { await vault.request({ action: 'lock'