From 465a3927df1b04ed7414274466c6d89c68ddfbc7 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Tue, 16 Sep 2025 13:44:03 -0700 Subject: [PATCH] Add UNSUPPORTED as a valid Ledger status instead of throwing. --- src/lib/ledger.ts | 23 ++++++++++++++--------- src/types.d.ts | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/lib/ledger.ts b/src/lib/ledger.ts index 9d3b4b4..dce4658 100644 --- a/src/lib/ledger.ts +++ b/src/lib/ledger.ts @@ -55,8 +55,6 @@ export class Ledger { 0x9000: 'OK' }) - static get UsbVendorId (): typeof ledgerUSBVendorId { return ledgerUSBVendorId } - /** * Check which transport protocols are supported by the browser and return the * transport type according to the following priorities: HID, Bluetooth, USB. @@ -83,9 +81,18 @@ export class Ledger { /** * Status of the Ledger device connection. * - * DISCONNECTED | BUSY | LOCKED | CONNECTED + * UNSUPPORTED | DISCONNECTED | BUSY | LOCKED | CONNECTED */ - static get status (): LedgerStatus { return this.#status } + static get status (): LedgerStatus { + return this.isUnsupported ? 'UNSUPPORTED' : this.#status + } + + /** + * Vendor ID assigned to Ledger for HID and USB interfaces. + */ + static get UsbVendorId (): typeof ledgerUSBVendorId { + return ledgerUSBVendorId + } /** * Request an account at a specific BIP-44 index. @@ -127,15 +134,13 @@ export class Ledger { * * @param {string} [api] Transport interface to use * @returns Device status as follows: + * - UNSUPPORTED: Platform does not support any Ledger transport protocols * - DISCONNECTED: Failed to communicate properly with the app * - BUSY: Nano app is not currently open * - LOCKED: Nano app is open but the device locked after a timeout * - CONNECTED: Nano app is open and listening */ static async connect (api?: 'hid' | 'ble' | 'usb'): Promise { - if (Ledger.isUnsupported) { - throw new Error('Browser is unsupported') - } if (api !== undefined) { if (api === 'hid' && Ledger.#transport !== TransportHID) { Ledger.#transport = TransportHID @@ -167,8 +172,8 @@ export class Ledger { console.error(err) this.#status = 'DISCONNECTED' } - console.log(this.#status) - return this.#status + console.log(this.status) + return this.status } /** diff --git a/src/types.d.ts b/src/types.d.ts index 7c411d6..f4839d5 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -450,7 +450,7 @@ export type KeyPair = { publicKey?: string | Uint8Array } -export type LedgerStatus = 'DISCONNECTED' | 'BUSY' | 'LOCKED' | 'CONNECTED' +export type LedgerStatus = 'UNSUPPORTED' | 'DISCONNECTED' | 'BUSY' | 'LOCKED' | 'CONNECTED' interface LedgerResponse { status: string -- 2.47.3