@@ -25,7 +25,7 @@ import (
2525 "github.com/ethereum/go-ethereum/accounts"
2626 "github.com/ethereum/go-ethereum/event"
2727 "github.com/ethereum/go-ethereum/log"
28- "github.com/karalabe/hid "
28+ "github.com/karalabe/usb "
2929)
3030
3131// LedgerScheme is the protocol scheme prefixing account and wallet URLs.
@@ -84,14 +84,20 @@ func NewLedgerHub() (*Hub, error) {
8484 }, 0xffa0 , 0 , newLedgerDriver )
8585}
8686
87- // NewTrezorHub creates a new hardware wallet manager for Trezor devices.
88- func NewTrezorHub () (* Hub , error ) {
89- return newHub (TrezorScheme , 0x534c , []uint16 {0x0001 /* Trezor 1 */ }, 0xff00 , 0 , newTrezorDriver )
87+ // NewTrezorHubWithHID creates a new hardware wallet manager for Trezor devices.
88+ func NewTrezorHubWithHID () (* Hub , error ) {
89+ return newHub (TrezorScheme , 0x534c , []uint16 {0x0001 /* Trezor HID */ }, 0xff00 , 0 , newTrezorDriver )
90+ }
91+
92+ // NewTrezorHubWithWebUSB creates a new hardware wallet manager for Trezor devices with
93+ // firmware version > 1.8.0
94+ func NewTrezorHubWithWebUSB () (* Hub , error ) {
95+ return newHub (TrezorScheme , 0x1209 , []uint16 {0x53c1 /* Trezor WebUSB */ }, 0xffff /* No usage id on webusb, don't match unset (0) */ , 0 , newTrezorDriver )
9096}
9197
9298// newHub creates a new hardware wallet manager for generic USB devices.
9399func newHub (scheme string , vendorID uint16 , productIDs []uint16 , usageID uint16 , endpointID int , makeDriver func (log.Logger ) driver ) (* Hub , error ) {
94- if ! hid .Supported () {
100+ if ! usb .Supported () {
95101 return nil , errors .New ("unsupported platform" )
96102 }
97103 hub := & Hub {
@@ -133,7 +139,7 @@ func (hub *Hub) refreshWallets() {
133139 return
134140 }
135141 // Retrieve the current list of USB wallet devices
136- var devices []hid .DeviceInfo
142+ var devices []usb .DeviceInfo
137143
138144 if runtime .GOOS == "linux" {
139145 // hidapi on Linux opens the device during enumeration to retrieve some infos,
@@ -148,8 +154,18 @@ func (hub *Hub) refreshWallets() {
148154 return
149155 }
150156 }
151- for _ , info := range hid .Enumerate (hub .vendorID , 0 ) {
157+ infos , err := usb .Enumerate (hub .vendorID , 0 )
158+ if err != nil {
159+ if runtime .GOOS == "linux" {
160+ // See rationale before the enumeration why this is needed and only on Linux.
161+ hub .commsLock .Unlock ()
162+ }
163+ log .Error ("error enumerating USB enumeration: " , "code" , err )
164+ return
165+ }
166+ for _ , info := range infos {
152167 for _ , id := range hub .productIDs {
168+ // Windows and Macos use UsageID matching, Linux uses Interface matching
153169 if info .ProductID == id && (info .UsagePage == hub .usageID || info .Interface == hub .endpointID ) {
154170 devices = append (devices , info )
155171 break
0 commit comments