@@ -8462,7 +8462,7 @@ impl<
84628462 payment_data,
84638463 payment_context,
84648464 phantom_shared_secret,
8465- onion_fields,
8465+ mut onion_fields,
84668466 has_recipient_created_payment_secret,
84678467 invoice_request_opt,
84688468 trampoline_shared_secret,
@@ -8603,7 +8603,7 @@ impl<
86038603 let verify_res = inbound_payment::verify(
86048604 payment_hash,
86058605 &payment_data,
8606- onion_fields.payment_metadata.as_deref (),
8606+ onion_fields.payment_metadata.as_mut (),
86078607 self.highest_seen_timestamp.load(Ordering::Acquire) as u64,
86088608 &self.inbound_payment_key,
86098609 &self.logger,
@@ -14372,24 +14372,24 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1437214372 }
1437314373 }
1437414374
14375- let (payment_hash, payment_secret) = match payment_hash {
14375+ let (payment_hash, payment_secret, payment_metadata ) = match payment_hash {
1437614376 Some(payment_hash) => {
14377- let payment_secret = self
14377+ let ( payment_secret, payment_metadata) = self
1437814378 .create_inbound_payment_for_hash(
1437914379 payment_hash, amount_msats,
1438014380 invoice_expiry_delta_secs.unwrap_or(DEFAULT_EXPIRY_TIME as u32),
1438114381 min_final_cltv_expiry_delta,
14382- payment_metadata.as_deref() ,
14382+ payment_metadata,
1438314383 )
1438414384 .map_err(|()| SignOrCreationError::CreationError(CreationError::InvalidAmount))?;
14385- (payment_hash, payment_secret)
14385+ (payment_hash, payment_secret, payment_metadata )
1438614386 },
1438714387 None => {
1438814388 self
1438914389 .create_inbound_payment(
1439014390 amount_msats, invoice_expiry_delta_secs.unwrap_or(DEFAULT_EXPIRY_TIME as u32),
1439114391 min_final_cltv_expiry_delta,
14392- payment_metadata.as_deref() ,
14392+ payment_metadata,
1439314393 )
1439414394 .map_err(|()| SignOrCreationError::CreationError(CreationError::InvalidAmount))?
1439514395 },
@@ -14516,8 +14516,7 @@ pub struct Bolt11InvoiceParameters {
1451614516 /// onion by the sender, available as [`RecipientOnionFields::payment_metadata`] via
1451714517 /// [`Event::PaymentClaimable::onion_fields`].
1451814518 ///
14519- /// Note that because it is exposed to the sender in the invoice you should consider encrypting
14520- /// it. It is committed to, however, so cannot be modified by the sender.
14519+ /// The metadata itself is encrypted and HMAC'd before being stored in the BOLT 11 invoice.
1452114520 pub payment_metadata: Option<Vec<u8>>,
1452214521}
1452314522
@@ -15023,6 +15022,7 @@ impl<
1502315022 |amount_msats, relative_expiry| {
1502415023 self.create_inbound_payment(Some(amount_msats), relative_expiry, None, None)
1502515024 .map_err(|()| Bolt12SemanticError::InvalidAmount)
15025+ .map(|(preimage, secret, _no_metadata)| (preimage, secret))
1502615026 },
1502715027 None,
1502815028 )?;
@@ -15033,8 +15033,8 @@ impl<
1503315033 Ok(invoice)
1503415034 }
1503515035
15036- /// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
15037- /// to pay us.
15036+ /// Gets a payment secret, payment hash, and encrypts the `payment_metadata` for use in an
15037+ /// invoice given to a third party wishing to pay us.
1503815038 ///
1503915039 /// This differs from [`create_inbound_payment_for_hash`] only in that it generates the
1504015040 /// [`PaymentHash`] and [`PaymentPreimage`] for you.
@@ -15065,8 +15065,8 @@ impl<
1506515065 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
1506615066 pub fn create_inbound_payment(
1506715067 &self, min_value_msat: Option<u64>, invoice_expiry_delta_secs: u32,
15068- min_final_cltv_expiry_delta: Option<u16>, payment_metadata: Option<&[u8] >,
15069- ) -> Result<(PaymentHash, PaymentSecret), ()> {
15068+ min_final_cltv_expiry_delta: Option<u16>, payment_metadata: Option<Vec<u8> >,
15069+ ) -> Result<(PaymentHash, PaymentSecret, Option<Vec<u8>> ), ()> {
1507015070 inbound_payment::create(
1507115071 &self.inbound_payment_key,
1507215072 min_value_msat,
@@ -15078,8 +15078,8 @@ impl<
1507815078 )
1507915079 }
1508015080
15081- /// Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is
15082- /// stored external to LDK.
15081+ /// Gets a [`PaymentSecret`] for a given [`PaymentHash`] ( for which the payment preimage is
15082+ /// stored external to LDK) and encrypts the `payment_metadata` .
1508315083 ///
1508415084 /// A [`PaymentClaimable`] event will only be generated if the [`PaymentSecret`] matches a
1508515085 /// payment secret fetched via this method or [`create_inbound_payment`], and which is at least
@@ -15115,41 +15115,34 @@ impl<
1511515115 /// Note that a malicious eavesdropper can intuit whether an inbound payment was created by
1511615116 /// `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
1511715117 ///
15118- /// # Note
15119- ///
15120- /// If you register an inbound payment with this method, then serialize the `ChannelManager`, then
15121- /// deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
15122- ///
1512315118 /// Errors if `min_value_msat` is greater than total bitcoin supply.
1512415119 ///
15125- /// If `min_final_cltv_expiry_delta` is set to some value, then the payment will not be receivable
15126- /// on versions of LDK prior to 0.0.114.
15127- ///
1512815120 /// [`create_inbound_payment`]: Self::create_inbound_payment
1512915121 /// [`PaymentClaimable`]: events::Event::PaymentClaimable
1513015122 pub fn create_inbound_payment_for_hash(
1513115123 &self, payment_hash: PaymentHash, min_value_msat: Option<u64>,
1513215124 invoice_expiry_delta_secs: u32, min_final_cltv_expiry: Option<u16>,
15133- payment_metadata: Option<&[u8] >,
15134- ) -> Result<PaymentSecret, ()> {
15125+ payment_metadata: Option<Vec<u8> >,
15126+ ) -> Result<( PaymentSecret, Option<Vec<u8>>) , ()> {
1513515127 inbound_payment::create_from_hash(
1513615128 &self.inbound_payment_key,
1513715129 min_value_msat,
1513815130 payment_hash,
1513915131 invoice_expiry_delta_secs,
15132+ &self.entropy_source,
1514015133 self.highest_seen_timestamp.load(Ordering::Acquire) as u64,
1514115134 min_final_cltv_expiry,
1514215135 payment_metadata,
1514315136 )
1514415137 }
1514515138
15146- /// Gets an LDK-generated payment preimage from a payment hash, metadata and secret that were
15147- /// previously returned from [`create_inbound_payment`].
15139+ /// Gets an LDK-generated payment preimage from a payment hash and secret and decrypts the
15140+ /// metadata (if any) that were previously returned from [`create_inbound_payment`].
1514815141 ///
1514915142 /// [`create_inbound_payment`]: Self::create_inbound_payment
15150- pub fn get_payment_preimage (
15143+ pub fn get_payment_preimage_decrypt_metadata (
1515115144 &self, payment_hash: PaymentHash, payment_secret: PaymentSecret,
15152- payment_metadata: Option<&[u8]>,
15145+ payment_metadata: Option<&mut [u8]>,
1515315146 ) -> Result<PaymentPreimage, APIError> {
1515415147 let expanded_key = &self.inbound_payment_key;
1515515148 inbound_payment::get_payment_preimage(
@@ -17235,7 +17228,9 @@ impl<
1723517228 relative_expiry,
1723617229 None,
1723717230 None,
17238- ).map_err(|_| Bolt12SemanticError::InvalidAmount)
17231+ )
17232+ .map_err(|_| Bolt12SemanticError::InvalidAmount)
17233+ .map(|(preimage, secret, _no_metadata)| (preimage, secret))
1723917234 };
1724017235
1724117236 let (result, context) = match invoice_request {
@@ -22137,7 +22132,8 @@ pub mod bench {
2213722132 payment_preimage.0[0..8].copy_from_slice(&payment_count.to_le_bytes());
2213822133 payment_count += 1;
2213922134 let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).to_byte_array());
22140- let payment_secret = $node_b.create_inbound_payment_for_hash(payment_hash, None, 7200, None, None).unwrap();
22135+ let (payment_secret, _no_payment_metadata) =
22136+ $node_b.create_inbound_payment_for_hash(payment_hash, None, 7200, None, None).unwrap();
2214122137
2214222138 $node_a.send_payment(payment_hash, RecipientOnionFields::secret_only(payment_secret, 10_000),
2214322139 PaymentId(payment_hash.0),
0 commit comments