upleb.uk

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

summaryrefslogtreecommitdiff
path: root/29.md
diff options
context:
space:
mode:
Diffstat (limited to '29.md')
-rw-r--r--29.md168
1 files changed, 99 insertions, 69 deletions
diff --git a/29.md b/29.md
index 6232f8b..331047f 100644
--- a/29.md
+++ b/29.md
@@ -22,9 +22,15 @@ Relays are supposed to generate the events that describe group metadata and grou
22 22
23A group may be identified by a string in the format `<host>'<group-id>`. For example, a group with _id_ `abcdef` hosted at the relay `wss://groups.nostr.com` would be identified by the string `groups.nostr.com'abcdef`. 23A group may be identified by a string in the format `<host>'<group-id>`. For example, a group with _id_ `abcdef` hosted at the relay `wss://groups.nostr.com` would be identified by the string `groups.nostr.com'abcdef`.
24 24
25Group identifiers must be strings restricted to the characters `a-z0-9-_`, and SHOULD be random in order to avoid name collisions.
26
27When encountering just the `<host>` without the `'<group-id>`, clients MAY infer `_` as the group id, which is a special top-level group dedicated to relay-local discussions.
28
25## The `h` tag 29## The `h` tag
26 30
27Events sent by users to groups (chat messages, text notes, moderation events etc) must have an `h` tag with the value set to the group _id_. 31Events sent by users to groups (chat messages, text notes, moderation events etc) MUST have an `h` tag with the value set to the group _id_.
32
33`h` tags MAY include the group's name as the second argument. This allows `unmanaged` groups to be assigned human-readable names without relay support.
28 34
29## Timeline references 35## Timeline references
30 36
@@ -36,48 +42,33 @@ This is a hack to prevent messages from being broadcasted to external relays tha
36 42
37Relays should prevent late publication (messages published now with a timestamp from days or even hours ago) unless they are open to receive a group forked or moved from another relay. 43Relays should prevent late publication (messages published now with a timestamp from days or even hours ago) unless they are open to receive a group forked or moved from another relay.
38 44
39## Event definitions 45## Group management
40 46
41- *text root note* (`kind:11`) 47Groups can have any number of users with elevated access. These users are identified by role labels which are arbitrarily defined by the relays (see also the description of `kind:39003`). What each role is capable of not defined in this NIP either, it's a relay policy that can vary. Roles can be assigned by other users (as long as they have the capability to add roles) by publishing a `kind:9000` event with that user's pubkey in a `p` tag and the roles afterwards (even if the user is already a group member a `kind:9000` can be issued and the user roles must just be updated).
42 48
43This is the basic unit of a "microblog" root text note sent to a group. 49The roles supported by the group as to having some special privilege assigned to them should be accessible on the event `kind:39003`, but the relay may also accept other role names, arbitrarily defined by clients, and just not do anything with them.
44 50
45```jsonc 51Users with any roles that have any privilege can be considered _admins_ in a broad sense and be returned in the `kind:39001` event for a group.
46 "kind": 11,
47 "content": "hello my friends lovers of pizza",
48 "tags": [
49 ["h", "<group-id>"],
50 ["previous", "<event-id-first-chars>", "<event-id-first-chars>", /*...*/]
51 ]
52 // other fields...
53```
54 52
55- *threaded text reply* (`kind:12`) 53## Unmanaged groups
56 54
57This is the basic unit of a "microblog" reply note sent to a group. It's the same as `kind:11`, except for the fact that it must be used whenever it's in reply to some other note (either in reply to a `kind:11` or a `kind:12`). `kind:12` events SHOULD use NIP-10 markers, leaving an empty relay url: 55Unmanaged groups are impromptu groups that can be used in any public relay unaware of NIP-29 specifics. They piggyback on relays' natural white/blacklists (or lack of) but aside from that are not actively managed and won't have any admins, group state or metadata events.
58 56
59* `["e", "<kind-11-root-id>", "", "root"]` 57In `unmanaged` groups, everybody is considered to be a member.
60* `["e", "<kind-12-event-id>", "", "reply"]`
61 58
62- *chat message* (`kind:9`) 59Unmanaged groups can transition to managed groups, in that case the relay master key just has to publish moderation events setting the state of all groups and start enforcing the rules they choose to.
63 60
64This is the basic unit of a _chat message_ sent to a group. 61## Event definitions
65 62
66```jsonc 63These are the events expected to be found in NIP-29 groups.
67 "kind": 9,
68 "content": "hello my friends lovers of pizza",
69 "tags": [
70 ["h", "<group-id>"],
71 ["previous", "<event-id-first-chars>", "<event-id-first-chars>", /*...*/]
72 ]
73 // other fields...
74```
75 64
76- *chat message threaded reply* (`kind:10`) 65### Normal user-created events
77 66
78Similar to `kind:12`, this is the basic unit of a chat message sent to a group. This is intended for in-chat threads that may be hidden by default. Not all in-chat replies MUST use `kind:10`, only when the intention is to create a hidden thread that isn't part of the normal flow of the chat (although clients are free to display those by default too). 67Groups may accept any event kind, including chats, threads, long-form articles, calendar, livestreams, market announcements and so on. These should be as defined in their respective NIPs, with the addition of the `h` tag.
79 68
80`kind:10` SHOULD use NIP-10 markers, just like `kind:12`. 69### User-related group management events
70
71These are events that can be sent by users to manage their situation in a group, they also require the `h` tag.
81 72
82- *join request* (`kind:9021`) 73- *join request* (`kind:9021`)
83 74
@@ -88,11 +79,14 @@ Any user can send one of these events to the relay in order to be automatically
88 "kind": 9021, 79 "kind": 9021,
89 "content": "optional reason", 80 "content": "optional reason",
90 "tags": [ 81 "tags": [
91 ["h", "<group-id>"] 82 ["h", "<group-id>"],
83 ["code", "<optional-invite-code>"]
92 ] 84 ]
93} 85}
94``` 86```
95 87
88The optional `code` tag may be used by the relay to preauthorize acceptances in `closed` groups, together with the `kind:9009` `create-invite` moderation event.
89
96- *leave request* (`kind:9022`) 90- *leave request* (`kind:9022`)
97 91
98Any user can send one of these events to the relay in order to be automatically removed from the group. The relay will automatically issue a `kind:9001` in response removing this user. 92Any user can send one of these events to the relay in order to be automatically removed from the group. The relay will automatically issue a `kind:9001` in response removing this user.
@@ -107,11 +101,15 @@ Any user can send one of these events to the relay in order to be automatically
107} 101}
108``` 102```
109 103
104### Group state -- or moderation
105
106These are events expected to be sent by the relay master key or by group admins -- and relays should reject them if they don't come from an authorized admin. They also require the `h` tag.
107
110- *moderation events* (`kinds:9000-9020`) (optional) 108- *moderation events* (`kinds:9000-9020`) (optional)
111 109
112Clients can send these events to a relay in order to accomplish a moderation action. Relays must check if the pubkey sending the event is capable of performing the given action. The relay may discard the event after taking action or keep it as a moderation log. 110Clients can send these events to a relay in order to accomplish a moderation action. Relays must check if the pubkey sending the event is capable of performing the given action based on its role and the relay's internal policy (see also the description of `kind:39003`).
113 111
114```json 112```jsonc
115{ 113{
116 "kind": 90xx, 114 "kind": 90xx,
117 "content": "optional reason", 115 "content": "optional reason",
@@ -124,17 +122,21 @@ Clients can send these events to a relay in order to accomplish a moderation act
124 122
125Each moderation action uses a different kind and requires different arguments, which are given as tags. These are defined in the following table: 123Each moderation action uses a different kind and requires different arguments, which are given as tags. These are defined in the following table:
126 124
127| kind | name | tags | 125| kind | name | tags |
128| --- | --- | --- | 126| --- | --- | --- |
129| 9000 | `add-user` | `p` (pubkey hex) | 127| 9000 | `put-user` | `p` with pubkey hex and optional roles |
130| 9001 | `remove-user` | `p` (pubkey hex) | 128| 9001 | `remove-user` | `p` with pubkey hex |
131| 9002 | `edit-metadata` | `name`, `about`, `picture` (string) | 129| 9002 | `edit-metadata` | fields from `kind:39000` to be modified |
132| 9003 | `add-permission` | `p` (pubkey), `permission` (name) | 130| 9005 | `delete-event` | `e` with event id hex |
133| 9004 | `remove-permission` | `p` (pubkey), `permission` (name) | 131| 9007 | `create-group` | |
134| 9005 | `delete-event` | `e` (id hex) | 132| 9008 | `delete-group` | |
135| 9006 | `edit-group-status` | `public` or `private`, `open` or `closed` | 133| 9009 | `create-invite` | |
136| 9007 | `create-group` | | 134
137| 9008 | `delete-group` | | 135It's expected that the group state (of who is an allowed member or not, who is an admin and with which permission or not, what are the group name and picture etc) can be fully reconstructed from the canonical sequence of these events.
136
137### Group metadata events
138
139These events contain the group id in a `d` tag instead of the `h` tag. They MUST be created by the relay master key only and a single instance of each (or none) should exist at all times for each group. They are merely informative but should reflect the latest group state (as it was changed by moderation events over time).
138 140
139- *group metadata* (`kind:39000`) (optional) 141- *group metadata* (`kind:39000`) (optional)
140 142
@@ -142,6 +144,8 @@ This event defines the metadata for the group -- basically how clients should di
142 144
143If the group is forked and hosted in multiple relays, there will be multiple versions of this event in each different relay and so on. 145If the group is forked and hosted in multiple relays, there will be multiple versions of this event in each different relay and so on.
144 146
147When this event is not found, clients may still connect to the group, but treat it as having a different status, `unmanaged`,
148
145```jsonc 149```jsonc
146{ 150{
147 "kind": 39000, 151 "kind": 39000,
@@ -162,41 +166,29 @@ If the group is forked and hosted in multiple relays, there will be multiple ver
162 166
163- *group admins* (`kind:39001`) (optional) 167- *group admins* (`kind:39001`) (optional)
164 168
165Similar to the group metadata, this event is supposed to be generated by relays that host the group. 169Each admin is listed along with one or more roles. These roles SHOULD have a correspondence with the roles supported by the relay, as advertised by the `kind:39003` event.
166 170
167Each admin gets a label that is only used for display purposes, and a list of permissions it has are listed afterwards. These permissions can inform client building UI, but ultimately are evaluated by the relay in order to become effective. 171```jsonc
168
169The list of capabilities, as defined by this NIP, for now, is the following:
170
171- `add-user`
172- `edit-metadata`
173- `delete-event`
174- `remove-user`
175- `add-permission`
176- `remove-permission`
177- `edit-group-status`
178- `delete-group`
179
180```json
181{ 172{
182 "kind": 39001, 173 "kind": 39001,
183 "content": "list of admins for the pizza lovers group", 174 "content": "list of admins for the pizza lovers group",
184 "tags": [ 175 "tags": [
185 ["d", "<group-id>"], 176 ["d", "<group-id>"],
186 ["p", "<pubkey1-as-hex>", "ceo", "add-user", "edit-metadata", "delete-event", "remove-user"], 177 ["p", "<pubkey1-as-hex>", "ceo"],
187 ["p", "<pubkey2-as-hex>", "secretary", "add-user", "delete-event"] 178 ["p", "<pubkey2-as-hex>", "secretary", "gardener"],
188 ] 179 // other pubkeys...
180 ],
189 // other fields... 181 // other fields...
190} 182}
191``` 183```
192 184
193- *group members* (`kind:39002`) (optional) 185- *group members* (`kind:39002`) (optional)
194 186
195Similar to *group admins*, this event is supposed to be generated by relays that host the group. 187It's a list of pubkeys that are members of the group. Relays might choose to not to publish this information, to restrict what pubkeys can fetch it or to only display a subset of the members in it.
196 188
197It's a NIP-51-like list of pubkeys that are members of the group. Relays might choose to not to publish this information or to restrict what pubkeys can fetch it. 189Clients should not assume this will always be present or that it will contain a full list of members.
198 190
199```json 191```jsonc
200{ 192{
201 "kind": 39002, 193 "kind": 39002,
202 "content": "list of members for the pizza lovers group", 194 "content": "list of members for the pizza lovers group",
@@ -205,10 +197,48 @@ It's a NIP-51-like list of pubkeys that are members of the group. Relays might c
205 ["p", "<admin1>"], 197 ["p", "<admin1>"],
206 ["p", "<member-pubkey1>"], 198 ["p", "<member-pubkey1>"],
207 ["p", "<member-pubkey2>"], 199 ["p", "<member-pubkey2>"],
208 ] 200 // other pubkeys...
201 ],
202 // other fields...
209} 203}
210``` 204```
211 205
212## Storing the list of groups a user belongs to 206- *group roles* (`kind:39003`) (optional)
207
208This is an event that MAY be published by the relay informing users and clients about what are the roles supported by this relay according to its internal logic.
209
210For example, a relay may choose to support the roles `"admin"` and `"moderator"`, in which the `"admin"` will be allowed to edit the group metadata, delete messages and remove users from the group, while the `"moderator"` can only delete messages (or the relay may choose to call these roles `"ceo"` and `"secretary"` instead, the exact role name is not relevant).
211
212The process through which the relay decides what roles to support and how to handle moderation events internally based on them is specific to each relay and not specified here.
213
214```jsonc
215{
216 "kind": 39003,
217 "content": "list of roles supported by this group",
218 "tags": [
219 ["d", "<group-id>"],
220 ["role", "<role-name>", "<optional-description>"],
221 ["role", "<role-name>", "<optional-description>"],
222 // other roles...
223 ],
224 // other fields...
225}
226```
227
228## Implementation quirks
229
230### Checking your own membership in a group
231
232The latest of either `kind:9000` or `kind:9001` events present in a group should tell a user that they are currently members of the group or if they were removed. In case none of these exist the user is assumed to not be a member of the group -- unless the group is `unmanaged`, in which case the user is assumed to be a member.
233
234### Adding yourself to a group
235
236When a group is `open`, anyone can send a `kind:9021` event to it in order to be added, then expect a `kind:9000` event to be emitted confirming that the user was added. The same happens with `closed` groups, except in that case a user may only send a `kind:9021` if it has an invite code.
237
238### Storing your list of groups
239
240A definition for `kind:10009` was included in [NIP-51](51.md) that allows clients to store the list of groups a user wants to remember being in.
241
242### Using `unmanaged` relays
213 243
214A definition for kind `10009` was included in [NIP-51](51.md) that allows clients to store the list of groups a user wants to remember being in. 244To prevent event leakage, when using `unmanaged` relays, clients should include the [NIP-70](70.md) `-` tag, as just the `previous` tag won't be checked by other `unmanaged` relays.