From e61651ac06c662b43817f85581b50e4254efbd7b Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Fri, 13 Sep 2024 08:07:38 -0300 Subject: [PATCH 1/4] nip29: make @staab happier. --- 29.md | 90 +++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 75 insertions(+), 15 deletions(-) diff --git a/29.md b/29.md index 6232f8b65..f4a543645 100644 --- a/29.md +++ b/29.md @@ -22,6 +22,12 @@ Relays are supposed to generate the events that describe group metadata and grou A group may be identified by a string in the format `'`. 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`. +Group identifiers must be strings restricted to the characters `a-z0-9-_`. + +When encountering just the `` without the `'`, clients can choose to connect to the group with id `_`, which is a special top-level group dedicated to relay-local discussions. + +Group identifiers in most cases should be random or pseudo-random, as that mitigates message replay confusiong and ensures they can be migrated or forked to other relays easily without risking conflicting with other groups using the same id in these new relays. This isn't a hard rule, as, for example, in `unmanaged` and/or ephemeral relays groups might not want to migrate ever, so they might not care about this. Notably, the `_` relay-local group isn't expected to be migrated ever. + ## The `h` tag Events 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_. @@ -36,8 +42,22 @@ This is a hack to prevent messages from being broadcasted to external relays tha Relays 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. +## Unmanaged groups + +Unmanaged 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. + +In `unmanaged` groups, everybody is considered to be a member. + +Unmanaged 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. + ## Event definitions +These are the events expected to be found in NIP-29 groups. + +### Normal user-created events + +These events generally can be sent by all members of a group and they require the `h` tag to be present so they're attached to a specific group. + - *text root note* (`kind:11`) This is the basic unit of a "microblog" root text note sent to a group. @@ -79,6 +99,14 @@ Similar to `kind:12`, this is the basic unit of a chat message sent to a group. `kind:10` SHOULD use NIP-10 markers, just like `kind:12`. +- other events: + +Groups may also accept other events, like long-form articles, calendar, livestream, market announcements and so on. These should be as defined in their respective NIPs, with the addition of the `h` tag. + +### User-related group management events + +These are events that can be sent my user to manage their situation in a group, they also require the `h` tag. + - *join request* (`kind:9021`) Any user can send one of these events to the relay in order to be automatically or manually added to the group. If the group is `open` the relay will automatically issue a `kind:9000` in response adding this user. Otherwise group admins may choose to query for these requests and act upon them. @@ -88,11 +116,14 @@ Any user can send one of these events to the relay in order to be automatically "kind": 9021, "content": "optional reason", "tags": [ - ["h", ""] + ["h", ""], + ["claim", ""] ] } ``` +The optional `claim` tag may be used by the relay to preauthorize acceptances in `closed` groups, together with the `kind:9009` `create-invite` moderation event. + - *leave request* (`kind:9022`) Any 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,6 +138,10 @@ Any user can send one of these events to the relay in order to be automatically } ``` +### Group state -- or moderation + +These 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. + - *moderation events* (`kinds:9000-9020`) (optional) Clients 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. @@ -124,17 +159,24 @@ Clients can send these events to a relay in order to accomplish a moderation act Each moderation action uses a different kind and requires different arguments, which are given as tags. These are defined in the following table: -| kind | name | tags | -| --- | --- | --- | -| 9000 | `add-user` | `p` (pubkey hex) | -| 9001 | `remove-user` | `p` (pubkey hex) | -| 9002 | `edit-metadata` | `name`, `about`, `picture` (string) | -| 9003 | `add-permission` | `p` (pubkey), `permission` (name) | -| 9004 | `remove-permission` | `p` (pubkey), `permission` (name) | -| 9005 | `delete-event` | `e` (id hex) | -| 9006 | `edit-group-status` | `public` or `private`, `open` or `closed` | -| 9007 | `create-group` | | -| 9008 | `delete-group` | | +| kind | name | tags | +| --- | --- | --- | +| 9000 | `add-user` | `p` (pubkey hex) | +| 9001 | `remove-user` | `p` (pubkey hex) | +| 9002 | `edit-metadata` | `name`, `about`, `picture` (string) | +| 9003 | `add-permission` | `p` (pubkey), `permission` (name) | +| 9004 | `remove-permission` | `p` (pubkey), `permission` (name) | +| 9005 | `delete-event` | `e` (id hex) | +| 9006 | `edit-group-status` | `public` or `private`, `open` or `closed` | +| 9007 | `create-group` | | +| 9008 | `delete-group` | | +| 9009 | `create-invite` | `code`, `uses` (how many times it can be used) | + +It'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. + +### Group metadata events + +These events contain the group id in a `d` tag instead of the `h` tag. They are expected to 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). - *group metadata* (`kind:39000`) (optional) @@ -142,6 +184,8 @@ This event defines the metadata for the group -- basically how clients should di If the group is forked and hosted in multiple relays, there will be multiple versions of this event in each different relay and so on. +When this event is not found, clients may still connect to the group, but treat it as having a different status, `unmanaged`, + ```jsonc { "kind": 39000, @@ -194,7 +238,9 @@ The list of capabilities, as defined by this NIP, for now, is the following: Similar to *group admins*, this event is supposed to be generated by relays that host the group. -It'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. +It's a 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. + +Clients should not assume this will always be present or that it will contain a full list of members, as relays may opt to not publish it or publish a shortened version. ```json { @@ -209,6 +255,20 @@ It's a NIP-51-like list of pubkeys that are members of the group. Relays might c } ``` -## Storing the list of groups a user belongs to +## Implementation quirks + +### Checking your own membership in a group + +The 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. + +### Adding yourself to a group + +When 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. + +### Storing your list of groups + +A 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. + +### Using `unmanaged` relays -A 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. +To prevent event leakage, replay and confusion, 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. From 765daceaa1a25a0324864668cf977cbdcb30bbd4 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Wed, 18 Sep 2024 22:27:03 -0300 Subject: [PATCH 2/4] remove invites, simplify group metadata edits, rework fine-grained "permissions" into unspecified "roles". --- 29.md | 77 +++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/29.md b/29.md index f4a543645..c0dbcef79 100644 --- a/29.md +++ b/29.md @@ -144,7 +144,7 @@ These are events expected to be sent by the relay master key or by group admins - *moderation events* (`kinds:9000-9020`) (optional) -Clients 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. +Clients 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`). ```json { @@ -161,22 +161,21 @@ Each moderation action uses a different kind and requires different arguments, w | kind | name | tags | | --- | --- | --- | -| 9000 | `add-user` | `p` (pubkey hex) | -| 9001 | `remove-user` | `p` (pubkey hex) | -| 9002 | `edit-metadata` | `name`, `about`, `picture` (string) | -| 9003 | `add-permission` | `p` (pubkey), `permission` (name) | -| 9004 | `remove-permission` | `p` (pubkey), `permission` (name) | -| 9005 | `delete-event` | `e` (id hex) | -| 9006 | `edit-group-status` | `public` or `private`, `open` or `closed` | +| 9000 | `add-user` | `p` with pubkey hex | +| 9001 | `remove-user` | `p` with pubkey hex | +| 9002 | `edit-metadata` | fields from `kind:39000` to be modified | +| 9003 | | | +| 9004 | | | +| 9005 | `delete-event` | | +| 9006 | `set-role` | `p` with pubkey hex and roles | | 9007 | `create-group` | | | 9008 | `delete-group` | | -| 9009 | `create-invite` | `code`, `uses` (how many times it can be used) | It'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. ### Group metadata events -These events contain the group id in a `d` tag instead of the `h` tag. They are expected to 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). +These 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). - *group metadata* (`kind:39000`) (optional) @@ -206,43 +205,29 @@ When this event is not found, clients may still connect to the group, but treat - *group admins* (`kind:39001`) (optional) -Similar to the group metadata, this event is supposed to be generated by relays that host the group. +Each 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. -Each 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. - -The list of capabilities, as defined by this NIP, for now, is the following: - -- `add-user` -- `edit-metadata` -- `delete-event` -- `remove-user` -- `add-permission` -- `remove-permission` -- `edit-group-status` -- `delete-group` - -```json +```jsonc { "kind": 39001, "content": "list of admins for the pizza lovers group", "tags": [ ["d", ""], - ["p", "", "ceo", "add-user", "edit-metadata", "delete-event", "remove-user"], - ["p", "", "secretary", "add-user", "delete-event"] - ] + ["p", "", "ceo"], + ["p", "", "secretary", "gardener"], + // other pubkeys... + ], // other fields... } ``` - *group members* (`kind:39002`) (optional) -Similar to *group admins*, this event is supposed to be generated by relays that host the group. +It'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. -It's a 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. +Clients should not assume this will always be present or that it will contain a full list of members. -Clients should not assume this will always be present or that it will contain a full list of members, as relays may opt to not publish it or publish a shortened version. - -```json +```jsonc { "kind": 39002, "content": "list of members for the pizza lovers group", @@ -251,7 +236,31 @@ Clients should not assume this will always be present or that it will contain a ["p", ""], ["p", ""], ["p", ""], - ] + // other pubkeys... + ], + // other fields... +} +``` + +- *group roles* (`kind:39003`) (optional) + +This 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. + +For 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). + +The 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. + +```jsonc +{ + "kind": 39003, + "content": "list of roles supported by this group", + "tags": [ + ["d", ""], + ["role", "", ""], + ["role", "", ""], + // other roles... + ], + // other fields... } ``` From e3cf02840d382360a604a7506e1b9608c63c4002 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Mon, 21 Oct 2024 13:45:51 -0300 Subject: [PATCH 3/4] rename "claim"=>"code", get rid of kind 9006 (just use 9000), add a paragraph explaining moderation. --- 29.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/29.md b/29.md index c0dbcef79..c4ee49527 100644 --- a/29.md +++ b/29.md @@ -42,6 +42,14 @@ This is a hack to prevent messages from being broadcasted to external relays tha Relays 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. +## Group management + +Groups 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). + +The 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. + +Users 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. + ## Unmanaged groups Unmanaged 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. @@ -117,12 +125,12 @@ Any user can send one of these events to the relay in order to be automatically "content": "optional reason", "tags": [ ["h", ""], - ["claim", ""] + ["code", ""] ] } ``` -The optional `claim` tag may be used by the relay to preauthorize acceptances in `closed` groups, together with the `kind:9009` `create-invite` moderation event. +The optional `code` tag may be used by the relay to preauthorize acceptances in `closed` groups, together with the `kind:9009` `create-invite` moderation event. - *leave request* (`kind:9022`) @@ -161,13 +169,10 @@ Each moderation action uses a different kind and requires different arguments, w | kind | name | tags | | --- | --- | --- | -| 9000 | `add-user` | `p` with pubkey hex | +| 9000 | `add-user` | `p` with pubkey hex and optional roles | | 9001 | `remove-user` | `p` with pubkey hex | | 9002 | `edit-metadata` | fields from `kind:39000` to be modified | -| 9003 | | | -| 9004 | | | | 9005 | `delete-event` | | -| 9006 | `set-role` | `p` with pubkey hex and roles | | 9007 | `create-group` | | | 9008 | `delete-group` | | From d4d040ee715a1f742a19e2c3a9e8697387725e46 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Tue, 22 Oct 2024 09:55:42 -0300 Subject: [PATCH 4/4] fix typo. --- 29.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/29.md b/29.md index c4ee49527..80e0f96cd 100644 --- a/29.md +++ b/29.md @@ -113,7 +113,7 @@ Groups may also accept other events, like long-form articles, calendar, livestre ### User-related group management events -These are events that can be sent my user to manage their situation in a group, they also require the `h` tag. +These are events that can be sent by users to manage their situation in a group, they also require the `h` tag. - *join request* (`kind:9021`)