upleb.uk

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

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoland <33993199+rolznz@users.noreply.github.com>2025-02-08 03:25:31 +0700
committerGitHub <noreply@github.com>2025-02-07 15:25:31 -0500
commit75f246ed987c23c99d77bfa6aeeb1afb669e23f7 (patch)
tree4b500ae9631507897e29f3323cc4af96b7e3b426
parent0023ca818c759f46cd357a812dca98abfd9824b8 (diff)
docs: clarify NIP-47 key usage (#1756)
-rw-r--r--47.md25
1 files changed, 18 insertions, 7 deletions
diff --git a/47.md b/47.md
index f15dc01..84f710e 100644
--- a/47.md
+++ b/47.md
@@ -1,7 +1,7 @@
1NIP-47 1NIP-47
2====== 2======
3 3
4Nostr Wallet Connect 4Nostr Wallet Connect (NWC)
5-------------------- 5--------------------
6 6
7`draft` `optional` 7`draft` `optional`
@@ -17,6 +17,9 @@ This NIP describes a way for clients to access a remote lightning wallet through
17* **wallet service**: Nostr app that typically runs on an always-on computer (eg. in the cloud or on a Raspberry Pi). This app has access to the APIs of the wallets it serves. 17* **wallet service**: Nostr app that typically runs on an always-on computer (eg. in the cloud or on a Raspberry Pi). This app has access to the APIs of the wallets it serves.
18 18
19## Theory of Operation 19## Theory of Operation
20
21Fundamentally NWC is communication between a **client** and **wallet service** by the means of E2E-encrypted direct messages over a nostr relay. The relay knows the kinds and tags of notes, but not the content of the encrypted payloads. The **user**'s identity key is not used to avoid linking payment activity to the user. Ideally unique keys are used for each individual connection.
22
20 1. **Users** who wish to use this NIP to allow **client(s)** to interact with their wallet must first acquire a special "connection" URI from their NIP-47 compliant wallet application. The wallet application may provide this URI using a QR screen, or a pasteable string, or some other means. 23 1. **Users** who wish to use this NIP to allow **client(s)** to interact with their wallet must first acquire a special "connection" URI from their NIP-47 compliant wallet application. The wallet application may provide this URI using a QR screen, or a pasteable string, or some other means.
21 24
22 2. The **user** should then copy this URI into their **client(s)** by pasting, or scanning the QR, etc. The **client(s)** should save this URI and use it later whenever the **user** (or the **client** on the user's behalf) wants to interact with the wallet. The **client** should then request an `info` (13194) event from the relay(s) specified in the URI. The **wallet service** will have sent that event to those relays earlier, and the relays will hold it as a replaceable event. 25 2. The **user** should then copy this URI into their **client(s)** by pasting, or scanning the QR, etc. The **client(s)** should save this URI and use it later whenever the **user** (or the **client** on the user's behalf) wants to interact with the wallet. The **client** should then request an `info` (13194) event from the relay(s) specified in the URI. The **wallet service** will have sent that event to those relays earlier, and the relays will hold it as a replaceable event.
@@ -45,7 +48,7 @@ If the **wallet service** supports notifications, the info event SHOULD contain
45 48
46### Request and Response Events 49### Request and Response Events
47 50
48Both the request and response events SHOULD contain one `p` tag, containing the public key of the **wallet service** if this is a request, and the public key of the **user** if this is a response. The response event SHOULD contain an `e` tag with the id of the request event it is responding to. 51Both the request and response events SHOULD contain one `p` tag, containing the public key of the **wallet service** if this is a request, and the public key of the **client** if this is a response. The response event SHOULD contain an `e` tag with the id of the request event it is responding to.
49Optionally, a request can have an `expiration` tag that has a unix timestamp in seconds. If the request is received after this timestamp, it should be ignored. 52Optionally, a request can have an `expiration` tag that has a unix timestamp in seconds. If the request is received after this timestamp, it should be ignored.
50 53
51The content of requests and responses is encrypted with [NIP04](04.md), and is a JSON-RPCish object with a semi-fixed structure: 54The content of requests and responses is encrypted with [NIP04](04.md), and is a JSON-RPCish object with a semi-fixed structure:
@@ -80,7 +83,7 @@ If the command was successful, the `error` field must be null.
80 83
81### Notification Events 84### Notification Events
82 85
83The notification event SHOULD contain one `p` tag, the public key of the **user**. 86The notification event SHOULD contain one `p` tag, the public key of the **client**.
84 87
85The content of notifications is encrypted with [NIP04](04.md), and is a JSON-RPCish object with a semi-fixed structure: 88The content of notifications is encrypted with [NIP04](04.md), and is a JSON-RPCish object with a semi-fixed structure:
86 89
@@ -105,19 +108,27 @@ The content of notifications is encrypted with [NIP04](04.md), and is a JSON-RPC
105- `OTHER`: Other error. 108- `OTHER`: Other error.
106 109
107## Nostr Wallet Connect URI 110## Nostr Wallet Connect URI
108**client** discovers **wallet service** by scanning a QR code, handling a deeplink or pasting in a URI.
109 111
110The **wallet service** generates this connection URI with protocol `nostr+walletconnect://` and base path its hex-encoded `pubkey` with the following query string parameters: 112Communication between the **client** and **wallet service** requires two keys in order to encrypt and decrypt messages. The connection URI includes the secret key of the **client** and only the public key of the **wallet service**.
113
114The **client** discovers **wallet service** by scanning a QR code, handling a deeplink or pasting in a URI.
115
116The **wallet service** generates this connection URI with protocol `nostr+walletconnect://` and base path its 32-byte hex-encoded `pubkey`, which SHOULD be unique per client connection.
117
118The connection URI contains the following query string parameters:
111 119
112- `relay` Required. URL of the relay where the **wallet service** is connected and will be listening for events. May be more than one. 120- `relay` Required. URL of the relay where the **wallet service** is connected and will be listening for events. May be more than one.
113- `secret` Required. 32-byte randomly generated hex encoded string. The **client** MUST use this to sign events and encrypt payloads when communicating with the **wallet service**. 121- `secret` Required. 32-byte randomly generated hex encoded string. The **client** MUST use this to sign events and encrypt payloads when communicating with the **wallet service**. The **wallet service** MUST use the corresponding public key of this secret to communicate with the **client**.
114 - Authorization does not require passing keys back and forth. 122 - Authorization does not require passing keys back and forth.
115 - The user can have different keys for different applications. Keys can be revoked and created at will and have arbitrary constraints (eg. budgets). 123 - The user can have different keys for different applications. Keys can be revoked and created at will and have arbitrary constraints (eg. budgets).
116 - The key is harder to leak since it is not shown to the user and backed up. 124 - The key is harder to leak since it is not shown to the user and backed up.
117 - It improves privacy because the user's main key would not be linked to their payments. 125 - It improves privacy because the user's main key would not be linked to their payments.
118- `lud16` Recommended. A lightning address that clients can use to automatically setup the `lud16` field on the user's profile if they have none configured. 126- `lud16` Recommended. A lightning address that clients can use to automatically setup the `lud16` field on the user's profile if they have none configured.
119 127
120The **client** should then store this connection and use it when the user wants to perform actions like paying an invoice. Due to this NIP using ephemeral events, it is recommended to pick relays that do not close connections on inactivity to not drop events. 128The **client** should then store this connection and use it when the user wants to perform actions like paying an invoice. Due to this NIP using ephemeral events, it is recommended to pick relays that do not close connections on inactivity to not drop events, and ideally retain the events until they are either consumed or become stale.
129
130- When the **client** sends or receives a message it will use the `secret` from the connection URI and **wallet service**'s `pubkey` to encrypt or decrypt.
131- When the **wallet service** sends or receives a message it will use its own secret and the corresponding pubkey of the **client's** `secret` to encrypt or decrypt. The **wallet service** SHOULD NOT store the secret it generates for the client and MUST NOT rely on the knowing the **client** secret for general operation.
121 132
122### Example connection string 133### Example connection string
123```sh 134```sh