upleb.uk

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

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--46.md85
1 files changed, 39 insertions, 46 deletions
diff --git a/46.md b/46.md
index e1675b0..c356a9c 100644
--- a/46.md
+++ b/46.md
@@ -4,6 +4,10 @@ NIP-46
4Nostr Remote Signing 4Nostr Remote Signing
5-------------------- 5--------------------
6 6
7## Changes
8
9`remote-signer-key` is introduced, passed in bunker url, clients must differentiate between `remote-signer-pubkey` and `user-pubkey`, must call `get_public_key` after connect.
10
7## Rationale 11## Rationale
8 12
9Private keys should be exposed to as few systems - apps, operating systems, devices - as possible as each system adds to the attack surface. 13Private keys should be exposed to as few systems - apps, operating systems, devices - as possible as each system adds to the attack surface.
@@ -12,51 +16,53 @@ This NIP describes a method for 2-way communication between a remote signer and
12 16
13## Terminology 17## Terminology
14 18
15- **Local keypair**: A local public and private key-pair used to encrypt content and communicate with the remote signer. Usually created by the client application. 19- **user**: A person that is trying to use Nostr.
16- **Remote user pubkey**: The public key that the user wants to sign as. The remote signer has control of the private key that matches this public key. 20- **client**: A user-facing application that _user_ is looking at and clicking buttons in. This application will send requests to _remote-signer_.
17- **Remote signer pubkey**: This is the public key of the remote signer itself. This is needed in both `create_account` command because you don't yet have a remote user pubkey. 21- **remote-signer**: A daemon or server running somewhere that will answer requests from _client_, also known as "bunker".
22- **client-keypair/pubkey**: The keys generated by _client_. Used to encrypt content and communicate with _remote-signer_.
23- **remote-signer-keypair/pubkey**: The keys used by _remote-signer_ to encrypt content and communicate with _client_. This keypair MAY be same as _user-keypair_, but not necessarily.
24- **user-keypair/pubkey**: The actual keys representing _user_ (that will be used to sign events in response to `sign_event` requests, for example). The _remote-signer_ generally has control over these keys.
18 25
19All pubkeys specified in this NIP are in hex format. 26All pubkeys specified in this NIP are in hex format.
20 27
21## Initiating a connection 28## Initiating a connection
22 29
23To initiate a connection between a client and a remote signer there are a few different options. 30There are two ways to initiate a connection:
24
25### Direct connection initiated by remote signer
26 31
27This is most common in a situation where you have your own nsecbunker or other type of remote signer and want to connect through a client that supports remote signing. 32### Direct connection initiated by _remote-signer_
28 33
29The remote signer would provide a connection token in the form: 34_remote-signer_ provides connection token in the form:
30 35
31``` 36```
32bunker://<remote-user-pubkey>?relay=<wss://relay-to-connect-on>&relay=<wss://another-relay-to-connect-on>&secret=<optional-secret-value> 37bunker://<remote-signer-pubkey>?relay=<wss://relay-to-connect-on>&relay=<wss://another-relay-to-connect-on>&secret=<optional-secret-value>
33``` 38```
34 39
35This token is pasted into the client by the user and the client then uses the details to connect to the remote signer via the specified relay(s). Optional secret can be used for single successfully established connection only, remote signer SHOULD ignore new attempts to establish connection with old optional secret. 40_user_ pastes this token on _client_, which then uses the details to connect to _remote-signer_ via the specified relays. Optional secret can be used for single successfully established connection only, _remote-signer_ SHOULD ignore new attempts to establish connection with old optional secret.
36 41
37### Direct connection initiated by the client 42### Direct connection initiated by the client
38 43
39In this case, basically the opposite direction of the first case, the client provides a connection token (or encodes the token in a QR code) and the signer initiates a connection to the client via the specified relay(s). 44In this case, basically the opposite direction of the first case, _client_ provides a connection token (or encodes the token in a QR code) and _remote-signer_ initiates a connection via the specified relays.
40 45
41``` 46```
42nostrconnect://<local-keypair-pubkey>?relay=<wss://relay-to-connect-on>&metadata=<json metadata in the form: {"name":"...", "url": "...", "description": "..."}> 47nostrconnect://<client-pubkey>?relay=<wss://relay-to-connect-on>&metadata=<json metadata in the form: {"name":"...", "url": "...", "description": "..."}>
43``` 48```
44 49
45## The flow 50## The flow
46 51
471. Client creates a local keypair. This keypair doesn't need to be communicated to the user since it's largely disposable (i.e. the user doesn't need to see this pubkey). Clients might choose to store it locally and they should delete it when the user logs out. 521. _client_ generates `client-keypair`. This keypair doesn't need to be communicated to _user_ since it's largely disposable. _client_ might choose to store it locally and they should delete it on logout;
482. Client gets the remote user pubkey (either via a `bunker://` connection string or a NIP-05 login-flow; shown below) 532. _client_ gets `remote-signer-pubkey` (either via a `bunker://` connection string or a NIP-05 login-flow; shown below);
493. Clients use the local keypair to send requests to the remote signer by `p`-tagging and encrypting to the remote user pubkey. 543. _client_ use `client-keypair` to send requests to _remote-signer_ by `p`-tagging and encrypting to `remote-signer-pubkey`;
504. The remote signer responds to the client by `p`-tagging and encrypting to the local keypair pubkey. 554. _remote-signer_ responds to _client_ by `p`-tagging and encrypting to the `client-pubkey`.
51 56
52### Example flow for signing an event 57### Example flow for signing an event
53 58
54- Remote user pubkey (e.g. signing as) `fa984bd7dbb282f07e16e7ae87b26a2a7b9b90b7246a44771f0cf5ae58018f52` 59- `remote-signer-pubkey` is `fa984bd7dbb282f07e16e7ae87b26a2a7b9b90b7246a44771f0cf5ae58018f52`
55- Local pubkey is `eff37350d839ce3707332348af4549a96051bd695d3223af4aabce4993531d86` 60- `user-pubkey` is also `fa984bd7dbb282f07e16e7ae87b26a2a7b9b90b7246a44771f0cf5ae58018f52`
61- `client-pubkey` is `eff37350d839ce3707332348af4549a96051bd695d3223af4aabce4993531d86`
56 62
57#### Signature request 63#### Signature request
58 64
59```json 65```js
60{ 66{
61 "kind": 24133, 67 "kind": 24133,
62 "pubkey": "eff37350d839ce3707332348af4549a96051bd695d3223af4aabce4993531d86", 68 "pubkey": "eff37350d839ce3707332348af4549a96051bd695d3223af4aabce4993531d86",
@@ -70,13 +76,13 @@ nostrconnect://<local-keypair-pubkey>?relay=<wss://relay-to-connect-on>&metadata
70 created_at: 1714078911 76 created_at: 1714078911
71 }>)] 77 }>)]
72 }), 78 }),
73 "tags": [["p", "fa984bd7dbb282f07e16e7ae87b26a2a7b9b90b7246a44771f0cf5ae58018f52"]], // p-tags the remote user pubkey 79 "tags": [["p", "fa984bd7dbb282f07e16e7ae87b26a2a7b9b90b7246a44771f0cf5ae58018f52"]], // p-tags the remote-signer-pubkey
74} 80}
75``` 81```
76 82
77#### Response event 83#### Response event
78 84
79```json 85```js
80{ 86{
81 "kind": 24133, 87 "kind": 24133,
82 "pubkey": "fa984bd7dbb282f07e16e7ae87b26a2a7b9b90b7246a44771f0cf5ae58018f52", 88 "pubkey": "fa984bd7dbb282f07e16e7ae87b26a2a7b9b90b7246a44771f0cf5ae58018f52",
@@ -84,7 +90,7 @@ nostrconnect://<local-keypair-pubkey>?relay=<wss://relay-to-connect-on>&metadata
84 "id": <random_string>, 90 "id": <random_string>,
85 "result": json_stringified(<signed-event>) 91 "result": json_stringified(<signed-event>)
86 }), 92 }),
87 "tags": [["p", "eff37350d839ce3707332348af4549a96051bd695d3223af4aabce4993531d86"]], // p-tags the local keypair pubkey 93 "tags": [["p", "eff37350d839ce3707332348af4549a96051bd695d3223af4aabce4993531d86"]], // p-tags the client-pubkey
88} 94}
89``` 95```
90 96
@@ -94,20 +100,18 @@ nostrconnect://<local-keypair-pubkey>?relay=<wss://relay-to-connect-on>&metadata
94 100
95## Request Events `kind: 24133` 101## Request Events `kind: 24133`
96 102
97```jsonc 103```js
98{ 104{
99 "id": <id>,
100 "kind": 24133, 105 "kind": 24133,
101 "pubkey": <local_keypair_pubkey>, 106 "pubkey": <local_keypair_pubkey>,
102 "content": <nip04(<request>)>, 107 "content": <nip04(<request>)>,
103 "tags": [["p", <remote_user_pubkey>]], // NB: in the `create_account` event, the remote signer pubkey should be `p` tagged. 108 "tags": [["p", <remote-signer-pubkey>]],
104 "created_at": <unix timestamp in seconds>
105} 109}
106``` 110```
107 111
108The `content` field is a JSON-RPC-like message that is [NIP-04](04.md) encrypted and has the following structure: 112The `content` field is a JSON-RPC-like message that is [NIP-04](04.md) encrypted and has the following structure:
109 113
110```json 114```jsonc
111{ 115{
112 "id": <random_string>, 116 "id": <random_string>,
113 "method": <method_name>, 117 "method": <method_name>,
@@ -125,15 +129,16 @@ Each of the following are methods that the client sends to the remote signer.
125 129
126| Command | Params | Result | 130| Command | Params | Result |
127| ------------------------ | ------------------------------------------------- | ---------------------------------------------------------------------- | 131| ------------------------ | ------------------------------------------------- | ---------------------------------------------------------------------- |
128| `connect` | `[<remote_user_pubkey>, <optional_secret>, <optional_requested_permissions>]` | "ack" | 132| `connect` | `[<user_pubkey>, <optional_secret>, <optional_requested_permissions>]` | "ack" |
129| `sign_event` | `[<{kind, content, tags, created_at}>]` | `json_stringified(<signed_event>)` | 133| `sign_event` | `[<{kind, content, tags, created_at}>]` | `json_stringified(<signed_event>)` |
130| `ping` | `[]` | "pong" | 134| `ping` | `[]` | "pong" |
131| `get_relays` | `[]` | `json_stringified({<relay_url>: {read: <boolean>, write: <boolean>}})` | 135| `get_relays` | `[]` | `json_stringified({<relay_url>: {read: <boolean>, write: <boolean>}})` |
132| `get_public_key` | `[]` | `<hex-pubkey>` | 136| `get_public_key` | `[]` | `<user-pubkey>` |
133| `nip04_encrypt` | `[<third_party_pubkey>, <plaintext_to_encrypt>]` | `<nip04_ciphertext>` | 137| `nip04_encrypt` | `[<third_party_pubkey>, <plaintext_to_encrypt>]` | `<nip04_ciphertext>` |
134| `nip04_decrypt` | `[<third_party_pubkey>, <nip04_ciphertext_to_decrypt>]` | `<plaintext>` | 138| `nip04_decrypt` | `[<third_party_pubkey>, <nip04_ciphertext_to_decrypt>]` | `<plaintext>` |
135| `nip44_encrypt` | `[<third_party_pubkey>, <plaintext_to_encrypt>]` | `<nip44_ciphertext>` | 139| `nip44_encrypt` | `[<third_party_pubkey>, <plaintext_to_encrypt>]` | `<nip44_ciphertext>` |
136| `nip44_decrypt` | `[<third_party_pubkey>, <nip44_ciphertext_to_decrypt>]` | `<plaintext>` | 140| `nip44_decrypt` | `[<third_party_pubkey>, <nip44_ciphertext_to_decrypt>]` | `<plaintext>` |
141| `create_account` | `[<username>, <domain>, <optional_email>, <optional_requested_permissions>]` | `<newly_created_user_pubkey>` |
137 142
138### Requested permissions 143### Requested permissions
139 144
@@ -145,9 +150,9 @@ The `connect` method may be provided with `optional_requested_permissions` for u
145{ 150{
146 "id": <id>, 151 "id": <id>,
147 "kind": 24133, 152 "kind": 24133,
148 "pubkey": <remote_signer_pubkey>, 153 "pubkey": <remote-signer-pubkey>,
149 "content": <nip04(<response>)>, 154 "content": <nip04(<response>)>,
150 "tags": [["p", <local_keypair_pubkey>]], 155 "tags": [["p", <client-pubkey>]],
151 "created_at": <unix timestamp in seconds> 156 "created_at": <unix timestamp in seconds>
152} 157}
153``` 158```
@@ -184,18 +189,6 @@ Clients should display (in a popup or new tab) the URL from the `error` field an
184 189
185![signing-example-with-auth-challenge](https://i.nostr.build/W3aj.png) 190![signing-example-with-auth-challenge](https://i.nostr.build/W3aj.png)
186 191
187## Remote Signer Commands
188
189Remote signers might support additional commands when communicating directly with it. These commands follow the same flow as noted above, the only difference is that when the client sends a request event, the `p`-tag is the pubkey of the remote signer itself and the `content` payload is encrypted to the same remote signer pubkey.
190
191### Methods/Commands
192
193Each of the following are methods that the client sends to the remote signer.
194
195| Command | Params | Result |
196| ---------------- | ------------------------------------------ | ------------------------------------ |
197| `create_account` | `[<username>, <domain>, <optional_email>, <optional_requested_permissions>]` | `<newly_created_remote_user_pubkey>` |
198
199## Appendix 192## Appendix
200 193
201### NIP-05 Login Flow 194### NIP-05 Login Flow
@@ -204,7 +197,7 @@ Clients might choose to present a more familiar login flow, so users can type a
204 197
205When the user types a NIP-05 the client: 198When the user types a NIP-05 the client:
206 199
207- Queries the `/.well-known/nostr.json` file from the domain for the NIP-05 address provided to get the user's pubkey (this is the **remote user pubkey**) 200- Queries the `/.well-known/nostr.json` file from the domain for the NIP-05 address provided to get the user's pubkey (this is the `user-pubkey`)
208- In the same `/.well-known/nostr.json` file, queries for the `nip46` key to get the relays that the remote signer will be listening on. 201- In the same `/.well-known/nostr.json` file, queries for the `nip46` key to get the relays that the remote signer will be listening on.
209- Now the client has enough information to send commands to the remote signer on behalf of the user. 202- Now the client has enough information to send commands to the remote signer on behalf of the user.
210 203
@@ -216,9 +209,9 @@ In this last case, most often used to facilitate an OAuth-like signin flow, the
216 209
217First the client will query for `kind: 31990` events that have a `k` tag of `24133`. 210First the client will query for `kind: 31990` events that have a `k` tag of `24133`.
218 211
219These are generally shown to a user, and once the user selects which remote signer to use and provides the remote user pubkey they want to use (via npub, pubkey, or nip-05 value), the client can initiate a connection. Note that it's on the user to select the remote signer that is actually managing the remote key that they would like to use in this case. If the remote user pubkey is managed on another remote signer, the connection will fail. 212These are generally shown to a user, and once the user selects which remote signer to use and provides the `user-pubkey` they want to use (via npub, pubkey, or nip-05 value), the client can initiate a connection. Note that it's on the user to select the _remote-signer_ that is actually managing the `user-keypair` that they would like to use in this case. If the `user-pubkey` is managed on another _remote-signer_ the connection will fail.
220 213
221In addition, it's important that clients validate that the pubkey of the announced remote signer matches the pubkey of the `_` entry in the `/.well-known/nostr.json` file of the remote signer's announced domain. 214In addition, it's important that clients validate that the pubkey of the announced _remote-signer_ matches the pubkey of the `_` entry in the `/.well-known/nostr.json` file of the remote signer's announced domain.
222 215
223Clients that allow users to create new accounts should also consider validating the availability of a given username in the namespace of remote signer's domain by checking the `/.well-known/nostr.json` file for existing usernames. Clients can then show users feedback in the UI before sending a `create_account` event to the remote signer and receiving an error in return. Ideally, remote signers would also respond with understandable error messages if a client tries to create an account with an existing username. 216Clients that allow users to create new accounts should also consider validating the availability of a given username in the namespace of remote signer's domain by checking the `/.well-known/nostr.json` file for existing usernames. Clients can then show users feedback in the UI before sending a `create_account` event to the remote signer and receiving an error in return. Ideally, remote signers would also respond with understandable error messages if a client tries to create an account with an existing username.
224 217