Skip to main content

cosmic_applet_avestruz/guide/
protocol.rs

1// SPDX-License-Identifier: MIT
2
3//! Which NIPs are spoken and which kinds are read and written, and where
4//! in the code each is. Documentation only.
5//!
6//! Nostr is specified in pieces, the NIPs, and a client is the set of
7//! pieces it took. This page is that set for Avestruz: for someone who
8//! knows the protocol and wants to find the code, or who knows the code
9//! and wants to know what another client will make of what it writes.
10//!
11//! 1. [The kinds](#the-kinds)
12//! 2. [The NIPs](#the-nips)
13//! 3. [What an event goes through](#what-an-event-goes-through)
14//! 4. [What is written, and what is only read](#what-is-written-and-what-is-only-read)
15//! 5. [What other clients find](#what-other-clients-find)
16//!
17//! # The kinds
18//!
19//! ```mermaid
20//! flowchart LR
21//!     subgraph said["What people say"]
22//!         k1["1: a note, a reply, a quote"]
23//!         k1111["1111: a comment"]
24//!     end
25//!     subgraph done["What is done to what they say"]
26//!         k6["6, 16: a repost"]
27//!         k7["7: a reaction"]
28//!         k9735["9735: a zap receipt"]
29//!     end
30//!     subgraph who["Who someone is, and where"]
31//!         k0["0: a profile"]
32//!         k3["3: who they follow"]
33//!         k10002["10002: where they write and read"]
34//!     end
35//!     subgraph own["What the account keeps"]
36//!         k10003["10003: bookmarks"]
37//!         lists["10006, 10007, 10050, 10086, 10089: lists of relays"]
38//!         k31234["31234: drafts"]
39//!     end
40//!     done --> said
41//!     said --> who
42//!     own --> who
43//! ```
44//!
45//! | Kind | What | Read | Written | Where |
46//! |---|---|---|---|---|
47//! | 0 | A profile | Yes | No | [`Profile`](crate::nostr::models::Profile) |
48//! | 1 | A text note: a note, a reply, a quote | Yes | Yes | [`crate::nostr::compose`], [`Note`](crate::nostr::models::Note) |
49//! | 3 | A contact list: who an account follows | Yes | Yes | [`crate::nostr::contacts`] |
50//! | 6, 16 | A repost of a note, of anything else | Counted, and told of when it is of the account's note | Yes | [`crate::nostr::engagement`], [`crate::nostr::notifications`] |
51//! | 7 | A reaction | Counted, and told of when it is to the account's note | Yes: a like, or an emoji | [`crate::nostr::engagement`], [`crate::nostr::notifications`] |
52//! | 1111 | A comment | Yes | Yes | [`crate::nostr::compose`] |
53//! | 9734 | A zap request | No | Signed, and sent to no relay | [`crate::nostr::zap`] |
54//! | 9735 | A zap receipt | Counted, and told of when the account's wallet service signed it | No | [`crate::nostr::engagement`], [`crate::nostr::notifications`] |
55//! | 10002 | A relay list | Yes, everyone's | Yes | [`crate::nostr::outbox`], [`crate::nostr::relay_lists`] |
56//! | 10003 | A bookmark list | Its private half | Its private half | [`crate::nostr::bookmarks`] |
57//! | 10006 | Blocked relays | Yes | Yes | [`crate::nostr::relay_lists`] |
58//! | 10007 | Search relays | Yes | Yes | [`crate::nostr::relay_lists`] |
59//! | 10050 | The relays direct messages go to | Yes | Yes | [`crate::nostr::relay_lists`] |
60//! | 10063 | A media server list (BUD-03) | Yes | Yes | [`crate::nostr::blossom`] |
61//! | 10086 | Indexer relays | Yes | Yes | [`crate::nostr::relay_lists`] |
62//! | 10089 | Trusted relays | Yes | Yes | [`crate::nostr::relay_lists`] |
63//! | 24242 | An authorization to send a file to media servers (BUD-11) | No | Signed, and sent to no relay: it goes to the media servers, with the file | [`crate::nostr::blossom`] |
64//! | 31234 | A draft wrap | Yes | Yes, to the relay it runs itself alone | [`crate::nostr::kept_drafts`] |
65//!
66//! A feed shows kinds 1 and 1111. Anything else that a note quotes or a
67//! thread is about (a picture, an article) shows as what it says, as
68//! plain text, with a comment under it being a comment.
69//!
70//! # The NIPs
71//!
72//! | NIP | What it is | What Avestruz does with it | Where |
73//! |---|---|---|---|
74//! | 01 | Events, filters, relays | Everything | [`crate::nostr::client`] |
75//! | 02 | Contact lists | The feed is who the account follows. Following and unfollowing rewrite the list | [`crate::nostr::contacts`] |
76//! | 04 | Encryption, the old way | Read, in lists older clients wrote. Never written | [`crate::nostr::account`] |
77//! | 05 | Names at a domain | Checked with the domain when a profile is open, and resolved when one is typed in a search | [`crate::nostr::nip05`] |
78//! | 10 | Replies to text notes | Threads are put in order by it, and replies are tagged by it | [`crate::nostr::thread`], [`crate::nostr::compose`] |
79//! | 11 | What a relay says of itself | Asked on the relays page, and for a relay typed in a search | [`crate::nostr::relay_info`] |
80//! | 17 | Private direct messages | Only the list of relays they go to (kind 10050) is shown and changed. Messages are not read or written | [`crate::nostr::relay_lists`] |
81//! | 18 | Reposts and quotes | Reposts are counted and made. A quote is a note with another's address in it | [`crate::nostr::engagement`], [`crate::nostr::compose`] |
82//! | 19 | Addresses: `npub`, `nsec`, `note`, `nevent`, `nprofile` | Read wherever one is typed or written in a note, relay hints included. Written in a quote, and in a note's share link, which names the relays it was seen on | [`crate::nostr::content`], [`crate::nostr::search`], [`crate::nostr::account`], [`crate::nostr::share`] |
83//! | 21 | `nostr:` links | Read in the text of notes | [`crate::nostr::content`] |
84//! | 22 | Comments | Read in threads. A reply to anything but a text note is one | [`crate::nostr::compose`] |
85//! | 25 | Reactions | Counted, whatever they say. A like is a `+`; any emoji Unicode has can be reacted with. The account's own shows as what it says, if that is an emoji, and as a like otherwise: a custom emoji (NIP-30) is one of those | [`crate::nostr::engagement`], [`crate::emoji`] |
86//! | 37 | Draft wraps | How drafts are kept. The list of private relays (kind 10013) is not used | [`crate::nostr::kept_drafts`] |
87//! | 42 | Authentication to a relay | Avestruz does not authenticate to relays. It looks for NIP-42 in what a relay says of itself, on the relays page | [`crate::nostr::relay_lists`] |
88//! | 44 | Encryption | What the account keeps to itself: private bookmarks, private relays in a list, drafts | [`crate::nostr::account`] |
89//! | 46 | Remote signing | One of the three ways to sign in | [`crate::nostr::account`] |
90//! | 50 | Search | The search page | [`crate::nostr::search`] |
91//! | 51 | Lists | The bookmark list and the lists of relays | [`crate::nostr::bookmarks`], [`crate::nostr::relay_lists`] |
92//! | 57 | Zaps | Zap requests are made, receipts are counted and waited for. A receipt for a zap to the account is checked against the key its Lightning address names, before it is told of | [`crate::nostr::zap`], [`crate::nostr::notifications`] |
93//! | 65 | Relay lists | Where the account writes, where everyone else is read from, and where what names the account is looked for: the relays it reads | [`crate::nostr::outbox`] |
94//! | 70 | Protected events | A note whose author asked that it go nowhere they didn't send it is reposted without being carried whole | [`crate::nostr::engagement`] |
95//! | 92 | `imeta` tags | Read for a picture's size, so that its room is held before it arrives; and for which links are videos, their proportions and the picture that stands for them. Written for each file attached to a note: its kind, hash, size, and a picture's width and height | [`crate::nostr::content`], [`crate::nostr::blossom`] |
96//!
97//! Beside the NIPs, zapping speaks LNURL-pay to a Lightning address
98//! (LUD-06 and LUD-16), over `https`.
99//!
100//! And attaching a file speaks Blossom to the account's media servers,
101//! over `https`: the file is sent (BUD-02) after asking whether it would
102//! be taken (BUD-06), the other servers are asked to fetch it (BUD-04),
103//! each request is authorized by an event the account signs (BUD-11),
104//! and which servers they are is the account's server list (BUD-03).
105//! Media servers of other kinds (NIP-96, NIP-98) are not spoken to. See
106//! [`crate::nostr::blossom`].
107//!
108//! # What an event goes through
109//!
110//! ```mermaid
111//! flowchart LR
112//!     relay["A relay sends an event"] --> checked["Its id and signature are checked, by the relay library"]
113//!     checked --> kept[("Kept in the store")]
114//!     kept --> queried["Asked for, by a filter"]
115//!     queried --> model["Made into what a view shows"]
116//!     model --> row["A row"]
117//!     written["Something is written"] --> unsigned["An unsigned event"]
118//!     unsigned --> signed["Signed: by the key from the keyring, or by a remote signer"]
119//!     signed --> sent["Sent to relays"]
120//!     sent -->|"once a relay took it"| kept
121//! ```
122//!
123//! An event is never shown straight from a relay. It goes into the store
124//! and what is shown is asked of the store, so what was checked once is
125//! what is shown, and what is shown is there the next time.
126//!
127//! What a view shows is not an event either, but a model made from one:
128//! a [`Note`](crate::nostr::models::Note) has its text taken apart into
129//! what is plain, what is a link, who is mentioned and what is quoted
130//! ([`crate::nostr::content`]), once, when it comes in. A row is built
131//! from that many times a second and parses nothing.
132//!
133//! Going the other way, the modules that make events make them *unsigned*
134//! and know nothing of keys: [`crate::nostr::compose`],
135//! [`crate::nostr::contacts`], [`crate::nostr::bookmarks`],
136//! [`crate::nostr::relay_lists`], [`crate::nostr::engagement`] and
137//! [`crate::nostr::kept_drafts`] are pure functions from what is meant to
138//! an `EventBuilder`. Signing is one place
139//! ([`Signer`](crate::nostr::account::Signer)), and sending is another
140//! ([`NostrService`](crate::nostr::client::NostrService)).
141//!
142//! # What is written, and what is only read
143//!
144//! Avestruz writes little, on purpose: what the account asked for, and
145//! nothing on its own.
146//!
147//! - It never writes a profile (kind 0).
148//! - It never writes a public bookmark, and never reads one: what is
149//!   bookmarked here is in the half of the list that is encrypted.
150//! - It never writes a list it could not read whole, and never writes a
151//!   first list without saying so (see
152//!   [`crate::guide::flows`]).
153//! - It never sends a draft to any relay but the one it runs itself.
154//! - It never sends what was typed in the sign-in field or the search
155//!   field anywhere, if it is a key.
156//!
157//! # What other clients find
158//!
159//! The lists are shared with every other client the account uses, so they
160//! are written the way the clients that keep the most in them write them:
161//!
162//! - a bookmark goes into the private half of kind 10003, after the
163//!   others, as an `e` tag that may say after the id where the note is;
164//! - a relay stays where its list had it, public or private, and a new
165//!   one goes where lists of that kind usually keep theirs;
166//! - a private half is written with NIP-44 and read with NIP-44 or NIP-04,
167//!   so a list an older client left can be read, and is written back the
168//!   new way;
169//! - whatever a list holds that this client doesn't know is carried over
170//!   to the next list untouched.