upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/01.md
diff options
context:
space:
mode:
authorVitor Pamplona <vitor@vitorpamplona.com>2024-12-19 10:15:46 -0500
committerGitHub <noreply@github.com>2024-12-19 10:15:46 -0500
commitf7d97f3f40dc6677e6f996ffff431142ffe05810 (patch)
tree2eaa8c8628cc9a4b05811ed3869e21221fd85307 /01.md
parentd5b77b6d7348061cd0f16adc35e4d02a3a0b7380 (diff)
parent561059ff85c171b87a12b8381b724b4afc569a97 (diff)
Merge branch 'master' into draft-event
Diffstat (limited to '01.md')
-rw-r--r--01.md41
1 files changed, 20 insertions, 21 deletions
diff --git a/01.md b/01.md
index b51fdf0..d62f317 100644
--- a/01.md
+++ b/01.md
@@ -43,16 +43,16 @@ To obtain the `event.id`, we `sha256` the serialized event. The serialization is
43``` 43```
44 44
45To prevent implementation differences from creating a different event ID for the same event, the following rules MUST be followed while serializing: 45To prevent implementation differences from creating a different event ID for the same event, the following rules MUST be followed while serializing:
46- No whitespace, line breaks or other unnecessary formatting should be included in the output JSON.
47- No characters except the following should be escaped, and instead should be included verbatim:
48 - A line break, `0x0A`, as `\n`
49 - A double quote, `0x22`, as `\"`
50 - A backslash, `0x5C`, as `\\`
51 - A carriage return, `0x0D`, as `\r`
52 - A tab character, `0x09`, as `\t`
53 - A backspace, `0x08`, as `\b`
54 - A form feed, `0x0C`, as `\f`
55- UTF-8 should be used for encoding. 46- UTF-8 should be used for encoding.
47- Whitespace, line breaks or other unnecessary formatting should not be included in the output JSON.
48- The following characters in the content field must be escaped as shown, and all other characters must be included verbatim:
49 - A line break (`0x0A`), use `\n`
50 - A double quote (`0x22`), use `\"`
51 - A backslash (`0x5C`), use `\\`
52 - A carriage return (`0x0D`), use `\r`
53 - A tab character (`0x09`), use `\t`
54 - A backspace, (`0x08`), use `\b`
55 - A form feed, (`0x0C`), use `\f`
56 56
57### Tags 57### Tags
58 58
@@ -77,25 +77,25 @@ This NIP defines 3 standard tags that can be used across all event kinds with th
77 77
78- The `e` tag, used to refer to an event: `["e", <32-bytes lowercase hex of the id of another event>, <recommended relay URL, optional>]` 78- The `e` tag, used to refer to an event: `["e", <32-bytes lowercase hex of the id of another event>, <recommended relay URL, optional>]`
79- The `p` tag, used to refer to another user: `["p", <32-bytes lowercase hex of a pubkey>, <recommended relay URL, optional>]` 79- The `p` tag, used to refer to another user: `["p", <32-bytes lowercase hex of a pubkey>, <recommended relay URL, optional>]`
80- The `a` tag, used to refer to a (maybe parameterized) replaceable event 80- The `a` tag, used to refer to an addressable or replaceable event
81 - for a parameterized replaceable event: `["a", <kind integer>:<32-bytes lowercase hex of a pubkey>:<d tag value>, <recommended relay URL, optional>]` 81 - for an addressable event: `["a", <kind integer>:<32-bytes lowercase hex of a pubkey>:<d tag value>, <recommended relay URL, optional>]`
82 - for a non-parameterized replaceable event: `["a", <kind integer>:<32-bytes lowercase hex of a pubkey>:, <recommended relay URL, optional>]` 82 - for a normal replaceable event: `["a", <kind integer>:<32-bytes lowercase hex of a pubkey>:, <recommended relay URL, optional>]`
83 83
84As a convention, all single-letter (only english alphabet letters: a-z, A-Z) key tags are expected to be indexed by relays, such that it is possible, for example, to query or subscribe to events that reference the event `"5c83da77af1dec6d7289834998ad7aafbd9e2191396d75ec3cc27f5a77226f36"` by using the `{"#e": ["5c83da77af1dec6d7289834998ad7aafbd9e2191396d75ec3cc27f5a77226f36"]}` filter. 84As a convention, all single-letter (only english alphabet letters: a-z, A-Z) key tags are expected to be indexed by relays, such that it is possible, for example, to query or subscribe to events that reference the event `"5c83da77af1dec6d7289834998ad7aafbd9e2191396d75ec3cc27f5a77226f36"` by using the `{"#e": ["5c83da77af1dec6d7289834998ad7aafbd9e2191396d75ec3cc27f5a77226f36"]}` filter. Only the first value in any given tag is indexed.
85 85
86### Kinds 86### Kinds
87 87
88Kinds specify how clients should interpret the meaning of each event and the other fields of each event (e.g. an `"r"` tag may have a meaning in an event of kind 1 and an entirely different meaning in an event of kind 10002). Each NIP may define the meaning of a set of kinds that weren't defined elsewhere. This NIP defines two basic kinds: 88Kinds specify how clients should interpret the meaning of each event and the other fields of each event (e.g. an `"r"` tag may have a meaning in an event of kind 1 and an entirely different meaning in an event of kind 10002). Each NIP may define the meaning of a set of kinds that weren't defined elsewhere. This NIP defines two basic kinds:
89 89
90- `0`: **metadata**: the `content` is set to a stringified JSON object `{name: <username>, about: <string>, picture: <url, string>}` describing the user who created the event. [Extra metadata fields](24.md#kind-0) may be set. A relay may delete older events once it gets a new one for the same pubkey. 90- `0`: **user metadata**: the `content` is set to a stringified JSON object `{name: <username>, about: <string>, picture: <url, string>}` describing the user who created the event. [Extra metadata fields](24.md#kind-0) may be set. A relay may delete older events once it gets a new one for the same pubkey.
91- `1`: **text note**: the `content` is set to the **plaintext** content of a note (anything the user wants to say). Content that must be parsed, such as Markdown and HTML, should not be used. Clients should also not parse content as those. 91- `1`: **text note**: the `content` is set to the **plaintext** content of a note (anything the user wants to say). Content that must be parsed, such as Markdown and HTML, should not be used. Clients should also not parse content as those.
92 92
93And also a convention for kind ranges that allow for easier experimentation and flexibility of relay implementation: 93And also a convention for kind ranges that allow for easier experimentation and flexibility of relay implementation:
94 94
95- for kind `n` such that `1000 <= n < 10000`, events are **regular**, which means they're all expected to be stored by relays. 95- for kind `n` such that `1000 <= n < 10000 || 4 <= n < 45 || n == 1 || n == 2`, events are **regular**, which means they're all expected to be stored by relays.
96- for kind `n` such that `10000 <= n < 20000 || n == 0 || n == 3`, events are **replaceable**, which means that, for each combination of `pubkey` and `kind`, only the latest event MUST be stored by relays, older versions MAY be discarded. 96- for kind `n` such that `10000 <= n < 20000 || n == 0 || n == 3`, events are **replaceable**, which means that, for each combination of `pubkey` and `kind`, only the latest event MUST be stored by relays, older versions MAY be discarded.
97- for kind `n` such that `20000 <= n < 30000`, events are **ephemeral**, which means they are not expected to be stored by relays. 97- for kind `n` such that `20000 <= n < 30000`, events are **ephemeral**, which means they are not expected to be stored by relays.
98- for kind `n` such that `30000 <= n < 40000`, events are **parameterized replaceable**, which means that, for each combination of `pubkey`, `kind` and the `d` tag's first value, only the latest event MUST be stored by relays, older versions MAY be discarded. 98- for kind `n` such that `30000 <= n < 40000`, events are **addressable** by their `kind`, `pubkey` and `d` tag value -- which means that, for each combination of `kind`, `pubkey` and the `d` tag value, only the latest event MUST be stored by relays, older versions MAY be discarded.
99 99
100In case of replaceable events with the same timestamp, the event with the lowest id (first in lexical order) should be retained, and the other discarded. 100In case of replaceable events with the same timestamp, the event with the lowest id (first in lexical order) should be retained, and the other discarded.
101 101
@@ -125,13 +125,13 @@ Clients can send 3 types of messages, which must be JSON arrays, according to th
125 "authors": <a list of lowercase pubkeys, the pubkey of an event must be one of these>, 125 "authors": <a list of lowercase pubkeys, the pubkey of an event must be one of these>,
126 "kinds": <a list of a kind numbers>, 126 "kinds": <a list of a kind numbers>,
127 "#<single-letter (a-zA-Z)>": <a list of tag values, for #e — a list of event ids, for #p — a list of pubkeys, etc.>, 127 "#<single-letter (a-zA-Z)>": <a list of tag values, for #e — a list of event ids, for #p — a list of pubkeys, etc.>,
128 "since": <an integer unix timestamp in seconds, events must be newer than this to pass>, 128 "since": <an integer unix timestamp in seconds. Events must have a created_at >= to this to pass>,
129 "until": <an integer unix timestamp in seconds, events must be older than this to pass>, 129 "until": <an integer unix timestamp in seconds. Events must have a created_at <= to this to pass>,
130 "limit": <maximum number of events relays SHOULD return in the initial query> 130 "limit": <maximum number of events relays SHOULD return in the initial query>
131} 131}
132``` 132```
133 133
134Upon receiving a `REQ` message, the relay SHOULD query its internal database and return events that match the filter, then store that filter and send again all future events it receives to that same websocket until the websocket is closed. The `CLOSE` event is received with the same `<subscription_id>` or a new `REQ` is sent using the same `<subscription_id>`, in which case relay MUST overwrite the previous subscription. 134Upon receiving a `REQ` message, the relay SHOULD return events that match the filter. Any new events it receives SHOULD be sent to that same websocket until the connection is closed, a `CLOSE` event is received with the same `<subscription_id>`, or a new `REQ` is sent using the same `<subscription_id>` (in which case a new subscription is created, replacing the old one).
135 135
136Filter attributes containing lists (`ids`, `authors`, `kinds` and tag filters like `#e`) are JSON arrays with one or more values. At least one of the arrays' values must match the relevant field in an event for the condition to be considered a match. For scalar event attributes such as `authors` and `kind`, the attribute from the event must be contained in the filter list. In the case of tag attributes such as `#e`, for which an event may have multiple values, the event and filter condition values must have at least one item in common. 136Filter attributes containing lists (`ids`, `authors`, `kinds` and tag filters like `#e`) are JSON arrays with one or more values. At least one of the arrays' values must match the relevant field in an event for the condition to be considered a match. For scalar event attributes such as `authors` and `kind`, the attribute from the event must be contained in the filter list. In the case of tag attributes such as `#e`, for which an event may have multiple values, the event and filter condition values must have at least one item in common.
137 137
@@ -143,7 +143,7 @@ All conditions of a filter that are specified must match for an event for it to
143 143
144A `REQ` message may contain multiple filters. In this case, events that match any of the filters are to be returned, i.e., multiple filters are to be interpreted as `||` conditions. 144A `REQ` message may contain multiple filters. In this case, events that match any of the filters are to be returned, i.e., multiple filters are to be interpreted as `||` conditions.
145 145
146The `limit` property of a filter is only valid for the initial query and MUST be ignored afterwards. When `limit: n` is present it is assumed that the events returned in the initial query will be the last `n` events ordered by the `created_at`. It is safe to return less events than `limit` specifies, but it is expected that relays do not return (much) more events than requested so clients don't get unnecessarily overwhelmed by data. 146The `limit` property of a filter is only valid for the initial query and MUST be ignored afterwards. When `limit: n` is present it is assumed that the events returned in the initial query will be the last `n` events ordered by the `created_at`. Newer events should appear first, and in the case of ties the event with the lowest id (first in lexical order) should be first. It is safe to return less events than `limit` specifies, but it is expected that relays do not return (much) more events than requested so clients don't get unnecessarily overwhelmed by data.
147 147
148### From relay to client: sending events and notices 148### From relay to client: sending events and notices
149 149
@@ -169,7 +169,6 @@ This NIP defines no rules for how `NOTICE` messages should be sent or treated.
169 * `["OK", "b1a649ebe8...", false, "pow: difficulty 26 is less than 30"]` 169 * `["OK", "b1a649ebe8...", false, "pow: difficulty 26 is less than 30"]`
170 * `["OK", "b1a649ebe8...", false, "error: could not connect to the database"]` 170 * `["OK", "b1a649ebe8...", false, "error: could not connect to the database"]`
171- `CLOSED` messages MUST be sent in response to a `REQ` when the relay refuses to fulfill it. It can also be sent when a relay decides to kill a subscription on its side before a client has disconnected or sent a `CLOSE`. This message uses the same pattern of `OK` messages with the machine-readable prefix and human-readable message. Some examples: 171- `CLOSED` messages MUST be sent in response to a `REQ` when the relay refuses to fulfill it. It can also be sent when a relay decides to kill a subscription on its side before a client has disconnected or sent a `CLOSE`. This message uses the same pattern of `OK` messages with the machine-readable prefix and human-readable message. Some examples:
172 * `["CLOSED", "sub1", "duplicate: sub1 already opened"]`
173 * `["CLOSED", "sub1", "unsupported: filter contains unknown elements"]` 172 * `["CLOSED", "sub1", "unsupported: filter contains unknown elements"]`
174 * `["CLOSED", "sub1", "error: could not connect to the database"]` 173 * `["CLOSED", "sub1", "error: could not connect to the database"]`
175 * `["CLOSED", "sub1", "error: shutting down idle subscription"]` 174 * `["CLOSED", "sub1", "error: shutting down idle subscription"]`