From ec3494d2b3c163542663ab8edddeadee756ba542 Mon Sep 17 00:00:00 2001 From: iosh Date: Fri, 22 Nov 2024 15:50:10 +0800 Subject: [PATCH] chore: replace TransportWebUSB with TransportWebHID --- packages/ledger/conflux.js | 22 +++++++++++++++------- packages/ledger/ethereum.js | 21 ++++++++++++++------- packages/ledger/package.json | 4 ++-- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/packages/ledger/conflux.js b/packages/ledger/conflux.js index c812d4a44..dd1de13fa 100644 --- a/packages/ledger/conflux.js +++ b/packages/ledger/conflux.js @@ -1,4 +1,4 @@ -import TransportWebUSB from '@ledgerhq/hw-transport-webusb' +import TransportWebHID from '@ledgerhq/hw-transport-webhid' import {decode} from '@fluent-wallet/base32-address' import {LEDGER_APP_NAME, LEDGER_CLA, INS, HDPATH, ERROR} from './const.js' import {handleName} from './index.js' @@ -20,12 +20,17 @@ export default class Conflux { this.transport = null } + async createApp(transport) { + const App = await import('@fluent-wallet/hw-app-conflux') + this.app = new App.default(transport) + this.transport = transport + } + async setApp() { if (!this.app) { try { - this.transport = await TransportWebUSB.create() - const App = await import('@fluent-wallet/hw-app-conflux') - this.app = new App.default(this.transport) + const transport = await TransportWebHID.create() + await this.createApp(transport) } catch (error) { console.warn(error) } @@ -85,7 +90,7 @@ export default class Conflux { } async isDeviceAuthed() { - const devices = await TransportWebUSB.list() + const devices = await TransportWebHID.list() return Boolean(devices.length) } @@ -123,7 +128,10 @@ export default class Conflux { */ async requestAuth() { try { - await TransportWebUSB?.request() + const transport = await TransportWebHID?.request() + if (!this.app) { + await this.createApp(transport) + } return true } catch (error) { return false @@ -154,7 +162,7 @@ export default class Conflux { } async getDeviceInfo() { - const devices = await TransportWebUSB.list() + const devices = await TransportWebHID.list() if (devices.length > 0) { const device = devices[0] return { diff --git a/packages/ledger/ethereum.js b/packages/ledger/ethereum.js index 2b5759f0d..ac60d506c 100644 --- a/packages/ledger/ethereum.js +++ b/packages/ledger/ethereum.js @@ -1,4 +1,4 @@ -import TransportWebUSB from '@ledgerhq/hw-transport-webusb' +import TransportWebHID from '@ledgerhq/hw-transport-webhid' import {LEDGER_APP_NAME, LEDGER_CLA, INS, HDPATH, ERROR} from './const.js' import {handleName} from './index.js' @@ -19,13 +19,17 @@ export default class Ethereum { this.app = null this.transport = null } + async createApp(transport) { + const App = await import('@ledgerhq/hw-app-eth') + this.app = new App.default(transport) + this.transport = transport + } async setApp() { if (!this.app) { try { - this.transport = await TransportWebUSB.create() - const App = await import('@ledgerhq/hw-app-eth') - this.app = new App.default(this.transport) + const transport = await TransportWebHID.create() + await this.createApp(transport) } catch (error) { console.warn(error) } @@ -103,7 +107,7 @@ export default class Ethereum { } async isDeviceAuthed() { - const devices = await TransportWebUSB.list() + const devices = await TransportWebHID.list() return Boolean(devices.length) } @@ -155,7 +159,10 @@ export default class Ethereum { */ async requestAuth() { try { - await TransportWebUSB?.request() + const transport = await TransportWebHID?.request() + if (!this.app) { + await this.createApp(transport) + } return true } catch (error) { return false @@ -185,7 +192,7 @@ export default class Ethereum { } async getDeviceInfo() { - const devices = await TransportWebUSB.list() + const devices = await TransportWebHID.list() if (devices.length > 0) { const device = devices[0] return { diff --git a/packages/ledger/package.json b/packages/ledger/package.json index 3455d1cbc..05391ea72 100644 --- a/packages/ledger/package.json +++ b/packages/ledger/package.json @@ -5,8 +5,8 @@ "version": "0.0.9", "dependencies": { "@fluent-wallet/base32-address": "workspace:packages/base32-address", - "@fluent-wallet/hw-app-conflux": "0.0.8", + "@fluent-wallet/hw-app-conflux": "0.1.1", "@ledgerhq/hw-app-eth": "6.24.1", - "@ledgerhq/hw-transport-webusb": "6.29.2" + "@ledgerhq/hw-transport-webhid": "6.29.4" } }