Remove webfinger and host-meta

This commit is contained in:
Alex Gleason 2024-05-21 12:54:10 -05:00
parent 8f393aa604
commit 938e26e2a0
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
4 changed files with 0 additions and 140 deletions

View File

@ -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);

View File

@ -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(
`<?xml version="1.0" encoding="UTF-8"?>
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
<Link rel="lrdd" template="${template}" type="application/xrd+xml" />
</XRD>
`,
);
};
export { hostMetaController };

View File

@ -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<URL>((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<Response> {
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 };

View File

@ -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<typeof webfingerSchema>;
export { webfingerSchema };
export type { Webfinger };