From 027c61e00ff6a9c04475613a1cf54c5be541c5c2 Mon Sep 17 00:00:00 2001 From: OFF0 Date: Wed, 2 Aug 2023 12:55:11 +0200 Subject: [PATCH] feed: support nostr:npub uri scheme (part of nip-21) added support for nostr:npub links in textnotes content. --- src/utils/dom.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/utils/dom.ts b/src/utils/dom.ts index 686cb49..a39cc86 100644 --- a/src/utils/dom.ts +++ b/src/utils/dom.ts @@ -1,3 +1,4 @@ +import {nip19} from 'nostr-tools'; import {isNotNull} from './array'; import {isValidURL} from './url'; @@ -96,6 +97,13 @@ export const parseTextContent = ( href: `lightning:${word}` }, `lightning:${word.slice(0, 24)}…`); } + if (word.startsWith('nostr:npub') && word.length === 69) { + const npub = word.slice(6); + const {type, data} = nip19.decode(npub); + if (type === 'npub') { + return elem('a', {href: `/${npub}`, data: {profile: data}}, data.slice(6, 15)) + } + } if (!word.match(/^(https?:\/\/|www\.)\S*/)) { return word; }