Store the source HumanReadableName in InvoiceRequestFields

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`.
This commit is contained in:
Matt Corallo 2024-09-30 18:18:38 +00:00
parent e447b49136
commit 8d8416b956
4 changed files with 19 additions and 0 deletions

View file

@ -89,6 +89,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 {

View file

@ -125,6 +125,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,

View 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);

View file

@ -1030,6 +1030,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.offer_from_hrn().clone(),
}
}
}
@ -1350,6 +1351,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`].
@ -1359,6 +1363,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),
});
@ -1370,6 +1375,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))),
});
@ -1378,6 +1384,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,
})
}
}
@ -2733,6 +2740,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,
}
);