diff --git a/package-lock.json b/package-lock.json index abd2db3..c584127 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,7 +33,7 @@ "@tiptap/suggestion": "^3.15.3", "@types/qrcode": "^1.5.6", "applesauce-accounts": "^5.0.0", - "applesauce-actions": "^5.0.0", + "applesauce-actions": "^5.0.2", "applesauce-common": "^5.0.0", "applesauce-content": "^5.0.0", "applesauce-core": "^5.0.0", @@ -5563,9 +5563,9 @@ } }, "node_modules/applesauce-actions": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/applesauce-actions/-/applesauce-actions-5.0.0.tgz", - "integrity": "sha512-Lw9x3P3+p9udmA9BvAssJDasDr+eIXq22SBwS3D6kt+3TOnBmJqONR3ru6K3j5S5MflYsiiy66b4TcATrBOXgQ==", + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/applesauce-actions/-/applesauce-actions-5.0.2.tgz", + "integrity": "sha512-ctdx2m4H0biItXBCefJwhwla2XTOsaJvMm9RmGebfYoVKr/NQQ3UROHCZFtgmsrYz/OCYooC2EpNFlLj8fTYOA==", "license": "MIT", "dependencies": { "applesauce-common": "^5.0.0", diff --git a/package.json b/package.json index 494749e..a1b66a4 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "@tiptap/suggestion": "^3.15.3", "@types/qrcode": "^1.5.6", "applesauce-accounts": "^5.0.0", - "applesauce-actions": "^5.0.0", + "applesauce-actions": "^5.0.2", "applesauce-common": "^5.0.0", "applesauce-content": "^5.0.0", "applesauce-core": "^5.0.0", diff --git a/src/services/gift-wrap.ts b/src/services/gift-wrap.ts index cd543cc..3098c52 100644 --- a/src/services/gift-wrap.ts +++ b/src/services/gift-wrap.ts @@ -22,6 +22,7 @@ import { } from "./db"; import { AGGREGATOR_RELAYS } from "./loaders"; import relayListCache from "./relay-list-cache"; +import { normalizeRelayURL } from "@/lib/relay-url"; /** Kind 10050: DM relay list (NIP-17) */ const DM_RELAY_LIST_KIND = 10050; @@ -248,11 +249,23 @@ class GiftWrapService { filter((e) => e !== undefined), map((event) => { if (!event) return []; - // Extract relay URLs from tags + // Extract relay URLs from tags and normalize them return event.tags .filter((tag) => tag[0] === "relay") .map((tag) => tag[1]) - .filter(Boolean); + .filter(Boolean) + .map((url) => { + try { + return normalizeRelayURL(url); + } catch (err) { + console.warn( + `[GiftWrap] Failed to normalize inbox relay URL: ${url}`, + err, + ); + return null; + } + }) + .filter((url): url is string => url !== null); }), ) .subscribe((relays) => { diff --git a/src/services/hub.ts b/src/services/hub.ts index 351af02..6784953 100644 --- a/src/services/hub.ts +++ b/src/services/hub.ts @@ -7,6 +7,7 @@ import { getSeenRelays } from "applesauce-core/helpers/relays"; import type { NostrEvent } from "nostr-tools/core"; import accountManager from "./accounts"; import { encryptedContentStorage } from "./db"; +import { normalizeRelayURL } from "@/lib/relay-url"; /** * Publishes a Nostr event to relays @@ -18,11 +19,27 @@ export async function publishEvent( event: NostrEvent, relayHints?: string[], ): Promise { + console.log( + `[Publish] 🚀 publishEvent called for kind ${event.kind}, id ${event.id?.slice(0, 8) || "UNSIGNED"}, relayHints:`, + relayHints, + ); + let relays: string[]; // If relays explicitly provided (e.g., from gift wrap actions), use them if (relayHints && relayHints.length > 0) { - relays = relayHints; + // Normalize relay hints to ensure consistent URLs + relays = relayHints + .map((url) => { + try { + return normalizeRelayURL(url); + } catch (err) { + console.warn(`[Publish] Failed to normalize relay hint: ${url}`, err); + return null; + } + }) + .filter((url): url is string => url !== null); + console.log( `[Publish] Using provided relay hints (${relays.length} relays) for event ${event.id.slice(0, 8)}`, ); @@ -39,20 +56,40 @@ export async function publishEvent( // If still no relays, throw error if (relays.length === 0) { + console.error( + `[Publish] ❌ No relays found for event ${event.id.slice(0, 8)}`, + ); throw new Error( "No relays found for publishing. Please configure relay list (kind 10002) or ensure event has relay hints.", ); } + console.log( + `[Publish] 📤 Publishing to ${relays.length} relays:`, + relays.join(", "), + ); + // Publish to relay pool await pool.publish(relays, event); + console.log( + `[Publish] ✅ Successfully published event ${event.id.slice(0, 8)}`, + ); + // If this is a gift wrap with decrypted content symbol, persist it to Dexie // This ensures when we receive it back from relay, it's recognized as unlocked if (event.kind === 1059) { + console.log( + `[Publish] 🎁 Gift wrap detected (kind 1059), checking for encrypted content symbol...`, + ); const EncryptedContentSymbol = Symbol.for("encrypted-content"); - if (Reflect.has(event, EncryptedContentSymbol)) { + const hasSymbol = Reflect.has(event, EncryptedContentSymbol); + console.log(`[Publish] Has EncryptedContentSymbol: ${hasSymbol}`); + if (hasSymbol) { const plaintext = Reflect.get(event, EncryptedContentSymbol); + console.log( + `[Publish] Plaintext length: ${plaintext?.length || 0} chars`, + ); try { await encryptedContentStorage.setItem(event.id, plaintext); console.log( @@ -61,11 +98,19 @@ export async function publishEvent( } catch (err) { console.warn(`[Publish] ⚠️ Failed to persist encrypted content:`, err); } + } else { + console.warn( + `[Publish] ⚠️ Gift wrap ${event.id.slice(0, 8)} has no EncryptedContentSymbol!`, + ); } } // Add to EventStore for immediate local availability + console.log( + `[Publish] 📥 Adding event ${event.id.slice(0, 8)} to EventStore`, + ); eventStore.add(event); + console.log(`[Publish] ✅ Complete`); } const factory = new EventFactory();