Skip to content

Commit d150aa5

Browse files
mdehoogqianhh
authored andcommitted
accounts/usbwallet: fix ledger access for latest firmware and add Ledger Flex (#31004)
The latest firmware for Ledger Nano S Plus now returns `0x5000` for it's product ID, which doesn't match any of the product IDs enumerated in `hub.go`. This PR removes the assumption about the interfaces exposed, and simply checks the upper byte for a match. Also adds support for the `0x0007` / `0x7000` product ID (Ledger Flex).
1 parent 22d5a9b commit d150aa5

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

accounts/usbwallet/hub.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,22 @@ func NewLedgerHub() (*Hub, error) {
7373
return newHub(LedgerScheme, 0x2c97, []uint16{
7474

7575
// Device definitions taken from
76-
// https://github.com/LedgerHQ/ledger-live/blob/38012bc8899e0f07149ea9cfe7e64b2c146bc92b/libs/ledgerjs/packages/devices/src/index.ts
76+
// https://github.com/LedgerHQ/ledger-live/blob/595cb73b7e6622dbbcfc11867082ddc886f1bf01/libs/ledgerjs/packages/devices/src/index.ts
7777

7878
// Original product IDs
7979
0x0000, /* Ledger Blue */
8080
0x0001, /* Ledger Nano S */
8181
0x0004, /* Ledger Nano X */
8282
0x0005, /* Ledger Nano S Plus */
8383
0x0006, /* Ledger Nano FTS */
84-
85-
0x0015, /* HID + U2F + WebUSB Ledger Blue */
86-
0x1015, /* HID + U2F + WebUSB Ledger Nano S */
87-
0x4015, /* HID + U2F + WebUSB Ledger Nano X */
88-
0x5015, /* HID + U2F + WebUSB Ledger Nano S Plus */
89-
0x6015, /* HID + U2F + WebUSB Ledger Nano FTS */
90-
91-
0x0011, /* HID + WebUSB Ledger Blue */
92-
0x1011, /* HID + WebUSB Ledger Nano S */
93-
0x4011, /* HID + WebUSB Ledger Nano X */
94-
0x5011, /* HID + WebUSB Ledger Nano S Plus */
95-
0x6011, /* HID + WebUSB Ledger Nano FTS */
84+
0x0007, /* Ledger Flex */
85+
86+
0x0000, /* WebUSB Ledger Blue */
87+
0x1000, /* WebUSB Ledger Nano S */
88+
0x4000, /* WebUSB Ledger Nano X */
89+
0x5000, /* WebUSB Ledger Nano S Plus */
90+
0x6000, /* WebUSB Ledger Nano FTS */
91+
0x7000, /* WebUSB Ledger Flex */
9692
}, 0xffa0, 0, newLedgerDriver)
9793
}
9894

@@ -185,8 +181,11 @@ func (hub *Hub) refreshWallets() {
185181

186182
for _, info := range infos {
187183
for _, id := range hub.productIDs {
184+
// We check both the raw ProductID (legacy) and just the upper byte, as Ledger
185+
// uses `MMII`, encoding a model (MM) and an interface bitfield (II)
186+
mmOnly := info.ProductID & 0xff00
188187
// Windows and Macos use UsageID matching, Linux uses Interface matching
189-
if info.ProductID == id && (info.UsagePage == hub.usageID || info.Interface == hub.endpointID) {
188+
if (info.ProductID == id || mmOnly == id) && (info.UsagePage == hub.usageID || info.Interface == hub.endpointID) {
190189
devices = append(devices, info)
191190
break
192191
}

0 commit comments

Comments
 (0)