feat(wallets): add WebUSB diagnostics module#437
feat(wallets): add WebUSB diagnostics module#437bensig wants to merge 1 commit intocaravan-bitcoin:mainfrom
Conversation
Add new webusb-diagnostics module with functions to help users troubleshoot Ledger connection issues: - detectBrowser() - Identifies browser and WebUSB/WebHID support - isWebUSBAvailable() - Checks if WebUSB API is available - isSecureContext() - Checks if page is served over HTTPS - getConnectedLedgerDevices() - Lists connected Ledger devices - runWebUSBDiagnostics() - Comprehensive diagnostics - getDiagnosticReport() - Human-readable diagnostic report Includes 20 tests covering browser detection, WebUSB availability, secure context checks, and diagnostic report generation.
🦋 Changeset detectedLatest commit: 129a066 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| /** | ||
| * Ledger USB vendor ID | ||
| */ | ||
| const LEDGER_VENDOR_ID = 0x2c97; |
There was a problem hiding this comment.
Should we move this into ledger.ts?
There was a problem hiding this comment.
presumably this could be used for other vendors too
| * Checks if the page is running in a secure context (required for WebUSB). | ||
| */ | ||
| export function isSecureContext(): boolean { | ||
| return typeof window !== "undefined" && window.isSecureContext === true; |
There was a problem hiding this comment.
Does this not work?
| return typeof window !== "undefined" && window.isSecureContext === true; | |
| return typeof window !== "undefined" && window.isSecureContext ; |
| export async function getConnectedLedgerDevices(): Promise<LedgerDeviceInfo[]> { | ||
| if (!isWebUSBAvailable()) { | ||
| return []; | ||
| } | ||
|
|
||
| try { | ||
| const devices = await (navigator as any).usb.getDevices(); | ||
| return devices | ||
| .filter((d: any) => d.vendorId === LEDGER_VENDOR_ID) |
There was a problem hiding this comment.
what about
| export async function getConnectedLedgerDevices(): Promise<LedgerDeviceInfo[]> { | |
| if (!isWebUSBAvailable()) { | |
| return []; | |
| } | |
| try { | |
| const devices = await (navigator as any).usb.getDevices(); | |
| return devices | |
| .filter((d: any) => d.vendorId === LEDGER_VENDOR_ID) | |
| export async function getCOnnectedDevices(vendorId): Promise<LedgerDeviceInfo[]> { | |
| if (!isWebUSBAvailable()) { | |
| return []; | |
| } | |
| try { | |
| const devices = await (navigator as any).usb.getDevices(); | |
| return devices | |
| .filter((d: any) => d.vendorId === vendorId) |
| let permissionGranted = false; | ||
|
|
||
| if (webUSBAvailable) { | ||
| devicesFound = await getConnectedLedgerDevices(); |
There was a problem hiding this comment.
and then we can either make this even more generic or run through a list of vendorIds (which is just one right now).
| /** | ||
| * Returns a human-readable diagnostic report as a string. | ||
| */ | ||
| export async function getDiagnosticReport(): Promise<string> { |
|
This pull request has been inactive for 30 days and has been marked as stale. It will be closed in 7 days if no further activity occurs. To keep this PR open, add the "long-lived" label or comment on it. |
|
@bensig curious if this was something you were interested in maintaining? I think this would be a great addition to the package if you're interested! |
Summary
Add a new
webusb-diagnosticsmodule to help users troubleshoot Ledger connection issues.This was inspired by real-world debugging where connection failures gave cryptic errors. The module provides functions to diagnose common issues like:
New exports
detectBrowser()isWebUSBAvailable()isSecureContext()getConnectedLedgerDevices()runWebUSBDiagnostics()getDiagnosticReport()Example usage
Test plan