Skip to content

Commit edc93aa

Browse files
Support async payments in BOLT 12.
This builds on prior commits by adding the ability to fetch an invoice from an always-online node on behalf of an often-offline recipient, e.g. a mobile node. The idea is that often-offline recipients will supply some always-online node such as their wallet vendor with a static (i.e. `payment_hash`-less) invoice to return on its behalf. The recipient will then publish an offer containing blinded paths that terminate at this always-online node, who payers can request the invoice from if the recipient is offline at the time. After receiving the static invoice, payers will commence the protocol outlined in [1] to send the HTLC asynchronously. [1]: https://lists.linuxfoundation.org/pipermail/lightning-dev/2021-October/003307.html
1 parent eb30b0b commit edc93aa

File tree

3 files changed

+93
-19
lines changed

3 files changed

+93
-19
lines changed

04-onion-routing.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ This is formatted according to the Type-Length-Value format defined in [BOLT #1]
213213
1. type: 18 (`total_amount_msat`)
214214
2. data:
215215
* [`tu64`:`total_msat`]
216+
1. type: 5482373484 (`sender_provided_payment_preimage`)
217+
2. data:
218+
* [`32*byte`:`payment_preimage`]
216219

217220
`short_channel_id` is the ID of the outgoing channel used to route the
218221
message; the receiving peer should operate the other end of this channel.
@@ -239,6 +242,9 @@ The requirements ensure consistency in responding to an unexpected
239242
`outgoing_cltv_value`, whether it is the final node or not, to avoid
240243
leaking its position in the route.
241244

245+
`sender_provided_payment_preimage` is set in the case that the recipient is
246+
often-offline and another node provided a static BOLT 12 invoice on their behalf.
247+
242248
### Requirements
243249

244250
The creator of `encrypted_recipient_data` (usually, the recipient of payment):
@@ -269,6 +275,12 @@ The writer of the TLV `payload`:
269275
- MUST use the current block height as a baseline value.
270276
- if a [random offset](07-routing-gossip.md#recommendations-for-routing) was added to improve privacy:
271277
- SHOULD add the offset to the baseline value.
278+
- if paying to a static BOLT 12 invoice:
279+
- MUST set `sender_provided_payment_preimage` to randomly generated unique bytes.
280+
- MUST set `update_add_htlc.payment_hash` to match the SHA256 hash of
281+
`sender_provided_payment_preimage`.
282+
- otherwise:
283+
- MUST NOT set `sender_provided_payment_preimage`.
272284
- MUST NOT include any other tlv field.
273285
- For every node outside of a blinded route:
274286
- MUST include `amt_to_forward` and `outgoing_cltv_value`.
@@ -319,6 +331,7 @@ The reader:
319331
- MUST return an error if `amt_to_forward` is below what it expects for the payment.
320332
- MUST return an error if incoming `cltv_expiry` < `outgoing_cltv_value`.
321333
- MUST return an error if incoming `cltv_expiry` < `current_block_height` + `min_final_cltv_expiry_delta`.
334+
- MUST use `sender_provided_payment_preimage` when claiming the HTLC, if present
322335
- Otherwise (it is not part of a blinded route):
323336
- MUST return an error if `blinding_point` is set in the incoming `update_add_htlc` or `current_blinding_point` is present.
324337
- MUST return an error if `amt_to_forward` or `outgoing_cltv_value` are not present.

09-features.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ The Context column decodes as follows:
2727
* `C+`: presented in the `channel_announcement` message, but always even (required).
2828
* `9`: presented in [BOLT 11](11-payment-encoding.md) invoices.
2929
* `B`: presented in the `allowed_features` field of a blinded path.
30+
* `R`: presented in [BOLT 12](12-offers.md) invoice requests.
3031

3132
| Bits | Name | Description | Context | Dependencies | Link |
3233
|-------|-----------------------------------|-----------------------------------------------------------|----------|---------------------------|-----------------------------------------------------------------------|
@@ -51,11 +52,17 @@ The Context column decodes as follows:
5152
| 48/49 | `option_payment_metadata` | Payment metadata in tlv record | 9 | | [BOLT #11](11-payment-encoding.md#tagged-fields) |
5253
| 50/51 | `option_zeroconf` | Understands zeroconf channel types | IN | `option_scid_alias` | [BOLT #2][bolt02-channel-ready] |
5354
| 52/53 | `option_htlc_hold` | Hold HTLCs and forward on receipt of an onion message | IN | `option_onion_messages` |
55+
| 56/57 | `option_om_mailbox` | Store-and-forward onion messages for often-offline peers | IN | `option_onion_messages` | [BOLT #12](bolt12-offers.md) |
56+
| 59 | `static_invoice_pay` | Supports paying BOLT 12 static invoices | R | `option_onion_messages` | [BOLT #12](bolt12-offers.md) |
5457

5558
## Definitions
5659

5760
We define `option_anchors` as `option_anchor_outputs || option_anchors_zero_fee_htlc_tx`.
5861

62+
We define `option_om_mailbox` as the ability to store an onion message on behalf
63+
of an offline peer, and forward it once the peer comes online (subject to rate
64+
limiting).
65+
5966
## Requirements
6067

6168
The origin node:

12-offer-encoding.md

Lines changed: 73 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Here we use "user" as shorthand for the individual user's lightning
4242
node and "merchant" as the shorthand for the node of someone who is
4343
selling or has sold something.
4444

45-
There are two basic payment flows supported by BOLT 12:
45+
There are three basic payment flows supported by BOLT 12:
4646

4747
The general user-pays-merchant flow is:
4848
1. A merchant publishes an *offer*, such as on a web page or a QR code.
@@ -59,6 +59,19 @@ The merchant-pays-user flow (e.g. ATM or refund):
5959
3. The merchant confirms the *invoice_node_id* to ensure it's about to pay the correct
6060
person, and makes a payment to the invoice.
6161

62+
The pay-mobile-user flow (e.g. paying a friend back to their mobile node):
63+
1. The mobile user supplies some always-online node with a static (i.e.
64+
`payment_hash`-less) invoice to return on its behalf. This always-online node may
65+
be the mobile user's channel counterparty, wallet vendor, or another node on the
66+
network that it has an out-of-band relationship with.
67+
2. The mobile user publishes an offer that contains blinded paths that terminate
68+
at the always-online node.
69+
3. The payer sends an `invoice_request` to the always-online node, who replies
70+
with the static invoice previously provided by the mobile user if the mobile user
71+
is offline. If they are online, the `invoice_request` is forwarded to the mobile
72+
user as usual.
73+
4. The payer makes a payment to the mobile user as indicated by the invoice.
74+
6275
## Payment Proofs and Payer Proofs
6376

6477
Note that the normal lightning "proof of payment" can only demonstrate that an
@@ -71,6 +84,9 @@ to request the invoice. In addition, the Merkle construction of the BOLT 12
7184
invoice signature allows the user to reveal invoice fields in case
7285
of a dispute selectively.
7386

87+
Payers will not get proofs in the case that they received a static invoice from the
88+
payee, see the pay-mobile-user flow above.
89+
7490
# Encoding
7591

7692
Each of the forms documented here are in
@@ -255,8 +271,9 @@ A writer of an offer:
255271
after midnight 1 January 1970, UTC that invoice_request should not be
256272
attempted.
257273
- if it is connected only by private channels:
258-
- MUST include `offer_paths` containing one or more paths to the node from
259-
publicly reachable nodes.
274+
- MUST include `offer_paths` containing one or more paths to the node
275+
that will reply to the `invoice_request`, using introduction nodes that are
276+
publicly reachable.
260277
- otherwise:
261278
- MAY include `offer_paths`.
262279
- if it includes `offer_paths`:
@@ -274,6 +291,8 @@ A writer of an offer:
274291
- MUST set `offer_quantity_max` to 0.
275292
- otherwise:
276293
- MUST NOT set `offer_quantity_max`.
294+
- if it is often-offline and the invoice may be provided by another node on their behalf:
295+
- MUST NOT include more than 1 chain in `offer_chains`.
277296

278297
A reader of an offer:
279298
- if the offer contains any TLV fields greater or equal to 80:
@@ -409,6 +428,20 @@ for [Signature Calculation](#signature-calculation).
409428
2. data:
410429
* [`bip340sig`:`sig`]
411430

431+
## Invoice Request Features
432+
433+
| Bits | Description | Name |
434+
|------|----------------------------------|-----------------------------|
435+
| 59 | Supports paying static invoices | static_invoice_pay/optional |
436+
437+
Setting `static_invoice_pay` indicates that the payer supports receiving a
438+
`payment_hash`-less invoice in response to their `invoice_request`, and
439+
subsequently setting `sender_provided_payment_preimage` in their payment onion.
440+
441+
Useful if the payee is often offline and the invoice is being returned on
442+
their behalf by another node, to avoid trusting that other node to not reuse a
443+
`payment_hash`.
444+
412445
## Requirements for Invoice Requests
413446

414447
The writer:
@@ -486,7 +519,14 @@ The reader:
486519
- MUST fail the request if bitcoin is not a supported chain.
487520
- otherwise:
488521
- MUST fail the request if `invreq_chain`.`chain` is not a supported chain.
489-
522+
- if receiving the `invoice_request` on behalf of an often-offline payee:
523+
- if the payee is online:
524+
- MUST forward the `invoice_request` to the payee
525+
- otherwise (payee is offline):
526+
- if `invreq_features` supports `static_invoice_pay`:
527+
- MUST reply with the static invoice previously provided by the payee
528+
- otherwise:
529+
- MUST reply with `invoice_error`
490530

491531
## Rationale
492532

@@ -515,10 +555,11 @@ informative for the payer to know how the sender claims
515555

516556
# Invoices
517557

518-
Invoices are a payment request, and when the payment is made,
519-
it can be combined with the invoice to form a cryptographic receipt.
558+
Invoices are a payment request. If `invoice_payment_hash` is set, then when the
559+
payment is made, the payment preimage can be combined with the invoice to form a
560+
cryptographic receipt.
520561

521-
The recipient sends an `invoice` in response to an `invoice_request` using
562+
The recipient creates an `invoice` for responding to an `invoice_request` using
522563
the `onion_message` `invoice` field.
523564

524565
1. `tlv_stream`: `invoice`
@@ -604,6 +645,9 @@ the `onion_message` `invoice` field.
604645
1. type: 176 (`invoice_node_id`)
605646
2. data:
606647
* [`point`:`node_id`]
648+
1. type: 178 (`invoice_message_paths`)
649+
2. data:
650+
* [`...*blinded_path`:`paths`]
607651
1. type: 240 (`signature`)
608652
2. data:
609653
* [`bip340sig`:`sig`]
@@ -642,21 +686,25 @@ may (due to capacity limits on a single channel) require it.
642686
A writer of an invoice:
643687
- MUST set `invoice_created_at` to the number of seconds since Midnight 1
644688
January 1970, UTC when the invoice was created.
645-
- MUST set `invoice_amount` to the minimum amount it will accept, in units of
646-
the minimal lightning-payable unit (e.g. milli-satoshis for bitcoin) for
647-
`invreq_chain`.
648-
- if the invoice is in response to an `invoice_request`:
689+
- if `invoice_payment_hash` is set and the invoice is in response to an `invoice_request`:
649690
- MUST copy all non-signature fields from the `invoice_request` (including unknown fields).
650691
- if `invreq_amount` is present:
651692
- MUST set `invoice_amount` to `invreq_amount`
652693
- otherwise:
653694
- MUST set `invoice_amount` to the *expected amount*.
654-
- otherwise (invoice not requested, e.g. for user to scan directly):
695+
- otherwise if the invoice was not requested (e.g. for user to scan directly):
655696
- MUST set `invreq_chain` as it would for an invoice_request.
656697
- MUST set `offer_description` as it would for an offer.
657698
- MUST NOT set `invreq_payer_id` or `offer_node_id`.
658-
- MUST set `invoice_payment_hash` to the SHA256 hash of the
659-
`payment_preimage` that will be given in return for payment.
699+
- if the invoice is intended to be provided by a node other than the recipient:
700+
- MUST NOT set `invoice_payment_hash`.
701+
- MUST NOT set `invoice_amount`.
702+
- MUST include `invoice_message_paths` containing at least two paths to
703+
the recipient, where the penultimate hop supports `option_om_mailbox`.
704+
- MUST NOT set any `invoice_request` TLV fields (i.e. 0 or in the 80-159 range)
705+
- otherwise:
706+
- MUST set `invoice_payment_hash` to the SHA256 hash of the
707+
`payment_preimage` that will be given in return for payment.
660708
- if `offer_node_id` is present:
661709
- MUST set `invoice_node_id` to `offer_node_id`.
662710
- otherwise:
@@ -682,15 +730,16 @@ A writer of an invoice:
682730
- MUST include `invoice_blindedpay` with exactly one `blinded_payinfo` for each `blinded_path` in `paths`, in order.
683731
- MUST set `features` in each `blinded_payinfo` to match `encrypted_data_tlv`.`allowed_features` (or empty, if no `allowed_features`).
684732
- SHOULD ignore any payment which does not use one of the paths.
685-
- if `offer_node_id` is present, and `invreq_payer_id` is identical to a previous `invoice_request`:
686-
- MAY simply reuse the previous invoice.
733+
- if `offer_node_id` is present, and `invreq_payer_id` is identical to a previous `invoice_request`, or if providing invoices on behalf of an often offline recipient:
734+
- MAY reuse the previous invoice.
687735
- otherwise:
688736
- MUST NOT reuse a previous invoice.
689737

690738
A reader of an invoice:
691-
- MUST reject the invoice if `invoice_amount` is not present.
692739
- MUST reject the invoice if `invoice_created_at` is not present.
693-
- MUST reject the invoice if `invoice_payment_hash` is not present.
740+
- if `static_invoice_pay` was not supported in `invreq_features`:
741+
- MUST reject the invoice if `invoice_payment_hash` is not present.
742+
- MUST reject the invoice if `invoice_amount` is not present.
694743
- MUST reject the invoice if `invoice_node_id` is not present.
695744
- if `invoice_features` contains unknown _odd_ bits that are non-zero:
696745
- MUST ignore the bit.
@@ -707,7 +756,8 @@ A reader of an invoice:
707756
- MUST NOT use the corresponding `invoice_paths`.`path` if `payinfo`.`features` has any unknown even bits set.
708757
- MUST reject the invoice if this leaves no usable paths.
709758
- if the invoice is a response to an `invoice_request`:
710-
- MUST reject the invoice if all fields less than type 160 do not exactly match the `invoice_request`.
759+
- if `invoice_payment_hash` is set:
760+
- MUST reject the invoice if all fields less than type 160 do not exactly match the `invoice_request`.
711761
- if `offer_node_id` is present (invoice_request for an offer):
712762
- MUST reject the invoice if `invoice_node_id` is not equal to `offer_node_id`.
713763
- otherwise (invoice_request without an offer):
@@ -727,6 +777,10 @@ A reader of an invoice:
727777
- MUST ignore any `fallback_address` for which `version` is greater than 16.
728778
- MUST ignore any `fallback_address` for which `address` is less than 2 or greater than 40 bytes.
729779
- MUST ignore any `fallback_address` for which `address` does not meet known requirements for the given `version`
780+
- if `invoice_payment_hash` is unset:
781+
- MUST reject the invoice if `invoice_message_paths` is not present or is empty.
782+
- MUST pay asynchronously using the `held_htlc_available` onion message
783+
flow, where the onion message is sent over `invoice_message_paths`.
730784

731785
## Rationale
732786

0 commit comments

Comments
 (0)