diff --git a/src/controllers/well-known/nostr.ts b/src/controllers/well-known/nostr.ts index 0669888..b6b7af0 100644 --- a/src/controllers/well-known/nostr.ts +++ b/src/controllers/well-known/nostr.ts @@ -10,9 +10,12 @@ const nameSchema = z.string().min(1).regex(/^\w+$/); * https://github.com/nostr-protocol/nips/blob/master/05.md */ const nostrController: AppController = async (c) => { + const store = c.get('store'); + const result = nameSchema.safeParse(c.req.query('name')); const name = result.success ? result.data : undefined; - const pointer = name ? await localNip05Lookup(c.get('store'), name) : undefined; + + const pointer = name ? await localNip05Lookup(store, name) : undefined; if (!name || !pointer) { return c.json({ names: {}, relays: {} }); diff --git a/src/utils/nip05.ts b/src/utils/nip05.ts index 840ef6d..a579da6 100644 --- a/src/utils/nip05.ts +++ b/src/utils/nip05.ts @@ -45,16 +45,15 @@ const nip05Cache = new SimpleLRU( { max: 500, ttl: Time.hours(1) }, ); -async function localNip05Lookup(store: NStore, name: string): Promise { - const [label] = await store.query([{ - kinds: [1985], +async function localNip05Lookup(store: NStore, localpart: string): Promise { + const [grant] = await store.query([{ + kinds: [30360], + '#d': [`${localpart}@${Conf.url.host}`], authors: [Conf.pubkey], - '#L': ['nip05'], - '#l': [`${name}@${Conf.url.host}`], limit: 1, }]); - const pubkey = label?.tags.find(([name]) => name === 'p')?.[1]; + const pubkey = grant?.tags.find(([name]) => name === 'p')?.[1]; if (pubkey) { return { pubkey, relays: [Conf.relay] };