diff --git a/packages/app/src/Element/Embed/Mention.tsx b/packages/app/src/Element/Embed/Mention.tsx index 0c599ba32..219a42212 100644 --- a/packages/app/src/Element/Embed/Mention.tsx +++ b/packages/app/src/Element/Embed/Mention.tsx @@ -14,7 +14,7 @@ export default function Mention({ link }: { link: NostrLink }) { return ( <> - e.stopPropagation()}> + e.stopPropagation()}> @ diff --git a/packages/app/src/Element/Embed/NostrLink.tsx b/packages/app/src/Element/Embed/NostrLink.tsx index 994a77487..becd6f9a1 100644 --- a/packages/app/src/Element/Embed/NostrLink.tsx +++ b/packages/app/src/Element/Embed/NostrLink.tsx @@ -8,6 +8,10 @@ export default function NostrLink({ link, depth }: { link: string; depth?: numbe const nav = tryParseNostrLink(link); if (nav?.type === NostrPrefix.PublicKey || nav?.type === NostrPrefix.Profile) { + if(nav.id.startsWith("npub")){ + // eslint-disable-next-line no-debugger + debugger; + } return ; } else if (nav?.type === NostrPrefix.Note || nav?.type === NostrPrefix.Event || nav?.type === NostrPrefix.Address) { if ((depth ?? 0) > 0) { diff --git a/packages/shared/src/utils.ts b/packages/shared/src/utils.ts index 6976140dd..aa075bc74 100644 --- a/packages/shared/src/utils.ts +++ b/packages/shared/src/utils.ts @@ -144,13 +144,9 @@ export function getPublicKey(privKey: string) { } export function bech32ToHex(str: string) { - try { - const nKey = bech32.decode(str, 1_000); - const buff = bech32.fromWords(nKey.words); - return utils.bytesToHex(Uint8Array.from(buff)); - } catch (e) { - return str; - } + const nKey = bech32.decode(str, 1_000); + const buff = bech32.fromWords(nKey.words); + return utils.bytesToHex(Uint8Array.from(buff)); } /** @@ -159,13 +155,9 @@ export function bech32ToHex(str: string) { * @returns */ export function bech32ToText(str: string) { - try { - const decoded = bech32.decode(str, 1000); - const buf = bech32.fromWords(decoded.words); - return new TextDecoder().decode(Uint8Array.from(buf)); - } catch { - return ""; - } + const decoded = bech32.decode(str, 1000); + const buf = bech32.fromWords(decoded.words); + return new TextDecoder().decode(Uint8Array.from(buf)); } export async function fetchNip05Pubkey(name: string, domain: string, timeout = 2_000): Promise { diff --git a/packages/system/src/nostr-link.ts b/packages/system/src/nostr-link.ts index ee47ad268..9c24bf8b9 100644 --- a/packages/system/src/nostr-link.ts +++ b/packages/system/src/nostr-link.ts @@ -233,11 +233,16 @@ export function tryParseNostrLink(link: string, prefixHint?: NostrPrefix): Nostr } } -export function parseNostrLink(link: string, prefixHint?: NostrPrefix): NostrLink { - let entity = link.startsWith("web+nostr:") || link.startsWith("nostr:") ? link.split(":")[1] : link; +export function trimNostrLink(link: string) { + let entity = (link.startsWith("web+nostr:") || link.startsWith("nostr:")) ? link.split(":")[1] : link; // trim any non-bech32 chars entity = entity.match(/(n(?:pub|profile|event|ote|addr|req)1[acdefghjklmnpqrstuvwxyz023456789]+)/)?.[0] ?? entity; + return entity; +} + +export function parseNostrLink(link: string, prefixHint?: NostrPrefix): NostrLink { + const entity = trimNostrLink(link); const isPrefix = (prefix: NostrPrefix) => { return entity.startsWith(prefix);