nostr.json: determine nip05 grant based on kind 30360 events

This commit is contained in:
Alex Gleason 2024-06-06 14:19:53 -05:00
parent 616c405f0f
commit ab2e9d8dd7
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 9 additions and 7 deletions

View File

@ -10,9 +10,12 @@ const nameSchema = z.string().min(1).regex(/^\w+$/);
* https://github.com/nostr-protocol/nips/blob/master/05.md * https://github.com/nostr-protocol/nips/blob/master/05.md
*/ */
const nostrController: AppController = async (c) => { const nostrController: AppController = async (c) => {
const store = c.get('store');
const result = nameSchema.safeParse(c.req.query('name')); const result = nameSchema.safeParse(c.req.query('name'));
const name = result.success ? result.data : undefined; 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) { if (!name || !pointer) {
return c.json({ names: {}, relays: {} }); return c.json({ names: {}, relays: {} });

View File

@ -45,16 +45,15 @@ const nip05Cache = new SimpleLRU<string, nip19.ProfilePointer>(
{ max: 500, ttl: Time.hours(1) }, { max: 500, ttl: Time.hours(1) },
); );
async function localNip05Lookup(store: NStore, name: string): Promise<nip19.ProfilePointer | undefined> { async function localNip05Lookup(store: NStore, localpart: string): Promise<nip19.ProfilePointer | undefined> {
const [label] = await store.query([{ const [grant] = await store.query([{
kinds: [1985], kinds: [30360],
'#d': [`${localpart}@${Conf.url.host}`],
authors: [Conf.pubkey], authors: [Conf.pubkey],
'#L': ['nip05'],
'#l': [`${name}@${Conf.url.host}`],
limit: 1, limit: 1,
}]); }]);
const pubkey = label?.tags.find(([name]) => name === 'p')?.[1]; const pubkey = grant?.tags.find(([name]) => name === 'p')?.[1];
if (pubkey) { if (pubkey) {
return { pubkey, relays: [Conf.relay] }; return { pubkey, relays: [Conf.relay] };