From 2140b3fbb22ada324f5ef0e084141a1ae5ac3283 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 13 May 2024 11:21:17 -0500 Subject: [PATCH] lookupPubkey: check the bech32 first --- ..env.swp | Bin 0 -> 1024 bytes src/utils/lookup.ts | 14 ++++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 ..env.swp diff --git a/..env.swp b/..env.swp new file mode 100644 index 0000000000000000000000000000000000000000..2ab134254314be032359c6894717262e417e7684 GIT binary patch literal 1024 zcmYc?$V<%2S1{8vVn6|1lPwq$b5bi%1aWW*@(XnHi*ZOI3G1cil_7CQnWG^v8Uh0x F0sw&A3CREe literal 0 HcmV?d00001 diff --git a/src/utils/lookup.ts b/src/utils/lookup.ts index ce42e2f2..90b30c2b 100644 --- a/src/utils/lookup.ts +++ b/src/utils/lookup.ts @@ -1,8 +1,9 @@ -import { NIP05, NostrEvent } from '@nostrify/nostrify'; +import { NIP05, NostrEvent, NSchema as n } from '@nostrify/nostrify'; import { getAuthor } from '@/queries.ts'; import { bech32ToPubkey } from '@/utils.ts'; import { nip05Cache } from '@/utils/nip05.ts'; +import { Stickynotes } from '@soapbox/stickynotes'; /** Resolve a bech32 or NIP-05 identifier to an account. */ export async function lookupAccount( @@ -18,14 +19,19 @@ export async function lookupAccount( /** Resolve a bech32 or NIP-05 identifier to a pubkey. */ export async function lookupPubkey(value: string, signal?: AbortSignal): Promise { + const console = new Stickynotes('ditto:lookup'); + + if (n.bech32().safeParse(value).success) { + return bech32ToPubkey(value); + } + if (NIP05.regex().test(value)) { try { const { pubkey } = await nip05Cache.fetch(value, { signal }); return pubkey; - } catch { + } catch (e) { + console.debug(e); return; } } - - return bech32ToPubkey(value); }