From a2069d6ad1423b1788428b93b6bbb4531c551572 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 2 Sep 2026 19:03:19 -0700 Subject: nevent and nprofile references come alive: nprofile mentions render as clickable @names beside their npub siblings, and note/nevent references become 'view note' links that fetch the event by id (relay hints first) and open its thread right in the app — the dim truncated stubs survive only for what genuinely can't resolve MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01MrkLsNScXe9b6BviUSdmMr --- src/nostr.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/nostr.js') diff --git a/src/nostr.js b/src/nostr.js index 753d4a8..a76ef5c 100644 --- a/src/nostr.js +++ b/src/nostr.js @@ -120,6 +120,18 @@ export function parseNostrPubkey(input) { } // An npub or 64-hex nostr pubkey → hex, or null if it isn't one. export function npubOf(pkHex) { try { return npubEncode(pkHex); } catch { return null; } } +// Any nostr entity reference → something renderable: npub/nprofile land as a +// pubkey (with relay hints when carried), note/nevent as an event id. +export function parseNostrRef(input) { + try { + const d = nip19decode(String(input || '').trim()); + if (d.type === 'npub') return { type: 'pubkey', pk: d.data }; + if (d.type === 'nprofile') return { type: 'pubkey', pk: d.data.pubkey, relays: d.data.relays || [] }; + if (d.type === 'note') return { type: 'event', id: d.data, relays: [] }; + if (d.type === 'nevent') return { type: 'event', id: d.data.id, relays: d.data.relays || [], author: d.data.author || null }; + } catch {} + return null; +} // A raw secret key → nsec, for the one place that deliberately exports it. export function nsecOf(sk) { try { return nsecEncode(sk); } catch { return null; } } -- cgit v1.2.3