]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Rename Payment{Hash,Id} hmac creation/verification methods for offers.
authorValentine Wallace <vwallace@protonmail.com>
Thu, 5 Sep 2024 20:40:51 +0000 (16:40 -0400)
committerValentine Wallace <vwallace@protonmail.com>
Fri, 13 Sep 2024 14:40:06 +0000 (10:40 -0400)
We want to specify that these methods are only to be used in an outbound offers
payment context, because we'll be adding similar methods for the outbound async
payments context in upcoming commits.

lightning/src/ln/channelmanager.rs
lightning/src/offers/signer.rs

index 90d896eddf0f615a452ab01017bd106986c53a02..7e891f93dfd9d6d082f4925e673f2f9eb8664335 100644 (file)
@@ -420,7 +420,7 @@ pub trait Verification {
        ) -> Hmac<Sha256>;
 
        /// Authenticates the data using an HMAC and a [`Nonce`] taken from an [`OffersContext`].
-       fn verify(
+       fn verify_for_offer_payment(
                &self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
        ) -> Result<(), ()>;
 }
@@ -436,7 +436,7 @@ impl Verification for PaymentHash {
 
        /// Authenticates the payment id using an HMAC and a [`Nonce`] taken from an
        /// [`OffersContext::InboundPayment`].
-       fn verify(
+       fn verify_for_offer_payment(
                &self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
        ) -> Result<(), ()> {
                signer::verify_payment_hash(*self, hmac, nonce, expanded_key)
@@ -461,15 +461,15 @@ impl Verification for PaymentId {
        fn hmac_for_offer_payment(
                &self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
        ) -> Hmac<Sha256> {
-               signer::hmac_for_payment_id(*self, nonce, expanded_key)
+               signer::hmac_for_offer_payment_id(*self, nonce, expanded_key)
        }
 
        /// Authenticates the payment id using an HMAC and a [`Nonce`] taken from an
        /// [`OffersContext::OutboundPayment`].
-       fn verify(
+       fn verify_for_offer_payment(
                &self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
        ) -> Result<(), ()> {
-               signer::verify_payment_id(*self, hmac, nonce, expanded_key)
+               signer::verify_offer_payment_id(*self, hmac, nonce, expanded_key)
        }
 }
 
@@ -11144,7 +11144,7 @@ where
                        OffersMessage::StaticInvoice(invoice) => {
                                let payment_id = match context {
                                        Some(OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }) => {
-                                               if payment_id.verify(hmac, nonce, expanded_key).is_err() {
+                                               if payment_id.verify_for_offer_payment(hmac, nonce, expanded_key).is_err() {
                                                        return None
                                                }
                                                payment_id
@@ -11157,7 +11157,7 @@ where
                        OffersMessage::InvoiceError(invoice_error) => {
                                let payment_hash = match context {
                                        Some(OffersContext::InboundPayment { payment_hash, nonce, hmac }) => {
-                                               match payment_hash.verify(hmac, nonce, expanded_key) {
+                                               match payment_hash.verify_for_offer_payment(hmac, nonce, expanded_key) {
                                                        Ok(_) => Some(payment_hash),
                                                        Err(_) => None,
                                                }
@@ -11170,7 +11170,7 @@ where
 
                                match context {
                                        Some(OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }) => {
-                                               if let Ok(()) = payment_id.verify(hmac, nonce, expanded_key) {
+                                               if let Ok(()) = payment_id.verify_for_offer_payment(hmac, nonce, expanded_key) {
                                                        self.abandon_payment_with_reason(
                                                                payment_id, PaymentFailureReason::InvoiceRequestRejected,
                                                        );
index 907e478227fa7692f12019b896e470f2549c9008..152c7af5736cca0c1ff0cf2e389ab1abc055ead4 100644 (file)
@@ -38,7 +38,7 @@ const WITHOUT_ENCRYPTED_PAYMENT_ID_HMAC_INPUT: &[u8; 16] = &[3; 16];
 const WITH_ENCRYPTED_PAYMENT_ID_HMAC_INPUT: &[u8; 16] = &[4; 16];
 
 // HMAC input for a `PaymentId`. The HMAC is used in `OffersContext::OutboundPayment`.
-const PAYMENT_ID_HMAC_INPUT: &[u8; 16] = &[5; 16];
+const OFFER_PAYMENT_ID_HMAC_INPUT: &[u8; 16] = &[5; 16];
 
 // HMAC input for a `PaymentHash`. The HMAC is used in `OffersContext::InboundPayment`.
 const PAYMENT_HASH_HMAC_INPUT: &[u8; 16] = &[6; 16];
@@ -399,23 +399,23 @@ fn hmac_for_message<'a>(
        Ok(hmac)
 }
 
-pub(crate) fn hmac_for_payment_id(
+pub(crate) fn hmac_for_offer_payment_id(
        payment_id: PaymentId, nonce: Nonce, expanded_key: &ExpandedKey,
 ) -> Hmac<Sha256> {
        const IV_BYTES: &[u8; IV_LEN] = b"LDK Payment ID ~";
        let mut hmac = expanded_key.hmac_for_offer();
        hmac.input(IV_BYTES);
        hmac.input(&nonce.0);
-       hmac.input(PAYMENT_ID_HMAC_INPUT);
+       hmac.input(OFFER_PAYMENT_ID_HMAC_INPUT);
        hmac.input(&payment_id.0);
 
        Hmac::from_engine(hmac)
 }
 
-pub(crate) fn verify_payment_id(
+pub(crate) fn verify_offer_payment_id(
        payment_id: PaymentId, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &ExpandedKey,
 ) -> Result<(), ()> {
-       if hmac_for_payment_id(payment_id, nonce, expanded_key) == hmac { Ok(()) } else { Err(()) }
+       if hmac_for_offer_payment_id(payment_id, nonce, expanded_key) == hmac { Ok(()) } else { Err(()) }
 }
 
 pub(crate) fn hmac_for_payment_hash(