diff options
| author | Pablo Fernandez <p@f7z.io> | 2023-06-08 22:32:17 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-08 22:32:17 +0200 |
| commit | 6baacf6fb1badf3ba2480a88519e357b3cbdaaac (patch) | |
| tree | b3d211bc3683b340d678c3574519f327e7b3858e /47.md | |
| parent | 964bc5b5ce946ab66aae945084549f26ffdef70f (diff) | |
| parent | 14a887d43b654f41de5d271e27ef69048f183fb4 (diff) | |
Merge branch 'master' into nip31
Diffstat (limited to '47.md')
| -rw-r--r-- | 47.md | 20 |
1 files changed, 16 insertions, 4 deletions
| @@ -12,8 +12,18 @@ This NIP describes a way for clients to access a remote Lightning wallet through | |||
| 12 | 12 | ||
| 13 | ## Terms | 13 | ## Terms |
| 14 | 14 | ||
| 15 | * **client**: Nostr app on any platform that wants to pay Lightning invoices | 15 | * **client**: Nostr app on any platform that wants to pay Lightning invoices. |
| 16 | * **wallet service**: Nostr app that typically runs on an always-on computer (eg. in the cloud or on a Raspberry Pi). | 16 | * **user**: The person using the **client**, and want's to connect their wallet app to their **client**. |
| 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 | |||
| 19 | ## Theory of Operation | ||
| 20 | 1. **Users** who which to use this NIP to send lightning payments to other nostr users 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 | |||
| 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** makes a payment. 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. | ||
| 23 | |||
| 24 | 3. When the **user** initiates a payment their nostr **client** create a `pay_invoice` request, encrypts it using a token from the URI, and sends it (kind 23194) to the relay(s) specified in the connection URI. The **wallet service** will be listening on those relays and will decrypt the request and then contact the **user's** wallet application to send the payment. The **wallet service** will know how to talk to the wallet application because the connection URI specified relay(s) that have access to the wallet app API. | ||
| 25 | |||
| 26 | 4. Once the payment is complete the **wallet service** will send an encrypted `response` (kind 23195) to the **user** over the relay(s) in the URI. | ||
| 17 | 27 | ||
| 18 | ## Events | 28 | ## Events |
| 19 | 29 | ||
| @@ -24,7 +34,8 @@ There are three event kinds: | |||
| 24 | 34 | ||
| 25 | The info event should be a replaceable event that is published by the **wallet service** on the relay to indicate which commands it supports. The content should be | 35 | The info event should be a replaceable event that is published by the **wallet service** on the relay to indicate which commands it supports. The content should be |
| 26 | a plaintext string with the supported commands, space-seperated, eg. `pay_invoice get_balance`. Only the `pay_invoice` command is described in this NIP, but other commands might be defined in different NIPs. | 36 | a plaintext string with the supported commands, space-seperated, eg. `pay_invoice get_balance`. Only the `pay_invoice` command is described in this NIP, but other commands might be defined in different NIPs. |
| 27 | Both 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. | 37 | |
| 38 | Both 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. | ||
| 28 | 39 | ||
| 29 | The content of requests and responses is encrypted with [NIP04](https://github.com/nostr-protocol/nips/blob/master/04.md), and is a JSON-RPCish object with a semi-fixed structure: | 40 | The content of requests and responses is encrypted with [NIP04](https://github.com/nostr-protocol/nips/blob/master/04.md), and is a JSON-RPCish object with a semi-fixed structure: |
| 30 | 41 | ||
| @@ -77,6 +88,7 @@ The **wallet service** generates this connection URI with protocol `nostr+wallet | |||
| 77 | - The user can have different keys for different applications. Keys can be revoked and created at will and have arbitrary constraints (eg. budgets). | 88 | - The user can have different keys for different applications. Keys can be revoked and created at will and have arbitrary constraints (eg. budgets). |
| 78 | - The key is harder to leak since it is not shown to the user and backed up. | 89 | - The key is harder to leak since it is not shown to the user and backed up. |
| 79 | - It improves privacy because the user's main key would not be linked to their payments. | 90 | - It improves privacy because the user's main key would not be linked to their payments. |
| 91 | - `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. | ||
| 80 | 92 | ||
| 81 | The **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. | 93 | The **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. |
| 82 | 94 | ||
| @@ -117,7 +129,7 @@ Errors: | |||
| 117 | ## Example pay invoice flow | 129 | ## Example pay invoice flow |
| 118 | 130 | ||
| 119 | 0. The user scans the QR code generated by the **wallet service** with their **client** application, they follow a `nostr+walletconnect:` deeplink or configure the connection details manually. | 131 | 0. The user scans the QR code generated by the **wallet service** with their **client** application, they follow a `nostr+walletconnect:` deeplink or configure the connection details manually. |
| 120 | 1. **client** sends an event to with **wallet service** service with kind `23194`. The content is a `pay_invoice` request. The private key is the secret from the connection string above. | 132 | 1. **client** sends an event to the **wallet service** service with kind `23194`. The content is a `pay_invoice` request. The private key is the secret from the connection string above. |
| 121 | 2. **wallet service** verifies that the author's key is authorized to perform the payment, decrypts the payload and sends the payment. | 133 | 2. **wallet service** verifies that the author's key is authorized to perform the payment, decrypts the payload and sends the payment. |
| 122 | 3. **wallet service** responds to the event by sending an event with kind `23195` and content being a response either containing an error message or a preimage. | 134 | 3. **wallet service** responds to the event by sending an event with kind `23195` and content being a response either containing an error message or a preimage. |
| 123 | 135 | ||