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-07 19:53:42 -0300
committerfiatjaf <fiatjaf@gmail.com>2023-01-07 19:53:42 -0300
commit6a70967f0eb6e7b00fc811e34631f8db046d6e1f (patch)
treee13d666f889487585d00dc64cbd590c570e77e10
parent50faceef0965042714e7f50a45b102f35c5231ca (diff)
add challenge from relay.
-rw-r--r--42.md37
-rw-r--r--README.md1
2 files changed, 28 insertions, 10 deletions
diff --git a/42.md b/42.md
index 4c884a9..93bb3e3 100644
--- a/42.md
+++ b/42.md
@@ -19,16 +19,23 @@ A relay may want to require clients to authenticate to access restricted resourc
19 before clients can query for that kind. 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. 20 - A relay may limit subscriptions of any kind to paying users or users whitelisted through any other means, and require authentication.
21 21
22## Protocol flow 22## Definitions
23
24This NIP defines a new message, `AUTH`, which relays can send when they support authentication and clients can send to relays when they want
25to authenticate. When sent by relays, the message is of the following form:
26
27```
28["AUTH", <challenge-string>]
29```
23 30
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: 31And, when sent by clients, of the following form:
25 32
26``` 33```
27["AUTH", <signed-event>] 34["AUTH", <signed-event-json>]
28``` 35```
29 36
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 37The signed event is an ephemeral event not meant to be published or queried, it must be of `kind: 22242` and it should have at least two tags,
31WebSocket URL of the relay. `created_at` should be the current time. Example: 38one for the relay URL and one for the challenge string as received from the relay. `created_at` should be the current time. Example:
32 39
33```json 40```json
34{ 41{
@@ -36,18 +43,27 @@ WebSocket URL of the relay. `created_at` should be the current time. Example:
36 "pubkey": "...", 43 "pubkey": "...",
37 "created_at": 1669695536, 44 "created_at": 1669695536,
38 "kind": 22242, 45 "kind": 22242,
39 "tags": [], 46 "tags": [
40 "content": "wss://relay.example.com/", 47 ["relay", "wss://relay.example.com/"],
48 ["challenge", "challengestringhere"]
49 ],
50 "content": "",
41 "sig": "..." 51 "sig": "..."
42} 52}
43``` 53```
44 54
55## Protocol flow
56
57At any moment the relay may send an `AUTH` message to the client containing a challenge. After receiving that the client may decide to
58authenticate itself or not. The challenge is expected to be valid for the duration of the connection or until a next challenge is sent by
59the relay.
60
45The client may send an auth message right before performing an action for which it knows authentication will be required -- for example, right 61The 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. The authentication 62before requesting `kind: 4` chat messages --, or it may do right on connection start or at some other moment it deems best. The authentication
47is expected to last for the duration of the WebSocket connection. 63is expected to last for the duration of the WebSocket connection.
48 64
49Upon receiving a message from an unauthenticated user it can't fulfill without authentication, a relay may choose to notify the client. For 65Upon receiving a message from an unauthenticated user it can't fulfill without authentication, a relay may choose to notify the client. For
50that it can use a `NOTICE` message with a standard prefix `"restricted: "` that is readable both by humans and machines, for example: 66that it can use a `NOTICE` or `OK` message with a standard prefix `"restricted: "` that is readable both by humans and machines, for example:
51 67
52``` 68```
53["NOTICE", "restricted: we can't serve DMs to unauthenticated users, does your client implement NIP-42?"] 69["NOTICE", "restricted: we can't serve DMs to unauthenticated users, does your client implement NIP-42?"]
@@ -56,7 +72,7 @@ that it can use a `NOTICE` message with a standard prefix `"restricted: "` that
56or it can return an `OK` message noting the reason an event was not written using the same prefix: 72or it can return an `OK` message noting the reason an event was not written using the same prefix:
57 73
58``` 74```
59["OK", "b1a649ebe8...", false, "restricted: we do not accept events from unauthenticated users, please sign up at https://example.com/"] 75["OK", <event-id>, false, "restricted: we do not accept events from unauthenticated users, please sign up at https://example.com/"]
60``` 76```
61 77
62## Signed Event Verification 78## Signed Event Verification
@@ -65,5 +81,6 @@ To verify `AUTH` messages, relays must ensure:
65 81
66 - that the `kind` is `22242`; 82 - that the `kind` is `22242`;
67 - that the event `created_at` is close (e.g. within ~10 minutes) of the current time; 83 - that the event `created_at` is close (e.g. within ~10 minutes) of the current time;
68 - that the `content` field matches the relay URL: 84 - that the `"challenge"` tag matches the challenge sent before;
85 - that the `"relay"` tag matches the relay URL:
69 - URL normalization techniques can be applied. For most cases just checking if the domain name is correct should be enough. 86 - 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 f627f4d..05737b1 100644
--- a/README.md
+++ b/README.md
@@ -70,6 +70,7 @@ NIPs stand for **Nostr Implementation Possibilities**. They exist to document wh
70| NOTICE | used to send human-readable messages to clients | [1](01.md) | 70| NOTICE | used to send human-readable messages to clients | [1](01.md) |
71| EOSE | used to notify clients all stored events have been sent | [15](15.md) | 71| EOSE | used to notify clients all stored events have been sent | [15](15.md) |
72| OK | used to notify clients if an EVENT was successuful | [20](20.md) | 72| OK | used to notify clients if an EVENT was successuful | [20](20.md) |
73| AUTH | used to send authentication challenges | [42](42.md) |
73 74
74Please update these lists when proposing NIPs introducing new event kinds. 75Please update these lists when proposing NIPs introducing new event kinds.
75 76