Skip to main content

Module protocol

Module protocol 

Source
Expand description

Which NIPs are spoken and which kinds are read and written, and where in the code each is. Documentation only.

Nostr is specified in pieces, the NIPs, and a client is the set of pieces it took. This page is that set for Avestruz: for someone who knows the protocol and wants to find the code, or who knows the code and wants to know what another client will make of what it writes.

  1. The kinds
  2. The NIPs
  3. What an event goes through
  4. What is written, and what is only read
  5. What other clients find

§The kinds

flowchart LR
    subgraph said["What people say"]
        k1["1: a note, a reply, a quote"]
        k1111["1111: a comment"]
    end
    subgraph done["What is done to what they say"]
        k6["6, 16: a repost"]
        k7["7: a reaction"]
        k9735["9735: a zap receipt"]
    end
    subgraph who["Who someone is, and where"]
        k0["0: a profile"]
        k3["3: who they follow"]
        k10002["10002: where they write and read"]
    end
    subgraph own["What the account keeps"]
        k10003["10003: bookmarks"]
        lists["10006, 10007, 10050, 10086, 10089: lists of relays"]
        k31234["31234: drafts"]
    end
    done --> said
    said --> who
    own --> who
KindWhatReadWrittenWhere
0A profileYesNoProfile
1A text note: a note, a reply, a quoteYesYescrate::nostr::compose, Note
3A contact list: who an account followsYesYescrate::nostr::contacts
6, 16A repost of a note, of anything elseCounted, and told of when it is of the account’s noteYescrate::nostr::engagement, crate::nostr::notifications
7A reactionCounted, and told of when it is to the account’s noteYes: a like, or an emojicrate::nostr::engagement, crate::nostr::notifications
1111A commentYesYescrate::nostr::compose
9734A zap requestNoSigned, and sent to no relaycrate::nostr::zap
9735A zap receiptCounted, and told of when the account’s wallet service signed itNocrate::nostr::engagement, crate::nostr::notifications
10002A relay listYes, everyone’sYescrate::nostr::outbox, crate::nostr::relay_lists
10003A bookmark listIts private halfIts private halfcrate::nostr::bookmarks
10006Blocked relaysYesYescrate::nostr::relay_lists
10007Search relaysYesYescrate::nostr::relay_lists
10050The relays direct messages go toYesYescrate::nostr::relay_lists
10063A media server list (BUD-03)YesYescrate::nostr::blossom
10086Indexer relaysYesYescrate::nostr::relay_lists
10089Trusted relaysYesYescrate::nostr::relay_lists
24242An authorization to send a file to media servers (BUD-11)NoSigned, and sent to no relay: it goes to the media servers, with the filecrate::nostr::blossom
31234A draft wrapYesYes, to the relay it runs itself alonecrate::nostr::kept_drafts

A feed shows kinds 1 and 1111. Anything else that a note quotes or a thread is about (a picture, an article) shows as what it says, as plain text, with a comment under it being a comment.

§The NIPs

