]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Store the source `HumanReadableName` in `InvoiceRequestFields`
authorMatt Corallo <git@bluematt.me>
Mon, 30 Sep 2024 18:18:38 +0000 (18:18 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 8 Oct 2024 19:47:54 +0000 (19:47 +0000)
When we receive a payment to an offer we issued resolved with a
human readable name, it may have been resolved using a wildcard
DNS entry which we want to map to a specific recipient account
locally. To do this, we need the human readable name from the
`InvoiceRequest` in the `PaymentClaim{able,ed}`, which we pipe
through here using `InvoiceRequestFields`.

fuzz/src/invoice_request_deser.rs
lightning/src/events/mod.rs
lightning/src/ln/offers_tests.rs
lightning/src/offers/invoice_request.rs

index fb5122ec23dd4bc74d424f951001b69f0bc19951..c492e0d93cb379d7332d0a44e6b3665e21a9db0f 100644 (file)
@@ -90,6 +90,7 @@ fn build_response<T: secp256k1::Signing + secp256k1::Verification>(
                        payer_note_truncated: invoice_request
                                .payer_note()
                                .map(|s| UntrustedString(s.to_string())),
+                       human_readable_name: None,
                },
        });
        let payee_tlvs = ReceiveTlvs {
index 379a0d79a9a82265988f134f30e4360e824c468a..547822e7826a4a48f48a04b760665ae94b61e884 100644 (file)
@@ -124,6 +124,10 @@ pub enum PaymentPurpose {
                /// The context of the payment such as information about the corresponding [`Offer`] and
                /// [`InvoiceRequest`].
                ///
+               /// This includes the Human Readable Name which the sender indicated they were paying to,
+               /// for possible recipient disambiguation if you're using a single wildcard DNS entry to
+               /// resolve to many recipients.
+               ///
                /// [`Offer`]: crate::offers::offer::Offer
                /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
                payment_context: Bolt12OfferContext,
index 12b10754e410d168b1676da2c61a36f1fe9a36d8..81c2e8464ea56b5b558a03328b37a63ccbcc8260 100644 (file)
@@ -564,6 +564,7 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
                        payer_signing_pubkey: invoice_request.payer_signing_pubkey(),
                        quantity: None,
                        payer_note_truncated: None,
+                       human_readable_name: None,
                },
        });
        assert_eq!(invoice_request.amount_msats(), None);
@@ -724,6 +725,7 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
                        payer_signing_pubkey: invoice_request.payer_signing_pubkey(),
                        quantity: None,
                        payer_note_truncated: None,
+                       human_readable_name: None,
                },
        });
        assert_eq!(invoice_request.amount_msats(), None);
@@ -844,6 +846,7 @@ fn pays_for_offer_without_blinded_paths() {
                        payer_signing_pubkey: invoice_request.payer_signing_pubkey(),
                        quantity: None,
                        payer_note_truncated: None,
+                       human_readable_name: None,
                },
        });
 
@@ -1111,6 +1114,7 @@ fn creates_and_pays_for_offer_with_retry() {
                        payer_signing_pubkey: invoice_request.payer_signing_pubkey(),
                        quantity: None,
                        payer_note_truncated: None,
+                       human_readable_name: None,
                },
        });
        assert_eq!(invoice_request.amount_msats(), None);
@@ -1175,6 +1179,7 @@ fn pays_bolt12_invoice_asynchronously() {
                        payer_signing_pubkey: invoice_request.payer_signing_pubkey(),
                        quantity: None,
                        payer_note_truncated: None,
+                       human_readable_name: None,
                },
        });
 
@@ -1264,6 +1269,7 @@ fn creates_offer_with_blinded_path_using_unannounced_introduction_node() {
                        payer_signing_pubkey: invoice_request.payer_signing_pubkey(),
                        quantity: None,
                        payer_note_truncated: None,
+                       human_readable_name: None,
                },
        });
        assert_ne!(invoice_request.payer_signing_pubkey(), bob_id);
index cee149695201855d4c525b860a5e57edb0e12be1..d7eb4b89fc365367d21f1db3417fd14d3d087545 100644 (file)
@@ -966,6 +966,7 @@ impl VerifiedInvoiceRequest {
                        quantity: *quantity,
                        payer_note_truncated: payer_note.clone()
                                .map(|mut s| { s.truncate(PAYER_NOTE_LIMIT); UntrustedString(s) }),
+                       human_readable_name: self.source_human_readable_name().clone(),
                }
        }
 }
@@ -1233,6 +1234,9 @@ pub struct InvoiceRequestFields {
        /// A payer-provided note which will be seen by the recipient and reflected back in the invoice
        /// response. Truncated to [`PAYER_NOTE_LIMIT`] characters.
        pub payer_note_truncated: Option<UntrustedString>,
+
+       /// The Human Readable Name which the sender indicated they were paying to.
+       pub human_readable_name: Option<HumanReadableName>,
 }
 
 /// The maximum number of characters included in [`InvoiceRequestFields::payer_note_truncated`].
@@ -1242,6 +1246,7 @@ impl Writeable for InvoiceRequestFields {
        fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
                write_tlv_fields!(writer, {
                        (0, self.payer_signing_pubkey, required),
+                       (1, self.human_readable_name, option),
                        (2, self.quantity.map(|v| HighZeroBytesDroppedBigSize(v)), option),
                        (4, self.payer_note_truncated.as_ref().map(|s| WithoutLength(&s.0)), option),
                });
@@ -1253,6 +1258,7 @@ impl Readable for InvoiceRequestFields {
        fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
                _init_and_read_len_prefixed_tlv_fields!(reader, {
                        (0, payer_signing_pubkey, required),
+                       (1, human_readable_name, option),
                        (2, quantity, (option, encoding: (u64, HighZeroBytesDroppedBigSize))),
                        (4, payer_note_truncated, (option, encoding: (String, WithoutLength))),
                });
@@ -1261,6 +1267,7 @@ impl Readable for InvoiceRequestFields {
                        payer_signing_pubkey: payer_signing_pubkey.0.unwrap(),
                        quantity,
                        payer_note_truncated: payer_note_truncated.map(|s| UntrustedString(s)),
+                       human_readable_name,
                })
        }
 }
@@ -2378,6 +2385,7 @@ mod tests {
                                                payer_signing_pubkey: payer_pubkey(),
                                                quantity: Some(1),
                                                payer_note_truncated: Some(UntrustedString("0".repeat(PAYER_NOTE_LIMIT))),
+                                               human_readable_name: None,
                                        }
                                );