From d1fd5c585c327ff3479834202e8433ae2899c0e4 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Sat, 27 Jul 2024 15:37:58 +0200 Subject: [PATCH] docs: :memo: Add docs about federation --- app/federation/http/page.mdx | 78 ++++++++++++++++++++++++++++++ app/federation/page.mdx | 18 +++++++ app/federation/validation/page.mdx | 31 ++++++++++++ app/introduction/page.mdx | 3 -- app/page.tsx | 2 +- components/ExperimentalWarning.tsx | 4 +- components/Footer.tsx | 14 ++++-- components/Guides.tsx | 53 ++++++++++---------- components/Header.tsx | 5 +- components/MobileNavigation.tsx | 4 ++ components/Navigation.tsx | 10 +++- components/Search.tsx | 4 ++ mdx/rehype.mjs | 1 + typography.ts | 2 +- 14 files changed, 189 insertions(+), 40 deletions(-) create mode 100644 app/federation/http/page.mdx create mode 100644 app/federation/page.mdx create mode 100644 app/federation/validation/page.mdx diff --git a/app/federation/http/page.mdx b/app/federation/http/page.mdx new file mode 100644 index 0000000..355edaf --- /dev/null +++ b/app/federation/http/page.mdx @@ -0,0 +1,78 @@ +export const metadata = { + title: 'HTTP', + description: + 'How Lysand uses the HTTP protocol for all communications between instances.', +} + +# HTTP + +Lysand uses the HTTP protocol for all communications between instances. HTTP requests must conform to certain standards to ensure compatibility between different implementations, as well as to ensure the security and integrity of the data being exchanged. + +## Communication + +ALL kinds of HTTP requests/responses between instances **MUST** include a [Signature](/signatures), signed with either the relevant [User](/entities/users)'s private key or the [Server Actor](/entities/server-actor)'s private key. + +## Requests + + + + + + Must include `application/json`. + + + Must include `application/json; charset=utf-8`, if the request has a body. + + + Request signature, if the request is signed. + + + Date and time of the request. + + + A string identifying the software making the request. + + + + + ```http {{ 'title': 'Example Request' }} + POST /users/1/inbox HTTP/1.1 + Accept: application/json + Signature: keyId="https://example.com/users/1",algorithm="ed25519",headers="(request-target) host date digest",signature="..." + Date: Thu, 01 Jan 1970 00:00:00 GMT + User-Agent: CoolServer/1.0 (https://coolserver.com) + ``` + + + +## Responses + + + + + + Must include `application/json; charset=utf-8`. + + + Response signature, if the response is signed. + + + Date and time of the response. + + + Must include `no-store` on entities that can be edited directly without a `Patch`, such as `Users`. + + **SHOULD** include a large `max-age` on entities that are not expected to change frequently, such as `Notes`, or CDN resources. + + + + + ```http {{ 'title': 'Example Response' }} + HTTP/1.1 200 OK + Content-Type: application/json; charset=utf-8 + Date: Thu, 01 Jan 1970 00:00:00 GMT + Signature: keyId="https://example.com/users/1",algorithm="ed25519",headers="(request-target) host date digest",signature="..." + Cache-Control: no-store + ``` + + \ No newline at end of file diff --git a/app/federation/page.mdx b/app/federation/page.mdx new file mode 100644 index 0000000..e3c6dd7 --- /dev/null +++ b/app/federation/page.mdx @@ -0,0 +1,18 @@ +import { Guides, Guide } from '@/components/Guides'; + +export const metadata = { + title: 'Federation', + description: + 'Description of federation behavior in Lysand.', +} + +# Federation + +Being a federation protocol, Lysand defines a set of rules for exchanging data between instances. This document outlines the behavior of instances in a Lysand federated network. {{ className: 'lead' }} + +Federation is built on the [HyperText Transfer Protocol (HTTP)](https://tools.ietf.org/html/rfc7230) and the [JavaScript Object Notation (JSON)](https://tools.ietf.org/html/rfc7159) data format. Instances communicate with each other by sending and receiving JSON payloads over HTTP. + + + + + \ No newline at end of file diff --git a/app/federation/validation/page.mdx b/app/federation/validation/page.mdx new file mode 100644 index 0000000..813205e --- /dev/null +++ b/app/federation/validation/page.mdx @@ -0,0 +1,31 @@ +export const metadata = { + title: 'Validation', + description: + 'Validation rules for Lysand implementations.', +} + +# Validation + +Implementations **MUST** strictly validate all incoming data to ensure that it is well-formed and adheres to the Lysand Protocol. If a request is invalid, the server **MUST** return a `400 Bad Request` HTTP status code. + + + Remember that while *your* implementation may disallow or restrict some user input, other implementations may not. You **should not** apply those restrictions to data coming from other instances. + + For example, if your implementation disallows using HTML in posts, you should not strip HTML from posts coming from other instances. You *may* choose to display them differently, but you should not modify the data itself. + + +Things that should be validated include, but are not limited to: + +- The presence of **all required fields**. +- The **format** of all fields (integers should not be strings, dates should be in ISO 8601 format, etc.). +- The presence of **all required headers**. +- The presence of a **valid signature**. +- The **length** of all fields (for example, the `username` field on a `User` entity should be at least 1 character long). + - Do not set arbitrary limits on the length of fields that other instances may send you. For example, a `bio` field should not be limited to 160 characters, even if your own implementation has such a limit. + - If you do set limits, they should be reasonable and well-documented. +- The **type**, **precision** and **scale** of all numeric fields. + - For example, a `size` field on a `ContentFormat` structure should be a positive integer, not a negative number or a floating-point number. +- The **validity** of all URLs and URIs (run them through your favorite URL parser). +- The **time** of all dates and times (people should not be born in the future, or in the year 0). + +It is your implementation's duty to reject data from other instances that does not adhere to the strict spec. **This is crucial to ensure the integrity of your instance and the network as a whole**. Allowing data that is technically valid but semantically incorrect can lead to the degradation of the entire Lysand ecosystem. \ No newline at end of file diff --git a/app/introduction/page.mdx b/app/introduction/page.mdx index 3cb16f8..f67406e 100644 --- a/app/introduction/page.mdx +++ b/app/introduction/page.mdx @@ -1,4 +1,3 @@ -import { Guides } from '@/components/Guides' import { Resources } from '@/components/Resources' import { HeroPattern } from '@/components/HeroPattern' @@ -50,6 +49,4 @@ The Lysand Protocol is heavily inspired by the [ActivityPub](https://www.w3.org/ - **Signatures**: Most types of interactions **must** be signed with a private key. Unlike other protocols, signatures are **mandatory**, not optional. - **Developer-Friendliness**: Understanding and implementing your own Lysand server should be easy. Documentation is aimed at developers first. -{/* */} - diff --git a/app/page.tsx b/app/page.tsx index 1e40eca..1aa3510 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -63,7 +63,7 @@ const Page: FC = () => { children: ( <>
-

