From fe7304ac7fc70baf9ceec09047bd7cc1f288b938 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 23 Feb 2026 18:03:29 -0400 Subject: [PATCH] v1.2.25 - Add NIP-42 AUTH support to web UI: onauth callback in subscribeMany and publish calls --- api/index.js | 33 +++++++++++++++++++++++++++++++-- src/main.h | 4 ++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/api/index.js b/api/index.js index b4d8726..2016643 100644 --- a/api/index.js +++ b/api/index.js @@ -1338,6 +1338,23 @@ async function subscribeToConfiguration() { console.log('No configuration events were received'); } }, + async onauth(challenge) { + // NIP-42 authentication: relay sent AUTH challenge, sign and respond + console.log('🔐 NIP-42 AUTH challenge received:', challenge); + try { + if (!window.nostr) { + console.error('NIP-42 auth required but no nostr extension available'); + return; + } + const url = relayConnectionUrl.value.trim(); + const authEvent = window.NostrTools.nip42.makeAuthEvent(url, challenge); + const signedAuthEvent = await window.nostr.signEvent(authEvent); + console.log('✅ NIP-42 AUTH event signed, responding to challenge'); + return signedAuthEvent; + } catch (authError) { + console.error('NIP-42 AUTH failed:', authError.message); + } + }, onclose(reason) { console.log('Subscription closed:', reason); // Reset subscription state to allow re-subscription @@ -5467,9 +5484,21 @@ async function sendAdminCommand(commandArray) { throw new Error('Event signing failed'); } - // Publish via SimplePool with detailed error diagnostics + // Publish via SimplePool with NIP-42 auth support const url = relayConnectionUrl.value.trim(); - const publishPromises = relayPool.publish([url], signedEvent); + const publishPromises = relayPool.publish([url], signedEvent, { + async onauth(challenge) { + console.log('🔐 NIP-42 AUTH challenge during publish:', challenge); + try { + const authEvent = window.NostrTools.nip42.makeAuthEvent(url, challenge); + const signedAuthEvent = await window.nostr.signEvent(authEvent); + console.log('✅ NIP-42 AUTH signed for publish'); + return signedAuthEvent; + } catch (authError) { + console.error('NIP-42 AUTH failed during publish:', authError.message); + } + } + }); // Use Promise.allSettled to capture per-relay outcomes const results = await Promise.allSettled(publishPromises); diff --git a/src/main.h b/src/main.h index 712b5e4..a26e114 100644 --- a/src/main.h +++ b/src/main.h @@ -13,8 +13,8 @@ // Using CRELAY_ prefix to avoid conflicts with nostr_core_lib VERSION macros #define CRELAY_VERSION_MAJOR 1 #define CRELAY_VERSION_MINOR 2 -#define CRELAY_VERSION_PATCH 24 -#define CRELAY_VERSION "v1.2.24" +#define CRELAY_VERSION_PATCH 25 +#define CRELAY_VERSION "v1.2.25" // Relay metadata (authoritative source for NIP-11 information) #define RELAY_NAME "C-Relay"