Skip to content

Commit

Permalink
chore: replace TransportWebUSB with TransportWebHID
Browse files Browse the repository at this point in the history
  • Loading branch information
iosh committed Nov 22, 2024
1 parent d0ff94d commit ec3494d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
22 changes: 15 additions & 7 deletions packages/ledger/conflux.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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)
}
Expand Down Expand Up @@ -85,7 +90,7 @@ export default class Conflux {
}

async isDeviceAuthed() {
const devices = await TransportWebUSB.list()
const devices = await TransportWebHID.list()
return Boolean(devices.length)
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
21 changes: 14 additions & 7 deletions packages/ledger/ethereum.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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)
}
Expand Down Expand Up @@ -103,7 +107,7 @@ export default class Ethereum {
}

async isDeviceAuthed() {
const devices = await TransportWebUSB.list()
const devices = await TransportWebHID.list()
return Boolean(devices.length)
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions packages/ledger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit ec3494d

Please sign in to comment.