Skip to content

Commit bf944a4

Browse files
committed
Add payment metadata to payment request
1 parent 886c8f0 commit bf944a4

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

04-onion-routing.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ It is formatted according to the Type-Length-Value format defined in [BOLT #1](0
263263
2. data:
264264
* [`32*byte`:`payment_secret`]
265265
* [`tu64`:`total_msat`]
266+
1. type: 16 (`payment_metadata`)
267+
2. data:
268+
* [`...*byte`:`payment_metadata`]
266269

267270
### Requirements
268271

@@ -280,6 +283,9 @@ The writer:
280283
- MUST include `payment_data`
281284
- MUST set `payment_secret` to the one provided
282285
- MUST set `total_msat` to the total amount it will send
286+
- if the recipient provided `payment_metadata`:
287+
- MUST include `payment_metadata`
288+
- MUST not apply an arbitrary limit to the size of `payment_metadata`.
283289

284290
The reader:
285291
- MUST return an error if `amt_to_forward` or `outgoing_cltv_value` are not present.
@@ -948,9 +954,9 @@ handling by the processing node.
948954
* [`u32`:`height`]
949955

950956
The `payment_hash` is unknown to the final node, the `payment_secret` doesn't
951-
match the `payment_hash`, the amount for that `payment_hash` is incorrect or
957+
match the `payment_hash`, the amount for that `payment_hash` is incorrect,
952958
the CLTV expiry of the htlc is too close to the current block height for safe
953-
handling.
959+
handling or `payment_metadata` isn't present while it should.
954960

955961
The `htlc_msat` parameter is superfluous, but left in for backwards
956962
compatibility. The value of `htlc_msat` always matches the amount specified in

09-features.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ The Context column decodes as follows:
4242
| 22/23 | `option_anchors_zero_fee_htlc_tx` | Anchor commitment type with zero fee HTLC transactions | IN | | [BOLT #3][bolt03-htlc-tx], [lightning-dev][ml-sighash-single-harmful]|
4343
| 26/27 | `option_shutdown_anysegwit` | Future segwit versions allowed in `shutdown` | IN | | [BOLT #2][bolt02-shutdown] |
4444
| 44/45 | `option_channel_type` | Node supports the `channel_type` field in open/accept | IN | | [BOLT #2](02-peer-protocol.md#the-open_channel-message) |
45+
| 48/49 | `option_payment_metadata` | Payment metadata in tlv record | 9 | | [BOLT #11](11-payment-encoding.md#tagged-fields)
4546

4647
## Definitions
4748

11-payment-encoding.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ Currently defined tagged fields are:
140140
* `p` (1): `data_length` 52. 256-bit SHA256 payment_hash. Preimage of this provides proof of payment.
141141
* `s` (16): `data_length` 52. This 256-bit secret prevents forwarding nodes from probing the payment recipient.
142142
* `d` (13): `data_length` variable. Short description of purpose of payment (UTF-8), e.g. '1 cup of coffee' or 'ナンセンス 1杯'
143+
* `m` (27): `data_length` variable. Additional metadata to attach to the
144+
payment. Note that the size of this field is limited by the maximum hop payload size. Long metadata fields reduce the maximum route length.
143145
* `n` (19): `data_length` 53. 33-byte public key of the payee node
144146
* `h` (23): `data_length` 52. 256-bit description of purpose of payment (SHA256). This is used to commit to an associated description that is over 639 bytes, but the transport mechanism for the description in that case is transport specific and not defined here.
145147
* `x` (6): `data_length` variable. `expiry` time in seconds (big-endian). Default is 3600 (1 hour) if not specified.
@@ -216,7 +218,8 @@ A reader:
216218
- MUST use that as [`payment_secret`](04-onion-routing.md#tlv_payload-payload-format)
217219
- if the `c` field (`min_final_cltv_expiry`) is not provided:
218220
- MUST use an expiry delta of at least 18 when making the payment
219-
221+
- if an `m` field is provided:
222+
- MUST use that as [`payment_metadata`](04-onion-routing.md#tlv_payload-payload-format)
220223
### Rationale
221224

222225
The type-and-length format allows future extensions to be backward
@@ -235,6 +238,9 @@ by which the description is served is as-yet unspecified and will
235238
probably be transport dependent. The `h` format could change in the future,
236239
by changing the length, so readers ignore it if it's not 256 bits.
237240

241+
The `m` field allows metadata to be attached to the payment. This supports
242+
applications where the recipient doesn't keep any context for the payment.
243+
238244
The `n` field can be used to explicitly specify the destination node ID,
239245
instead of requiring signature recovery.
240246

@@ -704,6 +710,36 @@ Breakdown:
704710
* `z599y53s3ujmcfjp5xrdap68qxymkqphwsexhmhr8wdz5usdzkzrse33chw6dlp3jhuhge9ley7j2ayx36kawe7kmgg8sv5ugdyusdcq`: signature
705711
* `zn8z9x`: Bech32 checksum
706712

713+
> ### Please send 0.01 BTC with payment metadata 0x01fafaf0
714+
> lnbc10m1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdp9wpshjmt9de6zqmt9w3skgct5vysxjmnnd9jx2mq8q8a04uqnp4q0n326hr8v9zprg8gsvezcch06gfaqqhde2aj730yg0durunfhv66sp5zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zygs9q2gqqqqqqsgqy9gw6ymamd20jumvdgpfphkhp8fzhhdhycw36egcmla5vlrtrmhs9t7psfy3hkkdqzm9eq64fjg558znccds5nhsfmxveha5xe0dykgpspdha0
715+
716+
Breakdown:
717+
718+
* `lnbc`: prefix, Lightning on Bitcoin mainnet
719+
* `10m`: amount (10 milli-bitcoin)
720+
* `1`: Bech32 separator
721+
* `pvjluez`: timestamp (1496314658)
722+
* `p`: payment hash
723+
* `p5`: `data_length` (`p` = 1, `5` = 20; 1 * 32 + 20 == 52)
724+
* `qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypq`: payment hash 0001020304050607080900010203040506070809000102030405060708090102
725+
* `d`: short description
726+
* `p9`: `data_length` (`p` = 1, `9` = 5; 1 * 32 + 5 == 37)
727+
* `wpshjmt9de6zqmt9w3skgct5vysxjmnnd9jx2`: 'payment metadata inside'
728+
* `m`: metadata
729+
* `q8`: `data_length` (`q` = 0, `8` = 7; 0 * 32 + 7 == 7)
730+
* `q8a04uq`: 0x01fafaf0
731+
* `n`: node id
732+
* `p4`: `data_length` (`p` = 1, `4` = 21; 1 * 32 + 21 == 53)
733+
* `q0n326hr8v9zprg8gsvezcch06gfaqqhde2aj730yg0durunfhv66`
734+
* `s`: payment secret
735+
* `p5`: `data_length` (`p` = 1, `5` = 20; 1 * 32 + 20 == 52)
736+
* `zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zyg3zygs`: 0x1111111111111111111111111111111111111111111111111111111111111111
737+
* `9`: features
738+
* `q2`: `data_length` (`q` = 0, `2` = 10; 0 * 32 + 10 == 10)
739+
* `gqqqqqqsgq`: [b01000000000000000000000000000000000100000100000000] = 8 + 14 + 48
740+
* `y9gw6ymamd20jumvdgpfphkhp8fzhhdhycw36egcmla5vlrtrmhs9t7psfy3hkkdqzm9eq64fjg558znccds5nhsfmxveha5xe0dykgp`: signature
741+
* `spdha0`: Bech32 checksum
742+
707743
# Examples of Invalid Invoices
708744

709745
> # Same, but adding invalid unknown feature 100

0 commit comments

Comments
 (0)