Remove USB/serial device filters and relax reconnect matching

This commit is contained in:
Laan Tungir
2026-06-09 15:23:28 -04:00
parent 43c8d0d3a3
commit c4ecc8aca2
7 changed files with 53 additions and 57 deletions
+24 -25
View File
@@ -8,7 +8,7 @@
* Two-file architecture:
* 1. Load nostr.bundle.js (official nostr-tools bundle)
* 2. Load nostr-lite.js (this file - NOSTR_LOGIN_LITE library with CSS-only themes)
* Generated on: 2026-05-28T13:23:09.549Z
* Generated on: 2026-06-09T19:20:04.771Z
*/
// Verify dependencies are loaded
@@ -1663,7 +1663,7 @@ class Modal {
try {
// Incremental step 1:
// chooser + capture + driver open only (no getPublicKey/auth yet).
const selectedDevice = await navigator.usb.requestDevice({ filters: [{ vendorId: 0x303a }] });
const selectedDevice = await navigator.usb.requestDevice({ filters: [{}] });
this._nsignerSelectedDevice = selectedDevice;
if (!window.NSignerWebUSB || typeof window.NSignerWebUSB !== 'function') {
@@ -2008,10 +2008,7 @@ class Modal {
if (!driver && canUsb) {
try {
const pairedUsb = await window.NSignerWebUSB.getPairedDevice({
vendorId: 0x303a,
productId: 0x4001
});
const pairedUsb = await window.NSignerWebUSB.getPairedDevice();
if (pairedUsb) {
renderConnectingScreen('Reconnecting to paired WebUSB device...');
transport = 'webusb';
@@ -2055,7 +2052,7 @@ class Modal {
} else if (target === 'webusb') {
renderConnectingScreen('Waiting for WebUSB device selection...');
try {
const selectedDevice = await navigator.usb.requestDevice({ filters: [{ vendorId: 0x303a }] });
const selectedDevice = await navigator.usb.requestDevice({ filters: [{}] });
transport = 'webusb';
driver = await connectUsbFromDevice(selectedDevice);
} catch (usbErr) {
@@ -2300,7 +2297,7 @@ class Modal {
throw new Error('NSignerWebUSB driver missing');
}
const selectedDevice = await navigator.usb.requestDevice({ filters: [{ vendorId: 0x303a }] });
const selectedDevice = await navigator.usb.requestDevice({ filters: [{}] });
const driver = new window.NSignerWebUSB(selectedDevice, {
callerSecretKey: caller.secret,
@@ -3364,9 +3361,9 @@ window.addEventListener('load', () => {
// ======================================
class NSignerWebUSB {
// Keep picker broad (vendor-level) so Chromium can show all matching Feather states.
// Product-level checks still happen during open()/RPC.
static FILTERS = [{ vendorId: 0x303a }];
// Keep WebUSB chooser unfiltered so users can select any USB device.
// WebUSB requires a non-empty filters array; {} matches all devices.
static FILTERS = [{}];
static async requestAndConnect(options = {}) {
if (!('usb' in navigator)) {
@@ -3385,13 +3382,14 @@ class NSignerWebUSB {
const devices = await navigator.usb.getDevices();
if (!devices || devices.length === 0) return null;
const vendorId = options.vendorId ?? 0x303a;
const vendorId = options.vendorId ?? null;
const productId = options.productId ?? null;
const serial = options.serialNumber || null;
return devices.find((d) => {
const vendorMatch = d.vendorId === vendorId;
if (!vendorMatch) return false;
if (vendorId !== null && vendorId !== undefined && d.vendorId !== vendorId) {
return false;
}
if (productId !== null && productId !== undefined && d.productId !== productId) {
return false;
@@ -3727,19 +3725,17 @@ if (typeof window !== 'undefined') {
// ======================================
class NSignerWebSerial {
// CH340 VID:PID 0x1a86:0x7523 (most CYD revisions)
// CP2102 VID:PID 0x10c4:0xea60 (some CYD revisions)
static FILTERS = [
{ usbVendorId: 0x1a86, usbProductId: 0x7523 },
{ usbVendorId: 0x10c4, usbProductId: 0xea60 }
];
// Keep Web Serial chooser unfiltered so users can select any serial port.
static FILTERS = [];
static async requestAndConnect(options = {}) {
if (!('serial' in navigator)) {
throw new Error('Web Serial API not available in this browser (requires Chrome 89+, Edge 89+, or Brave)');
}
const port = await navigator.serial.requestPort({ filters: NSignerWebSerial.FILTERS });
const port = NSignerWebSerial.FILTERS.length
? await navigator.serial.requestPort({ filters: NSignerWebSerial.FILTERS })
: await navigator.serial.requestPort();
const driver = new NSignerWebSerial(port, options);
await driver.open();
return driver;
@@ -4170,12 +4166,15 @@ class NSignerWebSerial {
const vid = matchInfo?.usbVendorId;
const pid = matchInfo?.usbProductId;
return ports.find((p) => {
// Prefer exact VID/PID match when available, but do not require it.
const exact = ports.find((p) => {
const i = p.getInfo?.() || {};
if (vid != null && i.usbVendorId !== vid) return false;
if (pid != null && i.usbProductId !== pid) return false;
return true;
}) || ports[0] || null;
});
return exact || ports[0] || null;
} catch (_) {
return null;
}
@@ -5958,8 +5957,8 @@ class AuthManager {
}
const paired = await window.NSignerWebUSB.getPairedDevice({
vendorId: nsigner.deviceVid ?? 0x303a,
productId: nsigner.deviceProductId ?? 0x4001,
vendorId: nsigner.deviceVid ?? null,
productId: nsigner.deviceProductId ?? null,
serialNumber: nsigner.deviceSerial || undefined
});
+5 -7
View File
@@ -249,12 +249,8 @@
const nip44DecOutEl = document.getElementById("nip44DecOut");
// ── State ─────────────────────────────────────────────────────────────────
// CH340 VID:PID 0x1a86:0x7523 (most CYD revisions)
// CP2102 VID:PID 0x10c4:0xea60 (some CYD revisions)
const SERIAL_FILTERS = [
{ usbVendorId: 0x1a86, usbProductId: 0x7523 },
{ usbVendorId: 0x10c4, usbProductId: 0xea60 }
];
// Keep chooser unfiltered so any serial-capable device can be selected.
const SERIAL_FILTERS = [];
let port = null; // SerialPort
let writer = null; // WritableStreamDefaultWriter
@@ -507,7 +503,9 @@
throw new Error("Web Serial API not available — use Chrome 89+, Edge 89+, or Brave");
}
const initiallySelected = await navigator.serial.requestPort({ filters: SERIAL_FILTERS });
const initiallySelected = SERIAL_FILTERS.length
? await navigator.serial.requestPort({ filters: SERIAL_FILTERS })
: await navigator.serial.requestPort();
const selectedInfo = initiallySelected.getInfo?.() || {};
let lastError = null;
+1 -1
View File
@@ -383,7 +383,7 @@
}
async function connect() {
dev = await navigator.usb.requestDevice({ filters: [{ vendorId: 0x303a }] });
dev = await navigator.usb.requestDevice({ filters: [{}] });
await dev.open();
if (dev.configuration === null) {
await dev.selectConfiguration(1);
+2 -2
View File
@@ -2005,8 +2005,8 @@ class AuthManager {
}
const paired = await window.NSignerWebUSB.getPairedDevice({
vendorId: nsigner.deviceVid ?? 0x303a,
productId: nsigner.deviceProductId ?? 0x4001,
vendorId: nsigner.deviceVid ?? null,
productId: nsigner.deviceProductId ?? null,
serialNumber: nsigner.deviceSerial || undefined
});
+10 -9
View File
@@ -1,17 +1,15 @@
class NSignerWebSerial {
// CH340 VID:PID 0x1a86:0x7523 (most CYD revisions)
// CP2102 VID:PID 0x10c4:0xea60 (some CYD revisions)
static FILTERS = [
{ usbVendorId: 0x1a86, usbProductId: 0x7523 },
{ usbVendorId: 0x10c4, usbProductId: 0xea60 }
];
// Keep Web Serial chooser unfiltered so users can select any serial port.
static FILTERS = [];
static async requestAndConnect(options = {}) {
if (!('serial' in navigator)) {
throw new Error('Web Serial API not available in this browser (requires Chrome 89+, Edge 89+, or Brave)');
}
const port = await navigator.serial.requestPort({ filters: NSignerWebSerial.FILTERS });
const port = NSignerWebSerial.FILTERS.length
? await navigator.serial.requestPort({ filters: NSignerWebSerial.FILTERS })
: await navigator.serial.requestPort();
const driver = new NSignerWebSerial(port, options);
await driver.open();
return driver;
@@ -442,12 +440,15 @@ class NSignerWebSerial {
const vid = matchInfo?.usbVendorId;
const pid = matchInfo?.usbProductId;
return ports.find((p) => {
// Prefer exact VID/PID match when available, but do not require it.
const exact = ports.find((p) => {
const i = p.getInfo?.() || {};
if (vid != null && i.usbVendorId !== vid) return false;
if (pid != null && i.usbProductId !== pid) return false;
return true;
}) || ports[0] || null;
});
return exact || ports[0] || null;
} catch (_) {
return null;
}
+7 -6
View File
@@ -1,7 +1,7 @@
class NSignerWebUSB {
// Keep picker broad (vendor-level) so Chromium can show all matching Feather states.
// Product-level checks still happen during open()/RPC.
static FILTERS = [{ vendorId: 0x303a }];
// Keep WebUSB chooser unfiltered so users can select any USB device.
// WebUSB requires a non-empty filters array; {} matches all devices.
static FILTERS = [{}];
static async requestAndConnect(options = {}) {
if (!('usb' in navigator)) {
@@ -20,13 +20,14 @@ class NSignerWebUSB {
const devices = await navigator.usb.getDevices();
if (!devices || devices.length === 0) return null;
const vendorId = options.vendorId ?? 0x303a;
const vendorId = options.vendorId ?? null;
const productId = options.productId ?? null;
const serial = options.serialNumber || null;
return devices.find((d) => {
const vendorMatch = d.vendorId === vendorId;
if (!vendorMatch) return false;
if (vendorId !== null && vendorId !== undefined && d.vendorId !== vendorId) {
return false;
}
if (productId !== null && productId !== undefined && d.productId !== productId) {
return false;
+4 -7
View File
@@ -1351,7 +1351,7 @@ class Modal {
try {
// Incremental step 1:
// chooser + capture + driver open only (no getPublicKey/auth yet).
const selectedDevice = await navigator.usb.requestDevice({ filters: [{ vendorId: 0x303a }] });
const selectedDevice = await navigator.usb.requestDevice({ filters: [{}] });
this._nsignerSelectedDevice = selectedDevice;
if (!window.NSignerWebUSB || typeof window.NSignerWebUSB !== 'function') {
@@ -1696,10 +1696,7 @@ class Modal {
if (!driver && canUsb) {
try {
const pairedUsb = await window.NSignerWebUSB.getPairedDevice({
vendorId: 0x303a,
productId: 0x4001
});
const pairedUsb = await window.NSignerWebUSB.getPairedDevice();
if (pairedUsb) {
renderConnectingScreen('Reconnecting to paired WebUSB device...');
transport = 'webusb';
@@ -1743,7 +1740,7 @@ class Modal {
} else if (target === 'webusb') {
renderConnectingScreen('Waiting for WebUSB device selection...');
try {
const selectedDevice = await navigator.usb.requestDevice({ filters: [{ vendorId: 0x303a }] });
const selectedDevice = await navigator.usb.requestDevice({ filters: [{}] });
transport = 'webusb';
driver = await connectUsbFromDevice(selectedDevice);
} catch (usbErr) {
@@ -1988,7 +1985,7 @@ class Modal {
throw new Error('NSignerWebUSB driver missing');
}
const selectedDevice = await navigator.usb.requestDevice({ filters: [{ vendorId: 0x303a }] });
const selectedDevice = await navigator.usb.requestDevice({ filters: [{}] });
const driver = new window.NSignerWebUSB(selectedDevice, {
callerSecretKey: caller.secret,