]> git.codecow.com Git - libnemo.git/commitdiff
Fix wallet destruction. Adjust Ledger browser support check.
authorChris Duncan <chris@zoso.dev>
Sun, 27 Jul 2025 07:28:44 +0000 (00:28 -0700)
committerChris Duncan <chris@zoso.dev>
Sun, 27 Jul 2025 07:28:44 +0000 (00:28 -0700)
src/lib/wallets/ledger-wallet.ts
src/lib/wallets/wallet.ts
src/types.d.ts
test/test.ledger.mjs

index cd5c947f8368409c8d7e69ea70a0ad5adb580000..70764080c322651f677f939d2829751c6a5d46ac 100644 (file)
@@ -35,17 +35,21 @@ export class LedgerWallet extends Wallet {
        * Check which transport protocols are supported by the browser and return the\r
        * transport type according to the following priorities: Bluetooth, USB, HID.\r
        */\r
-       static checkBrowserSupport (): void {\r
+       static get isUnsupported (): boolean {\r
                console.log('Checking browser Ledger support...')\r
-               if (typeof globalThis.navigator?.bluetooth?.getDevices === 'function') {\r
-                       this.DynamicTransport = TransportBLE\r
-               }\r
                if (typeof globalThis.navigator?.usb?.getDevices === 'function') {\r
                        this.DynamicTransport = TransportUSB\r
+                       return false\r
+               }\r
+               if (typeof globalThis.navigator?.bluetooth?.getDevices === 'function') {\r
+                       this.DynamicTransport = TransportBLE\r
+                       return false\r
                }\r
                if (typeof globalThis.navigator?.hid?.getDevices === 'function') {\r
                        this.DynamicTransport = TransportHID\r
+                       return false\r
                }\r
+               return true\r
        }\r
 \r
        /**\r
@@ -56,6 +60,7 @@ export class LedgerWallet extends Wallet {
        */\r
        static async create (): Promise<LedgerWallet> {\r
                try {\r
+                       if (this.isUnsupported) throw new Error('Browser is unsupported')\r
                        const id = await Entropy.create(16)\r
                        LedgerWallet.#isInternal = true\r
                        const wallet = new this(id)\r
index c09a0e1ec400ae9cb6114f6107b5b3002647ba0e..d4981c3ab702989cdd4a635b5678c253ba2105da 100644 (file)
@@ -178,7 +178,7 @@ export abstract class Wallet {
                        await SafeWorker.request<boolean>({\r
                                store: 'Wallet',\r
                                method: 'destroy',\r
-                               name: this.id\r
+                               names: this.id\r
                        })\r
                } catch (err) {\r
                        console.error(err)\r
index a68fc92308f3cdc269b745ada1d68147b8595bcd..e02eb80be2e4f6eb8a0a8bbc576b92ed7fa39881 100644 (file)
@@ -932,16 +932,14 @@ interface LedgerSignResponse extends LedgerResponse {
 */
 export declare class LedgerWallet extends Wallet {
        #private
-       get listenTimeout (): 30000
-       get openTimeout (): 3000
-       get status (): DeviceStatus
-       DynamicTransport: typeof TransportBLE | typeof TransportUSB | typeof TransportHID
-       private constructor ()
+       static DynamicTransport: typeof TransportBLE | typeof TransportUSB | typeof TransportHID
+       static get listenTimeout (): 30000
+       static get openTimeout (): 3000
        /**
        * Check which transport protocols are supported by the browser and return the
        * transport type according to the following priorities: Bluetooth, USB, HID.
        */
-       static checkBrowserSupport (): typeof TransportBLE | typeof TransportUSB | typeof TransportHID
+       static get isUnsupported (): boolean
        /**
        * Creates a new Ledger hardware wallet communication layer by dynamically
        * importing the ledger.js service.
@@ -949,6 +947,8 @@ export declare class LedgerWallet extends Wallet {
        * @returns {LedgerWallet} A wallet containing accounts and a Ledger device communication object
        */
        static create (): Promise<LedgerWallet>
+       get status (): DeviceStatus
+       private constructor ()
        /**
        * Check if the Nano app is currently open and set device status accordingly.
        *
@@ -964,7 +964,6 @@ export declare class LedgerWallet extends Wallet {
        * allow garbage collection.
        */
        destroy (): Promise<void>
-       init (): Promise<void>
        /**
        * Revokes permission granted by the user to access the Ledger device.
        *
index c334655c5dbdcbb3ae9250153f348a374bd063ad..51b8bb53e4e314457dc638115b4ec966d887bd83 100644 (file)
@@ -35,19 +35,13 @@ if (isNode) {
 
 const rpc = new Rpc(env.NODE_URL ?? '', env.API_KEY_NAME)
 
-let isUnsupported = true
-try {
-       LedgerWallet.checkBrowserSupport()
-       isUnsupported = false
-} catch {}
-
 /**
 * HID interactions require user gestures, so to reduce clicks, the variables
 * shared among tests like wallet and account are declared at the top-level.
 */
 await Promise.all([
        /* node:coverage disable */
-       suite('Ledger hardware wallet', { skip: false || isNode || isUnsupported }, async () => {
+       suite('Ledger hardware wallet', { skip: false || isNode || LedgerWallet.isUnsupported }, async () => {
 
                let wallet, account, openBlock, sendBlock, receiveBlock