From 278e13a6ef28cb51c2c8d3a92f4870022be53958 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 28 Mar 2025 14:53:24 -0500 Subject: [PATCH 1/3] Add .goosehints file --- .goosehints | 43 +++++++++++++++++++++++++++++++++++++++++++ .vscode/settings.json | 5 ++++- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 .goosehints diff --git a/.goosehints b/.goosehints new file mode 100644 index 00000000..4e17068c --- /dev/null +++ b/.goosehints @@ -0,0 +1,43 @@ +# Ditto + +This project is called Ditto, a self-hosted social media server written in TypeScript with Deno. It implements the [Nostr Protocol](https://raw.githubusercontent.com/nostr-protocol/nips/refs/heads/master/README.md), and parts of the [Mastodon API](https://docs.joinmastodon.org/methods/) and [Pleroma API](https://git.pleroma.social/pleroma/pleroma/-/raw/develop/docs/development/API/pleroma_api.md). + +## Project Structure + +Ditto is a monorepo with a `packages` directory. The main package is `packages/ditto`, and the main API definition is in `packages/ditto/app.ts`. + +## Deno, npm, and jsr + +Ditto uses Deno 2.x + +Dependencies are managed in `deno.json`, which are added with the `deno add` command. This command also updates the `deno.lock` file. npm packages can be added by using `deno add` and prefixing the package name with an `npm:` protocol. For example, `deno add npm:kysely` would add the `kysely` package from npm. + +[jsr](https://jsr.io/) is a modern alternative to npm. It's a completely different registry with different packages available. jsr packages can be added by using `deno add` and prefixing the package name with a `jsr:` protocol. For example, `deno add jsr:@std/assert` would add the `@std/assert` package from jsr. + +## Nostr + +Nostr is a decentralized social media protocol involving clients, relays, keys, and a unified Nostr event format. + +Specifications on Nostr are called "NIPs". NIP stands for "Nostr Implementation Possibilities". NIPs are numbered like `NIP-XX` where `XX` are two capitalized hexadecimal digits, eg `NIP-01` and `NIP-C7`. + +To learn about Nostr, use the fetch tool to read [NIP-01](https://raw.githubusercontent.com/nostr-protocol/nips/refs/heads/master/01.md). + +To read a specific NIP, construct the NIP URL following this template: `https://raw.githubusercontent.com/nostr-protocol/nips/refs/heads/master/{nip}.md` (replace `{nip}` in the URL template with the relevant NIP name, eg `07` for NIP-07, or `C7` for NIP-C7). Then use the fetch tool to read the URL. + +To discover the full list of NIPs, use the fetch tool to read the [NIPs README](https://raw.githubusercontent.com/nostr-protocol/nips/refs/heads/master/README.md). + +It's important that Ditto conforms to Nostr standards. Please read as much of the NIPs as you need to have a full understanding before adding or modifying Nostr events and filters. It is possible to add new ideas to Nostr that don't exist yet in the NIPs, but only after other options have been explored. Care must be taken when adding new Nostr ideas, to ensure they fit seamlessly within the existing Nostr ecosystem. + +## How Ditto uses Nostr and Mastodon API + +Ditto implements a full Nostr relay, available at `/relay` of the Ditto server. + +Mastodon API functionality, available at `/api/*, is built around the Nostr relay's storage implementation. + +Ditto's goal is to enable Mastodon API clients to interact directly with Nostr. It achieves this by implementing most of Mastodon's API, and "pretending" to be a Mastodon server to client applications, while in actuality it uses Nostr as its decentralized protocol layer. + +## Testing Changes + +After making changes, please run `deno task check` to check for type errors. If there are any type errors, please try to fix them. + +Afterwards, run `deno fmt` to format the code, and then you are done. Please do not try to run the server, or run any other tests. \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index ba5b1bb4..8a761ba9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,5 +2,8 @@ "deno.enable": true, "deno.lint": true, "editor.defaultFormatter": "denoland.vscode-deno", - "path-intellisense.extensionOnImport": true + "path-intellisense.extensionOnImport": true, + "files.associations": { + ".goosehints": "markdown" + } } From 34a29c8f4e6454d428d6546a5b060a02fc1c4d6d Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 28 Mar 2025 16:15:20 -0500 Subject: [PATCH 2/3] NIP-11 improvements --- packages/ditto/controllers/nostr/relay-info.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/ditto/controllers/nostr/relay-info.ts b/packages/ditto/controllers/nostr/relay-info.ts index 945e311b..f9df43d0 100644 --- a/packages/ditto/controllers/nostr/relay-info.ts +++ b/packages/ditto/controllers/nostr/relay-info.ts @@ -9,6 +9,8 @@ const relayInfoController: AppController = async (c) => { const meta = await getInstanceMetadata(c.var); c.res.headers.set('access-control-allow-origin', '*'); + c.res.headers.set('access-control-allow-headers', '*'); + c.res.headers.set('access-control-allow-methods', 'GET, POST, OPTIONS'); return c.json({ name: meta.name, @@ -16,7 +18,7 @@ const relayInfoController: AppController = async (c) => { pubkey: await conf.signer.getPublicKey(), contact: meta.email, supported_nips: [1, 5, 9, 11, 16, 45, 50, 46, 98], - software: 'Ditto', + software: 'https://gitlab.com/soapbox-pub/ditto', version: denoJson.version, limitation: { auth_required: false, From 1a6c114a57b76ebd14615b08b6fad63ec7f30730 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 28 Mar 2025 16:22:03 -0500 Subject: [PATCH 3/3] Fix inline codeblock in .goosehints --- .goosehints | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.goosehints b/.goosehints index 4e17068c..f22691c7 100644 --- a/.goosehints +++ b/.goosehints @@ -32,7 +32,7 @@ It's important that Ditto conforms to Nostr standards. Please read as much of th Ditto implements a full Nostr relay, available at `/relay` of the Ditto server. -Mastodon API functionality, available at `/api/*, is built around the Nostr relay's storage implementation. +Mastodon API functionality, available at `/api/*`, is built around the Nostr relay's storage implementation. Ditto's goal is to enable Mastodon API clients to interact directly with Nostr. It achieves this by implementing most of Mastodon's API, and "pretending" to be a Mastodon server to client applications, while in actuality it uses Nostr as its decentralized protocol layer.