From b0e190fd2255076ea9faea36a815f5d26a034f98 Mon Sep 17 00:00:00 2001 From: OFF0 Date: Fri, 24 Feb 2023 11:53:19 +0100 Subject: [PATCH] nip19: use bech32 npub and note in uris convert pubkey to npub and event id to note and store for later. use npub and note for uri's so that we dont need to guess what the view of a specific uri has to render. this is only the first step that changes uri's, next step is for the view to react to npub or note and render the correct view accordingly. --- src/main.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main.js b/src/main.js index 87c259d..ad6ca86 100644 --- a/src/main.js +++ b/src/main.js @@ -1,4 +1,4 @@ -import {generatePrivateKey, getEventHash, getPublicKey, signEvent} from 'nostr-tools'; +import {generatePrivateKey, getEventHash, getPublicKey, nip19, signEvent} from 'nostr-tools'; import {publish, sub, unsubAll} from './relays'; import {bounce} from './utils.js'; import {zeroLeadingBitsCount} from './cryptoutils.js'; @@ -137,10 +137,17 @@ function handleTextNote(evt, relay) { eventRelayMap[evt.id] = [relay, ...(eventRelayMap[evt.id])]; } else { eventRelayMap[evt.id] = [relay]; + const evtWithNip19 = { + nip19: { + note: nip19.noteEncode(evt.id), + npub: nip19.npubEncode(evt.pubkey), + }, + ...evt + }; if (evt.tags.some(hasEventTag)) { - handleReply(evt, relay); + handleReply(evtWithNip19, relay); } else { - textNoteList.push(evt); + textNoteList.push(evtWithNip19); } } if (!getViewElem(evt.id)) { @@ -324,9 +331,9 @@ function createTextNote(evt, relay) { ${evt.tags.length ? `\nTags ${JSON.stringify(evt.tags)}\n` : ''} ${evt.content}` }, [ - elem('a', {className: `mbox-username${name ? ' mbox-kind0-name' : ''}`, href: `/${evt.pubkey}`, data: {nav: '/[profile]'}}, name || userName), + elem('a', {className: `mbox-username${name ? ' mbox-kind0-name' : ''}`, href: `/${evt.nip19.npub}`, data: {nav: '/[profile]'}}, name || userName), ' ', - elem('a', {href: `/${evt.id}`, data: {nav: '/[note]'}}, formatTime(time)), + elem('a', {href: `/${evt.nip19.note}`, data: {nav: '/[note]'}}, formatTime(time)), ]), elem('div', {/* data: isLongContent ? {append: evt.content.slice(280)} : null*/}, [ ...content,