Fix account search

This commit is contained in:
Alex Gleason 2024-08-08 18:41:29 -05:00
parent 800e20a143
commit c7a59b50d0
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 27 additions and 10 deletions

18
src/utils/lookup.test.ts Normal file
View file

@ -0,0 +1,18 @@
import { assertEquals } from '@std/assert';
import { extractIdentifier } from './lookup.ts';
Deno.test('extractIdentifier', () => {
assertEquals(
extractIdentifier('https://njump.me/npub1q3sle0kvfsehgsuexttt3ugjd8xdklxfwwkh559wxckmzddywnws6cd26p'),
'npub1q3sle0kvfsehgsuexttt3ugjd8xdklxfwwkh559wxckmzddywnws6cd26p',
);
assertEquals(
extractIdentifier('npub1q3sle0kvfsehgsuexttt3ugjd8xdklxfwwkh559wxckmzddywnws6cd26p'),
'npub1q3sle0kvfsehgsuexttt3ugjd8xdklxfwwkh559wxckmzddywnws6cd26p',
);
assertEquals(
extractIdentifier('alex'),
undefined,
);
});

View file

@ -1,6 +1,7 @@
import { NIP05, NostrEvent, NSchema as n } from '@nostrify/nostrify';
import { NostrEvent, NSchema as n } from '@nostrify/nostrify';
import { nip19 } from 'nostr-tools';
import { match } from 'path-to-regexp';
import tldts from 'tldts';
import { getAuthor } from '@/queries.ts';
import { bech32ToPubkey } from '@/utils.ts';
@ -27,14 +28,12 @@ export async function lookupPubkey(value: string, signal?: AbortSignal): Promise
return bech32ToPubkey(value);
}
if (NIP05.regex().test(value)) {
try {
const { pubkey } = await nip05Cache.fetch(value, { signal });
return pubkey;
} catch (e) {
console.debug(e);
return;
}
try {
const { pubkey } = await nip05Cache.fetch(value, { signal });
return pubkey;
} catch (e) {
console.debug(e);
return;
}
}
@ -84,7 +83,7 @@ export function extractIdentifier(value: string): string | undefined {
return value;
}
if (NIP05.regex().test(value)) {
if (tldts.parse(value).isIcann) {
return value;
}
}