@@ -43,6 +43,36 @@ const refreshCycle = time.Second
4343// trashing.
4444const refreshThrottling = 500 * time .Millisecond
4545
46+ const (
47+ // deviceUsagePage identifies Ledger devices by HID usage page (0xffa0) on Windows and macOS.
48+ // See: https://github.com/LedgerHQ/ledger-live/blob/05a2980e838955a11a1418da638ef8ac3df4fb74/libs/ledgerjs/packages/hw-transport-node-hid-noevents/src/TransportNodeHid.ts
49+ deviceUsagePage = 0xffa0
50+ // deviceInterface identifies Ledger devices by USB interface number (0) on Linux.
51+ deviceInterface = 0
52+ )
53+
54+ // ledgerProductIDs contains all supported Ledger USB product IDs (legacy and WebUSB).
55+ // Device definitions taken from
56+ // https://github.com/LedgerHQ/ledger-live/blob/05a2980e838955a11a1418da638ef8ac3df4fb74/libs/ledgerjs/packages/devices/src/index.ts
57+ var ledgerProductIDs = []uint16 {
58+ // Original product IDs
59+ 0x0000 , /* Ledger Blue */
60+ 0x0001 , /* Ledger Nano S */
61+ 0x0004 , /* Ledger Nano X */
62+ 0x0005 , /* Ledger Nano S Plus */
63+ 0x0006 , /* Ledger Nano FTS */
64+ 0x0007 , /* Ledger Flex */
65+ 0x0008 , /* Ledger Nano Gen5 */
66+
67+ 0x0000 , /* WebUSB Ledger Blue */
68+ 0x1000 , /* WebUSB Ledger Nano S */
69+ 0x4000 , /* WebUSB Ledger Nano X */
70+ 0x5000 , /* WebUSB Ledger Nano S Plus */
71+ 0x6000 , /* WebUSB Ledger Nano FTS */
72+ 0x7000 , /* WebUSB Ledger Flex */
73+ 0x8000 , /* WebUSB Ledger Nano Gen5 */
74+ }
75+
4676// Hub is a accounts.Backend that can find and handle generic USB hardware wallets.
4777type Hub struct {
4878 scheme string // Protocol scheme prefixing account and wallet URLs.
@@ -70,28 +100,7 @@ type Hub struct {
70100
71101// NewLedgerHub creates a new hardware wallet manager for Ledger devices.
72102func NewLedgerHub () (* Hub , error ) {
73- return newHub (LedgerScheme , 0x2c97 , []uint16 {
74-
75- // Device definitions taken from
76- // https://github.com/LedgerHQ/ledger-live/blob/595cb73b7e6622dbbcfc11867082ddc886f1bf01/libs/ledgerjs/packages/devices/src/index.ts
77-
78- // Original product IDs
79- 0x0000 , /* Ledger Blue */
80- 0x0001 , /* Ledger Nano S */
81- 0x0004 , /* Ledger Nano X */
82- 0x0005 , /* Ledger Nano S Plus */
83- 0x0006 , /* Ledger Nano FTS */
84- 0x0007 , /* Ledger Flex */
85- 0x0008 , /* Ledger Nano Gen5 */
86-
87- 0x0000 , /* WebUSB Ledger Blue */
88- 0x1000 , /* WebUSB Ledger Nano S */
89- 0x4000 , /* WebUSB Ledger Nano X */
90- 0x5000 , /* WebUSB Ledger Nano S Plus */
91- 0x6000 , /* WebUSB Ledger Nano FTS */
92- 0x7000 , /* WebUSB Ledger Flex */
93- 0x8000 , /* WebUSB Ledger Nano Gen5 */
94- }, 0xffa0 , 0 , newLedgerDriver )
103+ return newHub (LedgerScheme , 0x2c97 , ledgerProductIDs , deviceUsagePage , deviceInterface , newLedgerDriver )
95104}
96105
97106// NewTrezorHubWithHID creates a new hardware wallet manager for Trezor devices.
@@ -168,7 +177,7 @@ func (hub *Hub) refreshWallets() {
168177 return
169178 }
170179 }
171- infos , err := hid . Enumerate (hub .vendorID , 0 )
180+ infos , err := usbEnumerate (hub .vendorID , 0 )
172181 if err != nil {
173182 failcount := hub .enumFails .Add (1 )
174183 if runtime .GOOS == "linux" {
@@ -288,3 +297,6 @@ func (hub *Hub) updater() {
288297 hub .stateLock .Unlock ()
289298 }
290299}
300+
301+ // usbEnumerate is an alias for hid.Enumerate, allowing for easier mocking/testing.
302+ var usbEnumerate = hid .Enumerate
0 commit comments