Merge remote-tracking branch 'origin/main' into zaps

This commit is contained in:
Alex Gleason
2024-01-22 12:00:55 -06:00
9 changed files with 104 additions and 98 deletions

View File

@@ -4,7 +4,7 @@ import { lodash, nip19, type UnsignedEvent } from '@/deps.ts';
import { jsonMetaContentSchema } from '@/schemas/nostr.ts';
import { type DittoEvent } from '@/storages/types.ts';
import { getLnurl } from '@/utils/lnurl.ts';
import { verifyNip05Cached } from '@/utils/nip05.ts';
import { nip05Cache } from '@/utils/nip05.ts';
import { Nip05, nostrDate, nostrNow, parseNip05 } from '@/utils.ts';
import { renderEmojis } from '@/views/mastodon/emojis.ts';
@@ -92,9 +92,19 @@ function accountFromPubkey(pubkey: string, opts: ToAccountOpts = {}) {
return renderAccount(event, opts);
}
async function parseAndVerifyNip05(nip05: string | undefined, pubkey: string): Promise<Nip05 | undefined> {
if (nip05 && await verifyNip05Cached(nip05, pubkey)) {
return parseNip05(nip05);
async function parseAndVerifyNip05(
nip05: string | undefined,
pubkey: string,
signal = AbortSignal.timeout(3000),
): Promise<Nip05 | undefined> {
if (!nip05) return;
try {
const result = await nip05Cache.fetch(nip05, { signal });
if (result.pubkey === pubkey) {
return parseNip05(nip05);
}
} catch (_e) {
// do nothing
}
}