nostr.json: determine nip05 grant based on kind 30360 events
This commit is contained in:
parent
616c405f0f
commit
ab2e9d8dd7
|
@ -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: {} });
|
||||
|
|
|
@ -45,16 +45,15 @@ const nip05Cache = new SimpleLRU<string, nip19.ProfilePointer>(
|
|||
{ max: 500, ttl: Time.hours(1) },
|
||||
);
|
||||
|
||||
async function localNip05Lookup(store: NStore, name: string): Promise<nip19.ProfilePointer | undefined> {
|
||||
const [label] = await store.query([{
|
||||
kinds: [1985],
|
||||
async function localNip05Lookup(store: NStore, localpart: string): Promise<nip19.ProfilePointer | undefined> {
|
||||
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] };
|
||||
|
|
Loading…
Reference in New Issue