@@ -8467,7 +8467,7 @@ impl<
84678467 payment_data,
84688468 payment_context,
84698469 phantom_shared_secret,
8470- onion_fields,
8470+ mut onion_fields,
84718471 has_recipient_created_payment_secret,
84728472 invoice_request_opt,
84738473 trampoline_shared_secret,
@@ -8608,7 +8608,7 @@ impl<
86088608 let verify_res = inbound_payment::verify(
86098609 payment_hash,
86108610 &payment_data,
8611- onion_fields.payment_metadata.as_deref (),
8611+ onion_fields.payment_metadata.as_mut (),
86128612 self.highest_seen_timestamp.load(Ordering::Acquire) as u64,
86138613 &self.inbound_payment_key,
86148614 &self.logger,
@@ -14477,24 +14477,24 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1447714477 }
1447814478 }
1447914479
14480- let (payment_hash, payment_secret) = match payment_hash {
14480+ let (payment_hash, payment_secret, payment_metadata ) = match payment_hash {
1448114481 Some(payment_hash) => {
14482- let payment_secret = self
14482+ let ( payment_secret, payment_metadata) = self
1448314483 .create_inbound_payment_for_hash(
1448414484 payment_hash, amount_msats,
1448514485 invoice_expiry_delta_secs.unwrap_or(DEFAULT_EXPIRY_TIME as u32),
1448614486 min_final_cltv_expiry_delta,
14487- payment_metadata.as_deref() ,
14487+ payment_metadata,
1448814488 )
1448914489 .map_err(|()| SignOrCreationError::CreationError(CreationError::InvalidAmount))?;
14490- (payment_hash, payment_secret)
14490+ (payment_hash, payment_secret, payment_metadata )
1449114491 },
1449214492 None => {
1449314493 self
1449414494 .create_inbound_payment(
1449514495 amount_msats, invoice_expiry_delta_secs.unwrap_or(DEFAULT_EXPIRY_TIME as u32),
1449614496 min_final_cltv_expiry_delta,
14497- payment_metadata.as_deref() ,
14497+ payment_metadata,
1449814498 )
1449914499 .map_err(|()| SignOrCreationError::CreationError(CreationError::InvalidAmount))?
1450014500 },
@@ -14621,8 +14621,7 @@ pub struct Bolt11InvoiceParameters {
1462114621 /// onion by the sender, available as [`RecipientOnionFields::payment_metadata`] via
1462214622 /// [`Event::PaymentClaimable::onion_fields`].
1462314623 ///
14624- /// Note that because it is exposed to the sender in the invoice you should consider encrypting
14625- /// it. It is committed to, however, so cannot be modified by the sender.
14624+ /// The metadata itself is encrypted and HMAC'd before being stored in the BOLT 11 invoice.
1462614625 pub payment_metadata: Option<Vec<u8>>,
1462714626}
1462814627
@@ -15128,6 +15127,7 @@ impl<
1512815127 |amount_msats, relative_expiry| {
1512915128 self.create_inbound_payment(Some(amount_msats), relative_expiry, None, None)
1513015129 .map_err(|()| Bolt12SemanticError::InvalidAmount)
15130+ .map(|(preimage, secret, _no_metadata)| (preimage, secret))
1513115131 },
1513215132 None,
1513315133 )?;
@@ -15138,8 +15138,8 @@ impl<
1513815138 Ok(invoice)
1513915139 }
1514015140
15141- /// Gets a payment secret and payment hash for use in an invoice given to a third party wishing
15142- /// to pay us.
15141+ /// Gets a payment secret, payment hash, and encrypts the `payment_metadata` for use in an
15142+ /// invoice given to a third party wishing to pay us.
1514315143 ///
1514415144 /// This differs from [`create_inbound_payment_for_hash`] only in that it generates the
1514515145 /// [`PaymentHash`] and [`PaymentPreimage`] for you.
@@ -15170,8 +15170,8 @@ impl<
1517015170 /// [`create_inbound_payment_for_hash`]: Self::create_inbound_payment_for_hash
1517115171 pub fn create_inbound_payment(
1517215172 &self, min_value_msat: Option<u64>, invoice_expiry_delta_secs: u32,
15173- min_final_cltv_expiry_delta: Option<u16>, payment_metadata: Option<&[u8] >,
15174- ) -> Result<(PaymentHash, PaymentSecret), ()> {
15173+ min_final_cltv_expiry_delta: Option<u16>, payment_metadata: Option<Vec<u8> >,
15174+ ) -> Result<(PaymentHash, PaymentSecret, Option<Vec<u8>> ), ()> {
1517515175 inbound_payment::create(
1517615176 &self.inbound_payment_key,
1517715177 min_value_msat,
@@ -15183,8 +15183,8 @@ impl<
1518315183 )
1518415184 }
1518515185
15186- /// Gets a [`PaymentSecret`] for a given [`PaymentHash`], for which the payment preimage is
15187- /// stored external to LDK.
15186+ /// Gets a [`PaymentSecret`] for a given [`PaymentHash`] ( for which the payment preimage is
15187+ /// stored external to LDK) and encrypts the `payment_metadata` .
1518815188 ///
1518915189 /// A [`PaymentClaimable`] event will only be generated if the [`PaymentSecret`] matches a
1519015190 /// payment secret fetched via this method or [`create_inbound_payment`], and which is at least
@@ -15220,41 +15220,34 @@ impl<
1522015220 /// Note that a malicious eavesdropper can intuit whether an inbound payment was created by
1522115221 /// `create_inbound_payment` or `create_inbound_payment_for_hash` based on runtime.
1522215222 ///
15223- /// # Note
15224- ///
15225- /// If you register an inbound payment with this method, then serialize the `ChannelManager`, then
15226- /// deserialize it with a node running 0.0.103 and earlier, the payment will fail to be received.
15227- ///
1522815223 /// Errors if `min_value_msat` is greater than total bitcoin supply.
1522915224 ///
15230- /// If `min_final_cltv_expiry_delta` is set to some value, then the payment will not be receivable
15231- /// on versions of LDK prior to 0.0.114.
15232- ///
1523315225 /// [`create_inbound_payment`]: Self::create_inbound_payment
1523415226 /// [`PaymentClaimable`]: events::Event::PaymentClaimable
1523515227 pub fn create_inbound_payment_for_hash(
1523615228 &self, payment_hash: PaymentHash, min_value_msat: Option<u64>,
1523715229 invoice_expiry_delta_secs: u32, min_final_cltv_expiry: Option<u16>,
15238- payment_metadata: Option<&[u8] >,
15239- ) -> Result<PaymentSecret, ()> {
15230+ payment_metadata: Option<Vec<u8> >,
15231+ ) -> Result<( PaymentSecret, Option<Vec<u8>>) , ()> {
1524015232 inbound_payment::create_from_hash(
1524115233 &self.inbound_payment_key,
1524215234 min_value_msat,
1524315235 payment_hash,
1524415236 invoice_expiry_delta_secs,
15237+ &self.entropy_source,
1524515238 self.highest_seen_timestamp.load(Ordering::Acquire) as u64,
1524615239 min_final_cltv_expiry,
1524715240 payment_metadata,
1524815241 )
1524915242 }
1525015243
15251- /// Gets an LDK-generated payment preimage from a payment hash, metadata and secret that were
15252- /// previously returned from [`create_inbound_payment`].
15244+ /// Gets an LDK-generated payment preimage from a payment hash and secret and decrypts the
15245+ /// metadata (if any) that were previously returned from [`create_inbound_payment`].
1525315246 ///
1525415247 /// [`create_inbound_payment`]: Self::create_inbound_payment
15255- pub fn get_payment_preimage (
15248+ pub fn get_payment_preimage_decrypt_metadata (
1525615249 &self, payment_hash: PaymentHash, payment_secret: PaymentSecret,
15257- payment_metadata: Option<&[u8]>,
15250+ payment_metadata: Option<&mut [u8]>,
1525815251 ) -> Result<PaymentPreimage, APIError> {
1525915252 let expanded_key = &self.inbound_payment_key;
1526015253 inbound_payment::get_payment_preimage(
@@ -17336,7 +17329,9 @@ impl<
1733617329 relative_expiry,
1733717330 None,
1733817331 None,
17339- ).map_err(|_| Bolt12SemanticError::InvalidAmount)
17332+ )
17333+ .map_err(|_| Bolt12SemanticError::InvalidAmount)
17334+ .map(|(preimage, secret, _no_metadata)| (preimage, secret))
1734017335 };
1734117336
1734217337 let (result, context) = match invoice_request {
@@ -22238,7 +22233,8 @@ pub mod bench {
2223822233 payment_preimage.0[0..8].copy_from_slice(&payment_count.to_le_bytes());
2223922234 payment_count += 1;
2224022235 let payment_hash = PaymentHash(Sha256::hash(&payment_preimage.0[..]).to_byte_array());
22241- let payment_secret = $node_b.create_inbound_payment_for_hash(payment_hash, None, 7200, None, None).unwrap();
22236+ let (payment_secret, _no_payment_metadata) =
22237+ $node_b.create_inbound_payment_for_hash(payment_hash, None, 7200, None, None).unwrap();
2224222238
2224322239 $node_a.send_payment(payment_hash, RecipientOnionFields::secret_only(payment_secret, 10_000),
2224422240 PaymentId(payment_hash.0),
0 commit comments