Compare commits

..

3 Commits

3 changed files with 28 additions and 6 deletions

View File

@@ -184,7 +184,7 @@ export async function initNDKPage(options = {}) {
// All pages in www/ directory, so worker path is always the same.
// Include explicit worker revision token so updated SharedWorker code is guaranteed to restart.
const WORKER_REVISION = 'relay-events-db-5';
const WORKER_REVISION = 'relay-events-db-6';
const workerPath = `./ndk-worker.js?v=${encodeURIComponent(VERSION)}&wr=${encodeURIComponent(WORKER_REVISION)}`;
// Initialize NDK SharedWorker (shared across all tabs/pages)
@@ -217,6 +217,7 @@ export async function initNDKPage(options = {}) {
const readyHandler = () => {
cleanup();
console.log('[init-ndk] Worker signaled ready, initialization complete');
tryRegisterActiveSigningPort();
resolve();
};
@@ -319,6 +320,7 @@ async function ensureAuthenticated() {
try {
const pubkey = await getPublicKeyWithTimeout(4000);
console.log('[init-ndk] Authentication successful, pubkey:', pubkey);
tryRegisterActiveSigningPort();
finish(true);
} catch (error) {
console.log('[init-ndk] window.nostr not ready yet:', error.message);
@@ -335,6 +337,7 @@ async function ensureAuthenticated() {
window.addEventListener('nlAuth', authHandler);
window.addEventListener('nlAuthRestored', authHandler);
window.addEventListener('nlMethodSelected', authHandler);
window.addEventListener('nlAuthStateChanged', authHandler);
});
}
@@ -484,6 +487,18 @@ function isExpectedSignerCapabilityError(method, error) {
/**
* Handle sign request from worker
*/
function tryRegisterActiveSigningPort() {
if (!ndkWorker?.port) return;
try {
const auth = window?.nostr?.authState || window?.NOSTR_LOGIN_LITE?.getAuthState?.() || 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 +541,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.14",
"VERSION_NUMBER": "0.7.14",
"BUILD_DATE": "2026-05-27T19:48:34.590Z"
}

View File

@@ -6103,10 +6103,8 @@ self.onconnect = (event) => {
console.log('[Worker] New port connected');
connectedPorts.push(port);
activeSigningPort = port;
port.onmessage = async (e) => {
activeSigningPort = port;
const {
type,
pubkey,
@@ -6180,6 +6178,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);