+

Lysand

diff --git a/components/ExperimentalWarning.tsx b/components/ExperimentalWarning.tsx index 08bddc2..52d1518 100644 --- a/components/ExperimentalWarning.tsx +++ b/components/ExperimentalWarning.tsx @@ -2,7 +2,7 @@ import type { FC } from "react"; export const ExperimentalWarning: FC = () => ( <> -
+
+ ); diff --git a/components/Footer.tsx b/components/Footer.tsx index ef22551..1bf9679 100644 --- a/components/Footer.tsx +++ b/components/Footer.tsx @@ -87,7 +87,12 @@ function SocialLink({ children: ReactNode; }) { return ( - + {children}
- - Follow us on GitHub + + Find us on GitHub

diff --git a/components/Guides.tsx b/components/Guides.tsx index c4bb00f..fa91594 100644 --- a/components/Guides.tsx +++ b/components/Guides.tsx @@ -1,41 +1,38 @@ +import type { ReactNode } from "react"; import { Button } from "./Button"; import { Heading } from "./Heading"; -const guides = [ - { - href: "/authentication", - name: "Authentication", - description: "Learn how to authenticate your API requests.", - }, -]; - -export function Guides() { +export function Guides({ children }: { children: ReactNode }) { return (
Guides
- {guides.map((guide) => ( -
-

- {guide.name} -

-

- {guide.description} -

-

- -

-
- ))} + {children}
); } + +export function Guide({ + href, + name, + description, +}: { href: string; name: string; description: string }) { + return ( +
+

+ {name} +

+

+ {description} +

+

+ +

+
+ ); +} diff --git a/components/Header.tsx b/components/Header.tsx index f12d60c..e1eccd4 100644 --- a/components/Header.tsx +++ b/components/Header.tsx @@ -80,7 +80,10 @@ export const Header = forwardRef, { className?: string }>(
-