NIP05: skip network request for invalid TLDs
This commit is contained in:
parent
1d37106b27
commit
823f389bce
|
@ -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();
|
||||||
|
|
Loading…
Reference in New Issue