upleb.uk

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

summaryrefslogtreecommitdiff
path: root/46.md
blob: 6610e82c93bed72e90da8f653ab244a9ab5ec905 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
NIP-46
======

Nostr Connect
-------------

`draft` `optional`

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.

## Signer Discovery

The client must somehow be able to contact the signer through a common relay.

### Started by the signer

The remote signer generates a connection token in the form

```
<npub1...>#<secret>?relay=wss://...&relay=wss://...
```

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.

### Started by the client

The client generates a QR code in the following form (URL-encoded):

```
nostrconnect://<client-key-hex>?relay=wss://...&metadata={"name":"client-name"}
```

The signer scans the QR code and sends a `connect` message to the client in the specified relays.

## Event payloads

Event payloads are [NIP-04](04.md)-encrypted JSON blobs that look like JSONRPC.

Events sent by the client to the remote signer have the following format:

```js
{
  "pubkey": "<client-key-hex>"
  "kind": 24133,
  "tags": [
    ["p", "<signer-key-hex>"]
  ],
  "content": "nip04_encrypted_json({id: <random-string>, method: <see-below>, params: []})",
  ...
}
```

And the events the remote signer sends to the client have the following format:

```js
  "pubkey": "<signer-key-hex>"
  "kind": 24133,
  "tags": [
    ["p", "<client-key-hex>"]
  ],
  "content": "nip04_encrypted_json({id: <request-id>, result: <any>, error: <reason-string>})",
  ...
```

### Methods

- **connect**
  - params: [`pubkey`, `secret`]
  - result: `null`
- **get_public_key**
  - params: []
  - result: `pubkey`
- **sign_event**
  - params: [`event`]
  - result: `event_with_pubkey_id_and_signature`
- **get_relays**
  - params: []
  - result: `{ [url: string]: {read: boolean, write: boolean} }`
- **nip04_encrypt**
  - params: [`peer-pubkey`, `plaintext`]
  - result: `nip4 ciphertext`
- **nip04_decrypt**
  - params: [`peer-pubkey`, `nip4 ciphertext`]
  - result: [`plaintext`]