]> git.codecow.com Git - libnemo.git/commitdiff
Add UNSUPPORTED as a valid Ledger status instead of throwing.
authorChris Duncan <chris@zoso.dev>
Tue, 16 Sep 2025 20:44:03 +0000 (13:44 -0700)
committerChris Duncan <chris@zoso.dev>
Tue, 16 Sep 2025 20:44:03 +0000 (13:44 -0700)
src/lib/ledger.ts
src/types.d.ts

index 9d3b4b4cf9fad7c6af186ca18a975b5f5e75e999..dce46580b47215b656d4dcf2b6a8494780323a70 100644 (file)
@@ -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<LedgerStatus> {
-               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
        }
 
        /**
index 7c411d6fa529be8016c352a0e8c358495f6e02ac..f4839d585611ae768d05d0457eead3eff7efc7b3 100644 (file)
@@ -450,7 +450,7 @@ export type KeyPair = {
        publicKey?: string | Uint8Array<ArrayBuffer>
 }
 
-export type LedgerStatus = 'DISCONNECTED' | 'BUSY' | 'LOCKED' | 'CONNECTED'
+export type LedgerStatus = 'UNSUPPORTED' | 'DISCONNECTED' | 'BUSY' | 'LOCKED' | 'CONNECTED'
 
 interface LedgerResponse {
        status: string