NIP05: skip network request for invalid TLDs

This commit is contained in:
Alex Gleason 2024-05-22 12:52:59 -05:00
parent 1d37106b27
commit 823f389bce
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 8 additions and 0 deletions

View File

@ -1,6 +1,7 @@
import { NIP05, NStore } from '@nostrify/nostrify'; import { NIP05, NStore } from '@nostrify/nostrify';
import Debug from '@soapbox/stickynotes/debug'; import Debug from '@soapbox/stickynotes/debug';
import { nip19 } from 'nostr-tools'; import { nip19 } from 'nostr-tools';
import tldts from 'tldts';
import { Conf } from '@/config.ts'; import { Conf } from '@/config.ts';
import { SimpleLRU } from '@/utils/SimpleLRU.ts'; import { SimpleLRU } from '@/utils/SimpleLRU.ts';
@ -13,7 +14,14 @@ const debug = Debug('ditto:nip05');
const nip05Cache = new SimpleLRU<string, nip19.ProfilePointer>( const nip05Cache = new SimpleLRU<string, nip19.ProfilePointer>(
async (key, { signal }) => { async (key, { signal }) => {
debug(`Lookup ${key}`); debug(`Lookup ${key}`);
const tld = tldts.parse(key);
if (!tld.isIcann || tld.isIp || tld.isPrivate) {
throw new Error(`Invalid NIP-05: ${key}`);
}
const [name, domain] = key.split('@'); const [name, domain] = key.split('@');
try { try {
if (domain === Conf.url.host) { if (domain === Conf.url.host) {
const store = await Storages.db(); const store = await Storages.db();