From 5ec40f285da3060e0ca8977f613a7a70babf674c Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 9 Jul 2023 18:16:20 -0500 Subject: [PATCH] Webfinger: actually, remove nostr lookup (this is bloat) --- src/controllers/well-known/webfinger.ts | 30 ++++++++----------------- src/schema.ts | 20 ----------------- 2 files changed, 9 insertions(+), 41 deletions(-) diff --git a/src/controllers/well-known/webfinger.ts b/src/controllers/well-known/webfinger.ts index 62a18def..b313299f 100644 --- a/src/controllers/well-known/webfinger.ts +++ b/src/controllers/well-known/webfinger.ts @@ -1,7 +1,6 @@ import { Conf } from '@/config.ts'; import { db } from '@/db.ts'; import { nip19, z } from '@/deps.ts'; -import { npubSchema } from '@/schema.ts'; import type { AppContext, AppController } from '@/app.ts'; import type { Webfinger } from '@/schemas/webfinger.ts'; @@ -22,9 +21,6 @@ const webfingerController: AppController = (c) => { case 'acct:': { return handleAcct(c, resource); } - case 'nostr:': { - return handleNostr(c, resource); - } default: return c.json({ error: 'Unsupported URI scheme' }, 400); } @@ -42,10 +38,17 @@ const acctSchema = z.custom((value) => value instanceof URL) async function handleAcct(c: AppContext, resource: URL): Promise { try { - const [username] = acctSchema.parse(resource); + const [username, host] = acctSchema.parse(resource); const user = await db.users.findFirst({ where: { username } }); + + const json = renderWebfinger({ + pubkey: user.pubkey, + username: user.username, + subject: `acct:${username}@${host}`, + }); + c.header('content-type', 'application/jrd+json'); - return c.body(JSON.stringify(renderWebfinger({ ...user, subject: `acct:${resource.pathname}` }))); + return c.body(JSON.stringify(json)); } catch (e) { if (e instanceof z.ZodError) { return c.json({ error: 'Invalid acct URI', schema: e }, 400); @@ -55,21 +58,6 @@ async function handleAcct(c: AppContext, resource: URL): Promise { } } -async function handleNostr(c: AppContext, resource: URL): Promise { - try { - const pubkey = npubSchema.parse(resource.pathname); - const user = await db.users.findFirst({ where: { pubkey } }); - c.header('content-type', 'application/jrd+json'); - return c.body(JSON.stringify(renderWebfinger({ ...user, subject: `nostr:${resource.pathname}` }))); - } catch (e) { - if (e instanceof z.ZodError) { - return c.json({ error: 'Invalid Nostr URI', schema: e }, 400); - } else { - return c.json({ error: 'Not found' }, 404); - } - } -} - interface RenderWebfingerOpts { pubkey: string; username: string; diff --git a/src/schema.ts b/src/schema.ts index bd44b349..63aaffb1 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -95,24 +95,6 @@ const decode64Schema = z.string().transform((value, ctx) => { } }); -const nip19Schema = z.string().transform((val, ctx) => { - try { - return nip19.decode(val); - } catch (_e) { - ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Invalid NIP-19 identifier', fatal: true }); - return z.NEVER; - } -}); - -const npubSchema = nip19Schema.transform((decoded, ctx) => { - if (decoded.type === 'npub') { - return decoded.data; - } else { - ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Unsupported NIP-19 identifier', fatal: true }); - return z.NEVER; - } -}); - export { decode64Schema, emojiTagSchema, @@ -120,8 +102,6 @@ export { jsonSchema, type MetaContent, metaContentSchema, - nip19Schema, - npubSchema, parseMetaContent, parseRelay, relaySchema,