Skip to content

Commit 704180b

Browse files
authored
Merge pull request #18 from troian/fix-ledger-pid
fix: use productID to detect ledger type
2 parents 73b5de1 + a706abf commit 704180b

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

ledger_hid.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ import (
2929
const (
3030
VendorLedger = 0x2c97
3131
UsagePageLedgerNanoS = 0xffa0
32-
//ProductNano = 1
33-
Channel = 0x0101
34-
PacketSize = 64
32+
Channel = 0x0101
33+
PacketSize = 64
3534
)
3635

3736
type 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+
4550
func NewLedgerAdmin() *LedgerAdminHID {
4651
return &LedgerAdminHID{}
4752
}
@@ -72,9 +77,11 @@ func (admin *LedgerAdminHID) ListDevices() ([]string, error) {
7277
func 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

8087
func (admin *LedgerAdminHID) CountDevices() int {
@@ -92,8 +99,8 @@ func (admin *LedgerAdminHID) CountDevices() int {
9299

93100
func 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

Comments
 (0)