NIPWhat it isWhat Avestruz does with itWhere
01Events, filters, relaysEverythingcrate::nostr::client
02Contact listsThe feed is who the account follows. Following and unfollowing rewrite the listcrate::nostr::contacts
04Encryption, the old wayRead, in lists older clients wrote. Never writtencrate::nostr::account
05Names at a domainChecked with the domain when a profile is open, and resolved when one is typed in a searchcrate::nostr::nip05
10Replies to text notesThreads are put in order by it, and replies are tagged by itcrate::nostr::thread, crate::nostr::compose
11What a relay says of itselfAsked on the relays page, and for a relay typed in a searchcrate::nostr::relay_info
17Private direct messagesOnly the list of relays they go to (kind 10050) is shown and changed. Messages are not read or writtencrate::nostr::relay_lists
18Reposts and quotesReposts are counted and made. A quote is a note with another’s address in itcrate::nostr::engagement, crate::nostr::compose
19Addresses: npub, nsec, note, nevent, nprofileRead 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 oncrate::nostr::content, crate::nostr::search, crate::nostr::account, crate::nostr::share
21nostr: linksRead in the text of notescrate::nostr::content
22CommentsRead in threads. A reply to anything but a text note is onecrate::nostr::compose
25ReactionsCounted, 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 thosecrate::nostr::engagement, crate::emoji
37Draft wrapsHow drafts are kept. The list of private relays (kind 10013) is not usedcrate::nostr::kept_drafts
42Authentication to a relayAvestruz does not authenticate to relays. It looks for NIP-42 in what a relay says of itself, on the relays pagecrate::nostr::relay_lists
44EncryptionWhat the account keeps to itself: private bookmarks, private relays in a list, draftscrate::nostr::account
46Remote signingOne of the three ways to sign incrate::nostr::account
50SearchThe search pagecrate::nostr::search
51ListsThe bookmark list and the lists of relayscrate::nostr::bookmarks, crate::nostr::relay_lists
57ZapsZap 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 ofcrate::nostr::zap, crate::nostr::notifications
65Relay listsWhere the account writes, where everyone else is read from, and where what names the account is looked for: the relays it readscrate::nostr::outbox
70Protected eventsA note whose author asked that it go nowhere they didn’t send it is reposted without being carried wholecrate::nostr::engagement
92imeta tagsRead 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 heightcrate::nostr::content, crate::nostr::blossom

Beside the NIPs, zapping speaks LNURL-pay to a Lightning address (LUD-06 and LUD-16), over https.

And attaching a file speaks Blossom to the account’s media servers, over https: the file is sent (BUD-02) after asking whether it would be taken (BUD-06), the other servers are asked to fetch it (BUD-04), each request is authorized by an event the account signs (BUD-11), and which servers they are is the account’s server list (BUD-03). Media servers of other kinds (NIP-96, NIP-98) are not spoken to. See crate::nostr::blossom.

§What an event goes through

flowchart LR
    relay["A relay sends an event"] --> checked["Its id and signature are checked, by the relay library"]
    checked --> kept[("Kept in the store")]
    kept --> queried["Asked for, by a filter"]
    queried --> model["Made into what a view shows"]
    model --> row["A row"]
    written["Something is written"] --> unsigned["An unsigned event"]
    unsigned --> signed["Signed: by the key from the keyring, or by a remote signer"]
    signed --> sent["Sent to relays"]
    sent -->|"once a relay took it"| kept

An event is never shown straight from a relay. It goes into the store and what is shown is asked of the store, so what was checked once is what is shown, and what is shown is there the next time.

What a view shows is not an event either, but a model made from one: a Note has its text taken apart into what is plain, what is a link, who is mentioned and what is quoted (crate::nostr::content), once, when it comes in. A row is built from that many times a second and parses nothing.

Going the other way, the modules that make events make them unsigned and know nothing of keys: crate::nostr::compose, crate::nostr::contacts, crate::nostr::bookmarks, crate::nostr::relay_lists, crate::nostr::engagement and crate::nostr::kept_drafts are pure functions from what is meant to an EventBuilder. Signing is one place (Signer), and sending is another (NostrService).

§What is written, and what is only read

Avestruz writes little, on purpose: what the account asked for, and nothing on its own.

  • It never writes a profile (kind 0).
  • It never writes a public bookmark, and never reads one: what is bookmarked here is in the half of the list that is encrypted.
  • It never writes a list it could not read whole, and never writes a first list without saying so (see crate::guide::flows).
  • It never sends a draft to any relay but the one it runs itself.
  • It never sends what was typed in the sign-in field or the search field anywhere, if it is a key.

§What other clients find

The lists are shared with every other client the account uses, so they are written the way the clients that keep the most in them write them:

  • a bookmark goes into the private half of kind 10003, after the others, as an e tag that may say after the id where the note is;
  • a relay stays where its list had it, public or private, and a new one goes where lists of that kind usually keep theirs;
  • a private half is written with NIP-44 and read with NIP-44 or NIP-04, so a list an older client left can be read, and is written back the new way;
  • whatever a list holds that this client doesn’t know is carried over to the next list untouched.