diff --git a/src/app.ts b/src/app.ts index e7862ab..be2ce84 100644 --- a/src/app.ts +++ b/src/app.ts @@ -76,10 +76,8 @@ import { } from '@/controllers/api/timelines.ts'; import { trendingTagsController } from '@/controllers/api/trends.ts'; import { indexController } from '@/controllers/site.ts'; -import { hostMetaController } from '@/controllers/well-known/host-meta.ts'; import { nodeInfoController, nodeInfoSchemaController } from '@/controllers/well-known/nodeinfo.ts'; import { nostrController } from '@/controllers/well-known/nostr.ts'; -import { webfingerController } from '@/controllers/well-known/webfinger.ts'; import { auth98Middleware, requireProof, requireRole } from '@/middleware/auth98Middleware.ts'; import { cacheMiddleware } from '@/middleware/cacheMiddleware.ts'; import { cspMiddleware } from '@/middleware/cspMiddleware.ts'; @@ -136,8 +134,6 @@ app.use( storeMiddleware, ); -app.get('/.well-known/webfinger', webfingerController); -app.get('/.well-known/host-meta', hostMetaController); app.get('/.well-known/nodeinfo', nodeInfoController); app.get('/.well-known/nostr.json', nostrController); diff --git a/src/controllers/well-known/host-meta.ts b/src/controllers/well-known/host-meta.ts deleted file mode 100644 index 85da11b..0000000 --- a/src/controllers/well-known/host-meta.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { Conf } from '@/config.ts'; - -import type { AppController } from '@/app.ts'; - -/** https://datatracker.ietf.org/doc/html/rfc6415 */ -const hostMetaController: AppController = (c) => { - const template = Conf.local('/.well-known/webfinger?resource={uri}'); - - c.header('content-type', 'application/xrd+xml'); - - return c.body( - ` - - - -`, - ); -}; - -export { hostMetaController }; diff --git a/src/controllers/well-known/webfinger.ts b/src/controllers/well-known/webfinger.ts deleted file mode 100644 index c1c8b81..0000000 --- a/src/controllers/well-known/webfinger.ts +++ /dev/null @@ -1,97 +0,0 @@ -import { nip19 } from 'nostr-tools'; -import { z } from 'zod'; - -import { Conf } from '@/config.ts'; -import { localNip05Lookup } from '@/utils/nip05.ts'; - -import type { AppContext, AppController } from '@/app.ts'; -import type { Webfinger } from '@/schemas/webfinger.ts'; - -const webfingerQuerySchema = z.object({ - resource: z.string().url(), -}); - -const webfingerController: AppController = (c) => { - const query = webfingerQuerySchema.safeParse(c.req.query()); - if (!query.success) { - return c.json({ error: 'Bad request', schema: query.error }, 400); - } - - const resource = new URL(query.data.resource); - - switch (resource.protocol) { - case 'acct:': { - return handleAcct(c, resource); - } - default: - return c.json({ error: 'Unsupported URI scheme' }, 400); - } -}; - -/** Transforms the resource URI into a `[username, domain]` tuple. */ -const acctSchema = z.custom((value) => value instanceof URL) - .transform((uri) => uri.pathname) - .pipe(z.string().email('Invalid acct')) - .transform((acct) => acct.split('@') as [username: string, host: string]) - .refine(([_username, host]) => host === Conf.url.hostname, { - message: 'Host must be local', - path: ['resource', 'acct'], - }); - -async function handleAcct(c: AppContext, resource: URL): Promise { - const result = acctSchema.safeParse(resource); - if (!result.success) { - return c.json({ error: 'Invalid acct URI', schema: result.error }, 400); - } - - const [username, host] = result.data; - const pointer = await localNip05Lookup(c.get('store'), username); - - if (!pointer) { - return c.json({ error: 'Not found' }, 404); - } - - const json = renderWebfinger({ - pubkey: pointer.pubkey, - username, - subject: `acct:${username}@${host}`, - }); - - c.header('content-type', 'application/jrd+json'); - return c.body(JSON.stringify(json)); -} - -interface RenderWebfingerOpts { - pubkey: string; - username: string; - subject: string; -} - -/** Present Nostr user on Webfinger. */ -function renderWebfinger({ pubkey, username, subject }: RenderWebfingerOpts): Webfinger { - const apId = Conf.local(`/users/${username}`); - - return { - subject, - aliases: [apId], - links: [ - { - rel: 'self', - type: 'application/activity+json', - href: apId, - }, - { - rel: 'self', - type: 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', - href: apId, - }, - { - rel: 'self', - type: 'application/nostr+json', - href: `nostr:${nip19.npubEncode(pubkey)}`, - }, - ], - }; -} - -export { webfingerController }; diff --git a/src/schemas/webfinger.ts b/src/schemas/webfinger.ts deleted file mode 100644 index 8c9cf57..0000000 --- a/src/schemas/webfinger.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { z } from 'zod'; - -const linkSchema = z.object({ - rel: z.string().optional(), - type: z.string().optional(), - href: z.string().optional(), - template: z.string().optional(), -}); - -const webfingerSchema = z.object({ - subject: z.string(), - aliases: z.array(z.string()).catch([]), - links: z.array(linkSchema), -}); - -type Webfinger = z.infer; - -export { webfingerSchema }; -export type { Webfinger };