2023-02-20 14:26:13 -05:00
NIP-46
======
Nostr Connect
2023-10-18 10:48:18 -04:00
-------------
2023-02-20 14:26:13 -05:00
2023-11-15 19:42:51 -05:00
`draft` `optional`
2023-02-20 14:26:13 -05:00
2023-10-18 10:48:18 -04:00
This NIP describes a method for 2-way communication between a **remote signer** and a normal Nostr client. The remote signer could be, for example, a hardware device dedicated to signing Nostr events, while the client is a normal Nostr client.
2023-02-20 14:26:13 -05:00
2023-10-18 10:48:18 -04:00
## Signer Discovery
2023-02-20 14:26:13 -05:00
2023-10-18 10:48:18 -04:00
The client must somehow be able to contact the signer through a common relay.
2023-02-20 14:26:13 -05:00
2023-10-18 10:48:18 -04:00
### Started by the signer
2023-02-20 14:26:13 -05:00
2023-10-18 10:48:18 -04:00
The remote signer generates a connection token in the form
2023-02-20 14:26:13 -05:00
2023-10-18 10:48:18 -04:00
```
< npub1... > #< secret > ?relay=wss://...& relay=wss://...
```
2023-02-20 14:26:13 -05:00
2023-10-18 10:48:18 -04:00
The user copies that token and pastes it in the client UI somehow. Then the client can send events of kind `24133` to the specified relays and wait for responses from the remote signer.
2023-02-20 14:26:13 -05:00
2023-10-18 10:48:18 -04:00
### Started by the client
2023-02-20 14:26:13 -05:00
2023-10-18 10:48:18 -04:00
The client generates a QR code in the following form (URL-encoded):
2023-02-20 14:26:13 -05:00
2023-10-18 10:48:18 -04:00
```
nostrconnect://< client-key-hex > ?relay=wss://...& metadata={"name":"client-name"}
```
2023-02-20 14:26:13 -05:00
2023-10-18 10:48:18 -04:00
The signer scans the QR code and sends a `connect` message to the client in the specified relays.
2023-02-20 14:26:13 -05:00
2023-10-18 10:48:18 -04:00
## Event payloads
2023-02-20 14:26:13 -05:00
2023-10-18 10:48:18 -04:00
Event payloads are [NIP-04 ](04.md )-encrypted JSON blobs that look like JSONRPC.
2023-02-20 14:26:13 -05:00
2023-10-18 10:48:18 -04:00
Events sent by the client to the remote signer have the following format:
2023-02-20 14:26:13 -05:00
2023-10-18 10:48:18 -04:00
```js
2023-02-20 14:26:13 -05:00
{
2023-10-18 10:48:18 -04:00
"pubkey": "< client-key-hex > "
"kind": 24133,
"tags": [
["p", "< signer-key-hex > "]
],
"content": "nip04_encrypted_json({id: < random-string > , method: < see-below > , params: []})",
...
2023-02-20 14:26:13 -05:00
}
```
2023-10-18 10:48:18 -04:00
And the events the remote signer sends to the client have the following format:
2023-02-20 14:26:13 -05:00
2023-10-18 10:48:18 -04:00
```js
"pubkey": "< signer-key-hex > "
"kind": 24133,
"tags": [
["p", "< client-key-hex > "]
],
"content": "nip04_encrypted_json({id: < request-id > , result: < any > , error: < reason-string > })",
...
2023-02-20 14:26:13 -05:00
```
### Methods
2023-10-18 10:48:18 -04:00
- **connect**
- params: [`pubkey`, `secret` ]
- result: `null`
2023-02-20 14:26:13 -05:00
- **get_public_key**
2023-10-18 10:48:18 -04:00
- params: []
- result: `pubkey`
2023-02-20 14:26:13 -05:00
- **sign_event**
2023-10-18 10:48:18 -04:00
- params: [`event`]
- result: `event_with_pubkey_id_and_signature`
2023-02-20 14:26:13 -05:00
- **get_relays**
2023-10-18 10:48:18 -04:00
- params: []
- result: `{ [url: string]: {read: boolean, write: boolean} }`
2023-02-20 14:26:13 -05:00
- **nip04_encrypt**
2023-10-18 10:48:18 -04:00
- params: [`pubkey`, `plaintext` ]
- result: `nip4 ciphertext`
2023-02-20 14:26:13 -05:00
- **nip04_decrypt**
2023-11-21 18:49:35 -05:00
- params: [`peer-pubkey`, `nip4 ciphertext` ]
2023-10-18 10:48:18 -04:00
- result: [`plaintext`]