From b9e756de2662fdb03bc1fead895bbbd18fce9a78 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 19 Dec 2023 19:18:20 -0600 Subject: [PATCH 1/2] deps: remove Author from nostr-relaypool --- src/deps.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/deps.ts b/src/deps.ts index a6b893c..b9db9e2 100644 --- a/src/deps.ts +++ b/src/deps.ts @@ -9,7 +9,7 @@ export { } from 'https://deno.land/x/hono@v3.10.1/mod.ts'; export { cors, logger, serveStatic } from 'https://deno.land/x/hono@v3.10.1/middleware.ts'; export { z } from 'https://deno.land/x/zod@v3.21.4/mod.ts'; -export { Author, RelayPool } from 'https://dev.jspm.io/nostr-relaypool@0.6.30'; +export { RelayPool } from 'https://dev.jspm.io/nostr-relaypool@0.6.30'; export { type Event, type EventTemplate, From 26e64e781c3d4e2cd6425993793905bb2457619c Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 19 Dec 2023 21:15:41 -0600 Subject: [PATCH 2/2] Add NIP-11 support --- src/controllers/api/instance.ts | 4 ++-- src/controllers/nostr/relay-info.ts | 19 +++++++++++++++++++ src/controllers/nostr/relay.ts | 8 +++++++- 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 src/controllers/nostr/relay-info.ts diff --git a/src/controllers/api/instance.ts b/src/controllers/api/instance.ts index 10b359b..ebc3269 100644 --- a/src/controllers/api/instance.ts +++ b/src/controllers/api/instance.ts @@ -10,8 +10,8 @@ const instanceController: AppController = (c) => { return c.json({ uri: host, title: 'Ditto', - description: 'An efficient and flexible social media server.', - short_description: 'An efficient and flexible social media server.', + description: 'Nostr and the Fediverse', + short_description: 'Nostr and the Fediverse', registrations: Conf.registrations, max_toot_chars: Conf.postCharLimit, configuration: { diff --git a/src/controllers/nostr/relay-info.ts b/src/controllers/nostr/relay-info.ts new file mode 100644 index 0000000..83b2c57 --- /dev/null +++ b/src/controllers/nostr/relay-info.ts @@ -0,0 +1,19 @@ +import { AppController } from '@/app.ts'; +import { Conf } from '@/config.ts'; + +const relayInfoController: AppController = (c) => { + return c.json({ + name: 'Ditto', + description: 'Nostr and the Fediverse.', + pubkey: '', + contact: `mailto:${Conf.adminEmail}`, + supported_nips: [1, 5, 9, 11, 45, 46, 98], + software: 'Ditto', + version: '0.0.0', + limitation: { + // TODO. + }, + }); +}; + +export { relayInfoController }; diff --git a/src/controllers/nostr/relay.ts b/src/controllers/nostr/relay.ts index 9f5cd59..f4b32b3 100644 --- a/src/controllers/nostr/relay.ts +++ b/src/controllers/nostr/relay.ts @@ -1,3 +1,4 @@ +import { relayInfoController } from '@/controllers/nostr/relay-info.ts'; import * as eventsDB from '@/db/events.ts'; import * as pipeline from '@/pipeline.ts'; import { jsonSchema } from '@/schema.ts'; @@ -116,9 +117,14 @@ function prepareFilters(filters: ClientREQ[2][]): Filter[] { })); } -const relayController: AppController = (c) => { +const relayController: AppController = (c, next) => { const upgrade = c.req.header('upgrade'); + // NIP-11: https://github.com/nostr-protocol/nips/blob/master/11.md + if (c.req.header('accept') === 'application/nostr+json') { + return relayInfoController(c, next); + } + if (upgrade?.toLowerCase() !== 'websocket') { return c.text('Please use a Nostr client to connect.', 400); }