]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add helper function to properly get invoice pubkey
authorbenthecarman <benthecarman@live.com>
Thu, 22 Feb 2024 18:05:37 +0000 (18:05 +0000)
committerbenthecarman <benthecarman@live.com>
Thu, 22 Feb 2024 18:05:37 +0000 (18:05 +0000)
lightning-invoice/src/lib.rs

index 610f739e57ad9d294610103edd36bbd5155d7109..457896633f63bf18af3f6345dfd9c66666e4d256 100644 (file)
@@ -1355,6 +1355,15 @@ impl Bolt11Invoice {
                self.signed_invoice.recover_payee_pub_key().expect("was checked by constructor").0
        }
 
+       /// Recover the payee's public key if one was included in the invoice, otherwise return the
+       /// recovered public key from the signature
+       pub fn get_payee_pub_key(&self) -> PublicKey {
+               match self.payee_pub_key() {
+                       Some(pk) => *pk,
+                       None => self.recover_payee_pub_key()
+               }
+       }
+
        /// Returns the Duration since the Unix epoch at which the invoice expires.
        /// Returning None if overflow occurred.
        pub fn expires_at(&self) -> Option<Duration> {