@@ -29,9 +29,8 @@ import (
2929const (
3030 VendorLedger = 0x2c97
3131 UsagePageLedgerNanoS = 0xffa0
32- //ProductNano = 1
33- Channel = 0x0101
34- PacketSize = 64
32+ Channel = 0x0101
33+ PacketSize = 64
3534)
3635
3736type LedgerAdminHID struct {}
@@ -42,6 +41,12 @@ type LedgerDeviceHID struct {
4241 readChannel chan []byte
4342}
4443
44+ // list of supported product ids as well as their corresponding interfaces
45+ var supportedLedgerProductID = map [uint16 ]int {
46+ 0x4011 : 0 , // Ledger Nano X
47+ 0x1011 : 0 , // Ledger Nano S
48+ }
49+
4550func NewLedgerAdmin () * LedgerAdminHID {
4651 return & LedgerAdminHID {}
4752}
@@ -72,9 +77,11 @@ func (admin *LedgerAdminHID) ListDevices() ([]string, error) {
7277func isLedgerDevice (d hid.DeviceInfo ) bool {
7378 deviceFound := d .UsagePage == UsagePageLedgerNanoS
7479 // Workarounds for possible empty usage pages
75- return deviceFound ||
76- (d .Product == "Nano S" && d .Interface == 0 ) ||
77- (d .Product == "Nano X" && d .Interface == 0 )
80+ if interfaceID , supported := supportedLedgerProductID [d .ProductID ]; deviceFound || (supported && (interfaceID == d .Interface )) {
81+ return true
82+ }
83+
84+ return false
7885}
7986
8087func (admin * LedgerAdminHID ) CountDevices () int {
@@ -92,8 +99,8 @@ func (admin *LedgerAdminHID) CountDevices() int {
9299
93100func newDevice (dev * hid.Device ) * LedgerDeviceHID {
94101 return & LedgerDeviceHID {
95- device : dev ,
96- readCo : new (sync.Once ),
102+ device : dev ,
103+ readCo : new (sync.Once ),
97104 readChannel : make (chan []byte ),
98105 }
99106}
0 commit comments