From 616c405f0f54ec4ed5a586a0f25c3395543d6b2a Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Thu, 6 Jun 2024 14:14:59 -0500 Subject: [PATCH] Add an endpoint to request a NIP-05 name --- src/app.ts | 3 ++- src/controllers/api/ditto.ts | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/app.ts b/src/app.ts index bb1c5b6..4378445 100644 --- a/src/app.ts +++ b/src/app.ts @@ -30,7 +30,7 @@ import { adminAccountAction, adminAccountsController } from '@/controllers/api/a import { appCredentialsController, createAppController } from '@/controllers/api/apps.ts'; import { blocksController } from '@/controllers/api/blocks.ts'; import { bookmarksController } from '@/controllers/api/bookmarks.ts'; -import { adminRelaysController, adminSetRelaysController } from '@/controllers/api/ditto.ts'; +import { adminRelaysController, adminSetRelaysController, inviteRequestController } from '@/controllers/api/ditto.ts'; import { emptyArrayController, emptyObjectController, notImplementedController } from '@/controllers/api/fallback.ts'; import { instanceController } from '@/controllers/api/instance.ts'; import { markersController, updateMarkersController } from '@/controllers/api/markers.ts'; @@ -239,6 +239,7 @@ app.delete('/api/v1/pleroma/admin/statuses/:id', requireRole('admin'), pleromaAd app.get('/api/v1/admin/ditto/relays', requireRole('admin'), adminRelaysController); app.put('/api/v1/admin/ditto/relays', requireRole('admin'), adminSetRelaysController); +app.post('/api/v1/ditto/nip05', requireSigner, inviteRequestController); app.post('/api/v1/ditto/zap', requireSigner, zapController); app.post('/api/v1/reports', requireSigner, reportController); diff --git a/src/controllers/api/ditto.ts b/src/controllers/api/ditto.ts index df4f210..cf08cd3 100644 --- a/src/controllers/api/ditto.ts +++ b/src/controllers/api/ditto.ts @@ -5,6 +5,7 @@ import { AppController } from '@/app.ts'; import { Conf } from '@/config.ts'; import { Storages } from '@/storages.ts'; import { AdminSigner } from '@/signers/AdminSigner.ts'; +import { createEvent } from '@/utils/api.ts'; const markerSchema = z.enum(['read', 'write']); @@ -58,3 +59,25 @@ function renderRelays(event: NostrEvent): RelayEntity[] { return acc; }, [] as RelayEntity[]); } + +const inviteRequestSchema = z.object({ + nip05: z.string().email(), + reason: z.string().max(500).optional(), +}); + +export const inviteRequestController: AppController = async (c) => { + const { nip05, reason } = inviteRequestSchema.parse(await c.req.json()); + + await createEvent({ + kind: 3036, + content: reason, + tags: [ + ['r', nip05], + ['L', 'nip05.domain'], + ['l', nip05.split('@')[1], 'nip05.domain'], + ['p', Conf.pubkey], + ], + }, c); + + return new Response('', { status: 204 }); +};