Skip to content

Commit 1f44066

Browse files
committed
Add LNURL-pay username docs
1 parent 27b1298 commit 1f44066

File tree

5 files changed

+102
-94
lines changed

5 files changed

+102
-94
lines changed

src/SUMMARY.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
- [Communicating fees](guide/communicating_fees.md)
2222
- [Using LNURL & Lightning addresses](guide/lnurl.md)
2323
- [Sending payments using LNURL-Pay/Lightning address](guide/lnurl_pay.md)
24-
- [Receiving payments using LNURL-Pay/Lightning address](guide/lnurlpay.md)
24+
- [Receiving payments using LNURL-Pay/Lightning address](guide/lnurl_pay_service.md)
2525
- [Receiving payments using LNURL-Withdraw](guide/lnurl_withdraw.md)
2626
- [Authenticating using LNURL-Auth](guide/lnurl_auth.md)
2727
- [Signing and verifying messages](guide/messages.md)

src/guide/lnurl_pay_service.md

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Receiving payments using LNURL-Pay
2+
3+
Breez SDK - Native *(Greenlight Implementation)* users have the ability to receive Lightning payments using [LNURL-Pay](https://github.com/lnurl/luds/blob/luds/06.md).
4+
5+
LNURL-Pay requires a web service that serves LNURL-Pay requests. This service needs to communicate with the SDK in order to fetch the necessary metadata data and the associated payment request.
6+
To interact with the SDK, the service uses a simple protocol over push notifications:
7+
* The service sends a push notification to the user's mobile app with the LNURL-Pay request and a reply URL.
8+
* The app responds to reply URL with the required data.
9+
* The service forwards the data to the payer.
10+
11+
## General workflow
12+
The following workflow is application specific and the steps detailed below refer to the misty-breez wallet implementation which requires running <b>[breez-lnurl](https://github.com/breez/breez-lnurl) </b>service.
13+
14+
![pay](https://github.com/breez/breez-sdk-docs/assets/5394889/ef0a3111-3604-4789-89c6-23adbd7e5d52)
15+
16+
### Step 1: Registering for an LNURL-Pay service
17+
Use a POST request to the service endpoint ```https://app.domain/lnurlpay/[pubkey]``` with the following payload to register the app for an LNURL-Pay service:
18+
19+
```json
20+
{
21+
"time": 1231006505, // Current UNIX timestamp
22+
"webhook_url": "[notification service webhook URL]",
23+
"username": "[optional username]",
24+
"signature": "[signed message]"
25+
}
26+
```
27+
28+
The `signature` refers to the result of a message signed by the private key of the `pubkey`, where the message is comprised of the following text:
29+
30+
```
31+
[time]-[webhook_url]
32+
```
33+
or, when the optional `username` field is set:
34+
```
35+
[time]-[webhook_url]-[username]
36+
```
37+
where `time`, `webhook_url` and `username` are the payload fields.
38+
39+
The service responds with following payload:
40+
```json
41+
{
42+
"lnurl": "[LNURL-pay encoded endpoint]",
43+
"lightning_address": "username@app.domain" // Only set when username is included
44+
}
45+
```
46+
47+
<div class="warning">
48+
<h4>Developer note</h4>
49+
50+
When a user changes their already registered username, this previous username is freely available to be registered by another user.
51+
52+
</div>
53+
54+
### Step 2: Processing an LNURL-Pay request
55+
When an LNURL-Pay GET request is received at ```https://app.domain/lnurlp/[identifier]``` (or ```https://app.domain/.well-known/lnurlp/[identifier]``` for lightning addresses) the service then sends a push notification to the app with the LNURL-Pay request and a callback URL. The payload may look like the following:
56+
57+
```json
58+
{
59+
"template": "lnurlpay_info",
60+
"data": {
61+
"reply_url": "https://app.domain/respond/[request_id]"
62+
"callback_url": "https://app.domain/lnurlpay/[identifier]/invoice"
63+
}
64+
}
65+
```
66+
67+
The ```reply_url``` is used by the app to respond to the LNURL-Pay request.
68+
The ```callback_url``` is the LNURL-Pay callback URL, used by the payer to fetch the invoice.
69+
70+
### Step 3: Responding to the callback url
71+
When the app receives the push notification, it parses the payload and then uses the ```reply_url``` to respond with the required data, for example:
72+
73+
```json
74+
{
75+
"callback": "https://app.domain/lnurlpay/[identifier]/invoice",
76+
"maxSendable": 10000,
77+
"minSendable": 1000,
78+
"metadata": "[[\"text/plain\",\"Pay to Breez\"]]",
79+
"tag": "payRequest"
80+
}
81+
```
82+
83+
The service receives the response from the app and forwards it to the sender.
84+
85+
### Step 4: Fetching a bolt11 invoice
86+
87+
The sender fetches a bolt11 invoice by invoking a GET request to the ```callback``` URL when a specific amount is added as a query parameter. For example:
88+
```
89+
https://app.domain/lnurlpay/[identifier]/invoice?amount=1000
90+
```
91+
An additional push notification is triggered to send the invoice request to the app. Then the app responds with the bolt11 invoice data.
92+
93+
### Step 5: Paying the invoice
94+
In the last step, the payer pays the received bolt11 invoice. Follow the steps [here](/notifications/getting_started.md) to receive payments via push notifications.
95+
96+
## Reference implementation
97+
For a complete reference implementation, see:
98+
* [Breez's NotificationService](https://github.com/breez/c-breez/blob/main/ios/Breez%20Notification%20Service%20Extension/NotificationService.swift)
99+
* [Breez's LNURL-Pay service](https://github.com/breez/breez-lnurl)

src/guide/lnurlpay.md

-91
This file was deleted.

src/guide/payment_notification.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ The `address_txs_confirmed` notification type will be received by the webhook in
5757

5858
#### Handling LNURL pay requests
5959

60-
Having the ability to process push notifications when the application is in the background or closed also opens up the ability to handle payment requests from a static LNURL address. To do this the application also needs to register a webhook with an [LNURL-pay service](lnurlpay.md), then when the LNURL service receives a request on the static LNURL address, it will forward it via the NDS to the application. The Notification Plugin handles the two-step flow for fulfilling these requests.
60+
Having the ability to process push notifications when the application is in the background or closed also opens up the ability to handle payment requests from a static LNURL address. To do this the application also needs to register a webhook with an [LNURL-pay service](lnurl_pay_service.md), then when the LNURL service receives a request on the static LNURL address, it will forward it via the NDS to the application. The Notification Plugin handles the two-step flow for fulfilling these requests.
6161

6262
Firstly the LNURL service receives a request for LNURL-pay information to get the min/max amount that can be received. The LNURL service calls the registered webhook and when receiving this notification, the Notification Plugin will connect to the Breez SDK and send a response back to the LNURL service based on the node info.
6363

src/notifications/getting_started.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ The `address_txs_confirmed` notification type will be received by the webhook in
5757

5858
#### Handling LNURL pay requests
5959

60-
Having the ability to process push notifications when the application is in the background or closed also opens up the ability to handle payment requests from a static LNURL address. To do this the application also needs to register a webhook with an [LNURL-pay service](/guide/lnurlpay.md), then when the LNURL service receives a request on the static LNURL address, it will forward it via the NDS to the application. The Notification Plugin handles the two-step flow for fulfilling these requests.
60+
Having the ability to process push notifications when the application is in the background or closed also opens up the ability to handle payment requests from a static LNURL address. To do this the application also needs to register a webhook with an [LNURL-pay service](/guide/lnurl_pay_service.md), then when the LNURL service receives a request on the static LNURL address, it will forward it via the NDS to the application. The Notification Plugin handles the two-step flow for fulfilling these requests.
6161

6262
Firstly the LNURL service receives a request for LNURL-pay information to get the min/max amount that can be received. The LNURL service calls the registered webhook and when receiving this notification, the Notification Plugin will connect to the Breez SDK and send a response back to the LNURL service based on the node info.
6363

0 commit comments

Comments
 (0)