upleb.uk

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

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfiatjaf <fiatjaf@gmail.com>2023-01-02 16:49:37 -0300
committerfiatjaf <fiatjaf@gmail.com>2023-01-02 16:56:44 -0300
commitc80be21cd44aa74efa42ead23a12343bf33ade34 (patch)
treeaad7a2a3bdcc0f9b55d6919901078b27d475afe6
parentb9467cb428489d800e8e2729b0449ee1ceec03a5 (diff)
drastically simplify @semisol's auth NIP.
-rw-r--r--41.md71
-rw-r--r--42.md68
-rw-r--r--README.md13
3 files changed, 76 insertions, 76 deletions
diff --git a/41.md b/41.md
deleted file mode 100644
index dfa49c3..0000000
--- a/41.md
+++ /dev/null
@@ -1,71 +0,0 @@
1NIP-41
2======
3
4Authentication of clients to relays
5-----------------------------------
6
7`draft` `optional` `author:Semisol`
8
9This NIP defines a way for clients to authenticate to relays by signing an ephemeral event.
10
11## Event format
12
13An event should be signed with `kind: 22241` and `content` being the WebSockets URL of the relay.
14The URL MUST:
15- Have a trailing slash if the path is `/`
16- Not have a port number if protocol is `ws` and port is `80` or protocol is `wss` and port is `443`
17- Not include the search/query
18
19Relays SHOULD treat authenticaiton events with a valid delegation as if it was the delegator authenticating.
20
21An example event is shown below:
22```json
23{
24 "id": "...",
25 "pubkey": "...",
26 "created_at": 1669695536,
27 "kind": 22241,
28 "tags": [],
29 "content": "wss://relay.example.com/",
30 "sig": "..."
31}
32```
33
34## Commands between the relay and the client
35
36This NIP defines a new command, `AUTH`, which can be sent by either the relay or the client with different meanings.
37
38A relay may send `["AUTH", <human readable reason>, <data object>]` when it needs authentication (examples: accessing kind 4 events, whitelist only, requiring proof of authorship for `EVENT`).
39The human readable reason SHOULD be prefixed with a string in the format `<short desc string>: <description>`. A list of short descriptions is listed below:
40- `restricted`: This relay is restricted and requires the pubkey of the client to check if it can access the relay. (requires a whitelist, payment, etc)
41- `publish`: The relay requests that the client identify who is sending an `EVENT` command.
42 This can be used for where only the signer of an event can publish it, or a pay-as-you-go relay allowing for you to publish others' events
43- `private`: The client has attempted to access a restricted set of events (example: kind 4 DMs) and should authenticate with the relay to receive them.
44- `other`: Any reason not defined here.
45
46`data object` MUST be a JSON object. It currently has one defined field, but may be extended by amendments to this NIP or other NIPs:
47- `subscription_id`: The subscription ID that triggered the `AUTH` request.
48
49A client may send one of the following to the relay:
50- `["AUTH", <signed event>]` to indicate it has accepted the request. This may also be sent without an authentication request.
51- `["AUTH", null]` to indicate it has rejected the request.
52
53A relay SHOULD send the [`OK`](https://github.com/nostr-protocol/nips/blob/master/20.md) command after they receive a
54non-rejecting authentication response, and use one of the following `message` prefixes if the event sent cannot be verified:
55- `too-old:`: The event signed has a too old `created_at` date.
56- `invalid-url:`: The URL in `content` is not matching.
57- `already-used:`: This event was already used to authenticate to this relay.
58- `bad-signature:`: The event has a bad signature.
59
60Please note that the `OK` message should only be sent as a response to other commands that the client sends instead of the `AUTH` command if the issue is not related to the authentication event being incorrectly signed (example: not on whitelist).
61
62Relays SHOULD send [`EOSE`](https://github.com/nostr-protocol/nips/blob/master/15.md) when an authentication request is triggered by a `REQ` command, and not send stored events after the `EOSE` when authentication is completed.
63Relays SHOULD send `OK` as a response when a command triggers authentication with the reason starting with `auth:`.
64
65Clients SHOULD retry the action (resending event, resubscribing) after they authenticate if they receive an `AUTH` request.
66
67## Signed event verification
68Relays when processing `AUTH` responses SHOULD verify the following before accepting the response:
69- that the `kind` is `22241`
70- that the event was recently signed (~10 minutes, by `created_at`)
71- that the `content` field matches the relay URL
diff --git a/42.md b/42.md
new file mode 100644
index 0000000..d5122ba
--- /dev/null
+++ b/42.md
@@ -0,0 +1,68 @@
1NIP-42
2======
3
4Authentication of clients to relays
5-----------------------------------
6
7`draft` `optional` `author:Semisol` `author:fiatjaf`
8
9This NIP defines a way for clients to authenticate to relays by signing an ephemeral event.
10
11## Motivation
12
13A relay may want to require clients to authenticate to access restricted resources. For example,
14
15 - A relay may request payment or other forms of whitelisting to publish events -- this can naïvely be achieved by limiting publication
16 to events signed by the whitelisted key, but with this NIP they may choose to accept any events as long as they are published from an
17 authenticated user;
18 - A relay may limit access to `kind: 4` DMs to only the parties involved in the chat exchange, and for that it may require authentication
19 before clients can query for that kind.
20 - A relay may limit subscriptions of any kind to paying users or users whitelisted through any other means, and require authentication.
21
22## Protocol flow
23
24This NIP defines a new message, `AUTH`, which clients can send to relays when they want to authenticate. The message is of the following form:
25
26```
27["AUTH", <signed-event>]
28```
29
30The signed event is an ephemeral event not meant to be published or queried, it must be of `kind: 22242` and content must be set to the
31WebSocket URL of the relay. `created_at` should be the current time. Example:
32
33```json
34{
35 "id": "...",
36 "pubkey": "...",
37 "created_at": 1669695536,
38 "kind": 22242,
39 "tags": [],
40 "content": "wss://relay.example.com/",
41 "sig": "..."
42}
43```
44
45The client may send an auth message right before performing an action for which it knows authentication will be required -- for example, right
46before requesting `kind: 4` chat messages --, or it may do right on connection start or at some other moment it deems best.
47
48Upon receiving a message from an unauthenticated user it can't fulfill without authentication, a relay may choose to notify the client. For
49that it can use a `NOTICE` message with a standard prefix `"restricted: "` that is readable both by humans and machines, for example:
50
51```
52["NOTICE", "restricted: we can't serve DMs to unauthenticated users, does your client implement NIP-42?"]
53```
54
55or
56
57```
58["NOTICE", "restricted: we do not accept events from unauthenticated users, please sign up at https://example.com/"]
59```
60
61## Signed Event Verification
62
63To verify `AUTH` messages, relays must ensure:
64
65 - that the `kind` is `22242`
66 - that the event was recently signed (~10 minutes, by `created_at`)
67 - that the `content` field matches the relay URL
68 - URL normalization techniques can be applied. For most cases just checking if the domain name is correct should be enough.
diff --git a/README.md b/README.md
index cce4166..f627f4d 100644
--- a/README.md
+++ b/README.md
@@ -28,6 +28,7 @@ NIPs stand for **Nostr Implementation Possibilities**. They exist to document wh
28- [NIP-35: User Discovery](35.md) 28- [NIP-35: User Discovery](35.md)
29- [NIP-36: Sensitive Content](36.md) 29- [NIP-36: Sensitive Content](36.md)
30- [NIP-40: Expiration Timestamp](40.md) 30- [NIP-40: Expiration Timestamp](40.md)
31- [NIP-42: Authentication of clients to relays](42.md)
31 32
32## Event Kinds 33## Event Kinds
33 34
@@ -47,6 +48,7 @@ NIPs stand for **Nostr Implementation Possibilities**. They exist to document wh
47| 43 | Channel Hide Message | [28](28.md) | 48| 43 | Channel Hide Message | [28](28.md) |
48| 44 | Channel Mute User | [28](28.md) | 49| 44 | Channel Mute User | [28](28.md) |
49| 45-49 | Public Chat Reserved | [28](28.md) | 50| 45-49 | Public Chat Reserved | [28](28.md) |
51| 22242 | Client Authentication | [42](42.md) |
50| 10000-19999 | Replaceable Events Reserved | [16](16.md) | 52| 10000-19999 | Replaceable Events Reserved | [16](16.md) |
51| 20000-29999 | Ephemeral Events Reserved | [16](16.md) | 53| 20000-29999 | Ephemeral Events Reserved | [16](16.md) |
52 54
@@ -54,11 +56,12 @@ NIPs stand for **Nostr Implementation Possibilities**. They exist to document wh
54## Message types 56## Message types
55 57
56### Client to Relay 58### Client to Relay
57| type | description | NIP | 59| type | description | NIP |
58|-------|-----------------------------------------------------|------------| 60|-------|-----------------------------------------------------|-------------|
59| EVENT | used to publish events | [1](01.md) | 61| EVENT | used to publish events | [1](01.md) |
60| REQ | used to request events and subscribe to new updates | [1](01.md) | 62| REQ | used to request events and subscribe to new updates | [1](01.md) |
61| CLOSE | used to stop previous subscriptions | [1](01.md) | 63| CLOSE | used to stop previous subscriptions | [1](01.md) |
64| AUTH | used to send authentication events | [42](42.md) |
62 65
63### Relay to Client 66### Relay to Client
64| type | description | NIP | 67| type | description | NIP |