Improve shared worker nsigner routing with explicit active signing port registration

This commit is contained in:
Laan Tungir
2026-05-27 15:17:45 -04:00
parent bd713d01f9
commit bc8e2f46fd
3 changed files with 25 additions and 4 deletions

View File

@@ -335,6 +335,7 @@ async function ensureAuthenticated() {
window.addEventListener('nlAuth', authHandler);
window.addEventListener('nlAuthRestored', authHandler);
window.addEventListener('nlMethodSelected', authHandler);
window.addEventListener('nlAuthStateChanged', authHandler);
});
}
@@ -484,6 +485,18 @@ function isExpectedSignerCapabilityError(method, error) {
/**
* Handle sign request from worker
*/
function tryRegisterActiveSigningPort() {
if (!ndkWorker?.port) return;
try {
const auth = window?.NOSTR_LOGIN_LITE?.getAuthState?.() || window?.nostr?.authState || null;
if (auth?.method === 'nsigner' && auth?.signer?.driver) {
ndkWorker.port.postMessage({ type: 'setActiveSigningPort' });
}
} catch (_) {
// ignore
}
}
async function handleSignRequest(requestId, method, params) {
try {
let result;
@@ -526,6 +539,9 @@ async function handleSignRequest(requestId, method, params) {
requestId: requestId,
result: result
});
// If this tab successfully signs using hardware signer, pin worker routing to this tab.
tryRegisterActiveSigningPort();
} catch (error) {
if (isExpectedSignerCapabilityError(method, error)) {

View File

@@ -1,5 +1,5 @@
{
"VERSION": "v0.7.11",
"VERSION_NUMBER": "0.7.11",
"BUILD_DATE": "2026-05-03T11:00:46.559Z"
"VERSION": "v0.7.12",
"VERSION_NUMBER": "0.7.12",
"BUILD_DATE": "2026-05-27T19:17:45.501Z"
}

View File

@@ -6106,7 +6106,6 @@ self.onconnect = (event) => {
activeSigningPort = port;
port.onmessage = async (e) => {
activeSigningPort = port;
const {
type,
pubkey,
@@ -6180,6 +6179,12 @@ self.onconnect = (event) => {
case 'ndkFetchEvents':
await handleNdkFetchEvents(requestId, filters, port);
break;
case 'setActiveSigningPort':
activeSigningPort = port;
console.log('[Worker] Active signing port set explicitly by page');
port.postMessage({ type: 'activeSigningPortSet' });
break;
case 'signResponse':
handleSignResponse(requestId, result, error);