Skip to content

Commit

Permalink
high-level-api: prefer WebHID on Windows
Browse files Browse the repository at this point in the history
HID has better compatibility on Windows due to driver issues for WebUSB
for the Nano X (see LedgerHQ/ledgerjs#456 and
WICG/webusb#143).
  • Loading branch information
danimoh committed Jun 23, 2020
1 parent 4d3efed commit 168debe
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/high-level-api/transport-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,28 @@ export function isSupported(transportType?: TransportType): boolean {

export function autoDetectTransportTypeToUse(): TransportType | null {
// Determine the best available transport type. Exclude WebBle as it's only suitable for Nano X.
return [
// TODO according to Ledger, HID has better compatibility on windows due to driver issues for WebUSB. Need to
// test and investigate that claim. On Linux however, WebUSB is preferable for multiple reasons (Chrome):
// - Currently HID permission is only valid until device is disconnected while WebUSB remembers a granted
// permission. This results in a device selection popup every time the Ledger is reconnected (or changes to
// another app or the dashboard, where Ledger reports different device descriptors, i.e. appears as a
// different device). This also requires a user gesture every time.
// - HID device selection popup does not update on changes, for example on switch from Ledger dashboard to app
// or when Ledger gets connected.
// - HID does not emit disconnects immediately but only at next request.
TransportType.WEB_USB, // WebUSB preferred over WebHID because of reasons stated above
TransportType.WEB_HID, // WebHID preferred over U2F because U2F can time out and causes popups in Windows
TransportType.U2F, // U2F as legacy fallback
].find(isSupported) || null;
let transportTypesByPreference;
// HID has better compatibility on Windows due to driver issues for WebUSB for the Nano X (see
// https://github.com/LedgerHQ/ledgerjs/issues/456 and https://github.com/WICG/webusb/issues/143). On other
// platforms however, WebUSB is preferable for multiple reasons (Chrome):
// - Currently HID permission is only valid until device is disconnected while WebUSB remembers a granted
// permission. This results in a device selection popup every time the Ledger is reconnected (or changes to
// another app or the dashboard, where Ledger reports different device descriptors, i.e. appears as a
// different device). This also requires a user gesture every time.
// - HID device selection popup does not update on changes, for example on switch from Ledger dashboard to app
// or when Ledger gets connected.
// - HID does not emit disconnects immediately but only at next request.
// TODO this situation needs to be re-evaluated once WebHID is stable
const isWindows = /Win/.test(window.navigator.platform); // see https://stackoverflow.com/a/38241481
if (isWindows) {
transportTypesByPreference = [TransportType.WEB_HID, TransportType.WEB_USB];
} else {
transportTypesByPreference = [TransportType.WEB_USB, TransportType.WEB_HID];
}
// U2F as legacy fallback. The others are preferred as U2F can time out and causes native Windows security popups
// in Windows and additionally Firefox internal popups in Firefox on all platforms.
transportTypesByPreference.push(TransportType.U2F);
return transportTypesByPreference.find(isSupported) || null;
}

/**
Expand Down

0 comments on commit 168debe

Please sign in to comment.