From: Jeffrey Czyz Date: Fri, 19 Jul 2024 14:56:11 +0000 (-0500) Subject: Rename InvoiceRequest::verify X-Git-Tag: v0.0.124-beta~37^2~14 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=9d463408c8097c47a8e8a38e95daee49e7a7fb92;p=rust-lightning Rename InvoiceRequest::verify --- diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 80faffc0d..b5356a853 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -10717,7 +10717,7 @@ where Ok(invoice_request) => invoice_request, Err(()) => return ResponseInstruction::NoResponse, }, - None => match invoice_request.verify(expanded_key, secp_ctx) { + None => match invoice_request.verify_using_metadata(expanded_key, secp_ctx) { Ok(invoice_request) => invoice_request, Err(()) => { let error = Bolt12SemanticError::InvalidMetadata; diff --git a/lightning/src/offers/invoice.rs b/lightning/src/offers/invoice.rs index 6100f02ca..2d34b1c09 100644 --- a/lightning/src/offers/invoice.rs +++ b/lightning/src/offers/invoice.rs @@ -1797,7 +1797,7 @@ mod tests { .sign(payer_sign).unwrap(); match invoice_request - .verify(&expanded_key, &secp_ctx).unwrap() + .verify_using_metadata(&expanded_key, &secp_ctx).unwrap() .respond_using_derived_keys_no_std(payment_paths(), payment_hash(), now()) { Ok(_) => panic!("expected error"), diff --git a/lightning/src/offers/invoice_request.rs b/lightning/src/offers/invoice_request.rs index 0fee4683c..39eb157d7 100644 --- a/lightning/src/offers/invoice_request.rs +++ b/lightning/src/offers/invoice_request.rs @@ -605,7 +605,7 @@ pub struct InvoiceRequest { signature: Signature, } -/// An [`InvoiceRequest`] that has been verified by [`InvoiceRequest::verify`] or +/// An [`InvoiceRequest`] that has been verified by [`InvoiceRequest::verify_using_metadata`] or /// [`InvoiceRequest::verify_using_recipient_data`] and exposes different ways to respond depending /// on whether the signing keys were derived. #[derive(Clone, Debug)] @@ -738,8 +738,9 @@ macro_rules! invoice_request_respond_with_explicit_signing_pubkey_methods { ( /// # Note /// /// If the originating [`Offer`] was created using [`OfferBuilder::deriving_signing_pubkey`], - /// then first use [`InvoiceRequest::verify`] or [`InvoiceRequest::verify_using_recipient_data`] - /// and then [`VerifiedInvoiceRequest`] methods instead. + /// then first use [`InvoiceRequest::verify_using_metadata`] or + /// [`InvoiceRequest::verify_using_recipient_data`] and then [`VerifiedInvoiceRequest`] methods + /// instead. /// /// [`Bolt12Invoice::created_at`]: crate::offers::invoice::Bolt12Invoice::created_at /// [`OfferBuilder::deriving_signing_pubkey`]: crate::offers::offer::OfferBuilder::deriving_signing_pubkey @@ -783,7 +784,7 @@ macro_rules! invoice_request_verify_method { ($self: ident, $self_type: ty) => { /// [`Bolt12Invoice`] for the request if they could be extracted from the metadata. /// /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice - pub fn verify< + pub fn verify_using_metadata< #[cfg(not(c_bindings))] T: secp256k1::Signing >( @@ -793,7 +794,8 @@ macro_rules! invoice_request_verify_method { ($self: ident, $self_type: ty) => { #[cfg(c_bindings)] secp_ctx: &Secp256k1, ) -> Result { - let (offer_id, keys) = $self.contents.inner.offer.verify(&$self.bytes, key, secp_ctx)?; + let (offer_id, keys) = + $self.contents.inner.offer.verify_using_metadata(&$self.bytes, key, secp_ctx)?; Ok(VerifiedInvoiceRequest { offer_id, #[cfg(not(c_bindings))] @@ -2326,7 +2328,7 @@ mod tests { .payer_note("0".repeat(PAYER_NOTE_LIMIT * 2)) .build().unwrap() .sign(payer_sign).unwrap(); - match invoice_request.verify(&expanded_key, &secp_ctx) { + match invoice_request.verify_using_metadata(&expanded_key, &secp_ctx) { Ok(invoice_request) => { let fields = invoice_request.fields(); assert_eq!(invoice_request.offer_id, offer.id()); diff --git a/lightning/src/offers/offer.rs b/lightning/src/offers/offer.rs index 1911940eb..94d5175a5 100644 --- a/lightning/src/offers/offer.rs +++ b/lightning/src/offers/offer.rs @@ -248,12 +248,12 @@ macro_rules! offer_derived_metadata_builder_methods { ($secp_context: ty) => { /// `node_id` is used for the signing pubkey. /// /// Also, sets the metadata when [`OfferBuilder::build`] is called such that it can be used by - /// [`InvoiceRequest::verify`] to determine if the request was produced for the offer given an - /// [`ExpandedKey`]. However, if [`OfferBuilder::path`] is called, then the metadata will not be - /// set and must be included in each [`BlindedPath`] instead. In this case, use - /// [`InvoiceRequest::verify_using_recipient_data`]. + /// [`InvoiceRequest::verify_using_metadata`] to determine if the request was produced for the + /// offer given an [`ExpandedKey`]. However, if [`OfferBuilder::path`] is called, then the + /// metadata will not be set and must be included in each [`BlindedPath`] instead. In this case, + /// use [`InvoiceRequest::verify_using_recipient_data`]. /// - /// [`InvoiceRequest::verify`]: crate::offers::invoice_request::InvoiceRequest::verify + /// [`InvoiceRequest::verify_using_metadata`]: crate::offers::invoice_request::InvoiceRequest::verify_using_metadata /// [`InvoiceRequest::verify_using_recipient_data`]: crate::offers::invoice_request::InvoiceRequest::verify_using_recipient_data /// [`ExpandedKey`]: crate::ln::inbound_payment::ExpandedKey pub fn deriving_signing_pubkey( @@ -922,20 +922,20 @@ impl OfferContents { self.signing_pubkey } - pub(super) fn verify( + pub(super) fn verify_using_metadata( &self, bytes: &[u8], key: &ExpandedKey, secp_ctx: &Secp256k1 ) -> Result<(OfferId, Option), ()> { - self.verify_using_metadata(bytes, self.metadata.as_ref(), key, secp_ctx) + self.verify(bytes, self.metadata.as_ref(), key, secp_ctx) } pub(super) fn verify_using_recipient_data( &self, bytes: &[u8], nonce: Nonce, key: &ExpandedKey, secp_ctx: &Secp256k1 ) -> Result<(OfferId, Option), ()> { - self.verify_using_metadata(bytes, Some(&Metadata::RecipientData(nonce)), key, secp_ctx) + self.verify(bytes, Some(&Metadata::RecipientData(nonce)), key, secp_ctx) } /// Verifies that the offer metadata was produced from the offer in the TLV stream. - fn verify_using_metadata( + fn verify( &self, bytes: &[u8], metadata: Option<&Metadata>, key: &ExpandedKey, secp_ctx: &Secp256k1 ) -> Result<(OfferId, Option), ()> { match metadata { @@ -1311,7 +1311,7 @@ mod tests { let invoice_request = offer.request_invoice(vec![1; 32], payer_pubkey()).unwrap() .build().unwrap() .sign(payer_sign).unwrap(); - match invoice_request.verify(&expanded_key, &secp_ctx) { + match invoice_request.verify_using_metadata(&expanded_key, &secp_ctx) { Ok(invoice_request) => assert_eq!(invoice_request.offer_id, offer.id()), Err(_) => panic!("unexpected error"), } @@ -1335,7 +1335,7 @@ mod tests { .request_invoice(vec![1; 32], payer_pubkey()).unwrap() .build().unwrap() .sign(payer_sign).unwrap(); - assert!(invoice_request.verify(&expanded_key, &secp_ctx).is_err()); + assert!(invoice_request.verify_using_metadata(&expanded_key, &secp_ctx).is_err()); // Fails verification with altered metadata let mut tlv_stream = offer.as_tlv_stream(); @@ -1349,7 +1349,7 @@ mod tests { .request_invoice(vec![1; 32], payer_pubkey()).unwrap() .build().unwrap() .sign(payer_sign).unwrap(); - assert!(invoice_request.verify(&expanded_key, &secp_ctx).is_err()); + assert!(invoice_request.verify_using_metadata(&expanded_key, &secp_ctx).is_err()); } #[test] @@ -1390,7 +1390,7 @@ mod tests { let invoice_request = offer.request_invoice(vec![1; 32], payer_pubkey()).unwrap() .build().unwrap() .sign(payer_sign).unwrap(); - assert!(invoice_request.verify(&expanded_key, &secp_ctx).is_err()); + assert!(invoice_request.verify_using_metadata(&expanded_key, &secp_ctx).is_err()); // Fails verification with altered offer field let mut tlv_stream = offer.as_tlv_stream();