Skip to content

Commit

Permalink
Rename Bolt12Invoice::verify
Browse files Browse the repository at this point in the history
  • Loading branch information
jkczyz committed Jul 19, 2024
1 parent 69f2c37 commit 2280707
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4123,7 +4123,7 @@ where

match context {
OffersContext::Unknown {} if invoice.is_for_refund_without_paths() => {
invoice.verify(expanded_key, secp_ctx)
invoice.verify_using_metadata(expanded_key, secp_ctx)
},
OffersContext::OutboundPayment { payment_id, nonce } => {
invoice
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/offers/invoice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ impl Bolt12Invoice {
/// checking the payer metadata from the invoice request.
///
/// Returns the associated [`PaymentId`] to use when sending the payment.
pub fn verify<T: secp256k1::Signing>(
pub fn verify_using_metadata<T: secp256k1::Signing>(
&self, key: &ExpandedKey, secp_ctx: &Secp256k1<T>
) -> Result<PaymentId, ()> {
let metadata = match &self.contents {
Expand Down
8 changes: 4 additions & 4 deletions lightning/src/offers/invoice_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ mod tests {
.unwrap()
.build().unwrap()
.sign(recipient_sign).unwrap();
match invoice.verify(&expanded_key, &secp_ctx) {
match invoice.verify_using_metadata(&expanded_key, &secp_ctx) {
Ok(payment_id) => assert_eq!(payment_id, PaymentId([1; 32])),
Err(()) => panic!("verification failed"),
}
Expand All @@ -1440,7 +1440,7 @@ mod tests {
signature_tlv_stream.write(&mut encoded_invoice).unwrap();

let invoice = Bolt12Invoice::try_from(encoded_invoice).unwrap();
assert!(invoice.verify(&expanded_key, &secp_ctx).is_err());
assert!(invoice.verify_using_metadata(&expanded_key, &secp_ctx).is_err());

// Fails verification with altered metadata
let (
Expand All @@ -1463,7 +1463,7 @@ mod tests {
signature_tlv_stream.write(&mut encoded_invoice).unwrap();

let invoice = Bolt12Invoice::try_from(encoded_invoice).unwrap();
assert!(invoice.verify(&expanded_key, &secp_ctx).is_err());
assert!(invoice.verify_using_metadata(&expanded_key, &secp_ctx).is_err());
}

#[test]
Expand All @@ -1487,7 +1487,7 @@ mod tests {
.unwrap()
.build().unwrap()
.sign(recipient_sign).unwrap();
assert!(invoice.verify(&expanded_key, &secp_ctx).is_err());
assert!(invoice.verify_using_metadata(&expanded_key, &secp_ctx).is_err());
assert!(invoice.verify_using_payer_data(payment_id, nonce, &expanded_key, &secp_ctx));

// Fails verification with altered fields
Expand Down
7 changes: 4 additions & 3 deletions lightning/src/offers/offer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,16 +685,17 @@ macro_rules! request_invoice_derived_payer_id { ($self: ident, $builder: ty) =>
/// - derives the [`InvoiceRequest::payer_id`] such that a different key can be used for each
/// request,
/// - sets [`InvoiceRequest::payer_metadata`] when [`InvoiceRequestBuilder::build`] is called
/// such that it can be used by [`Bolt12Invoice::verify`] to determine if the invoice was
/// requested using a base [`ExpandedKey`] from which the payer id was derived, and
/// such that it can be used by [`Bolt12Invoice::verify_using_metadata`] to determine if the
/// invoice was requested using a base [`ExpandedKey`] from which the payer id was derived,
/// and
/// - includes the [`PaymentId`] encrypted in [`InvoiceRequest::payer_metadata`] so that it can
/// be used when sending the payment for the requested invoice.
///
/// Useful to protect the sender's privacy.
///
/// [`InvoiceRequest::payer_id`]: crate::offers::invoice_request::InvoiceRequest::payer_id
/// [`InvoiceRequest::payer_metadata`]: crate::offers::invoice_request::InvoiceRequest::payer_metadata
/// [`Bolt12Invoice::verify`]: crate::offers::invoice::Bolt12Invoice::verify
/// [`Bolt12Invoice::verify_using_metadata`]: crate::offers::invoice::Bolt12Invoice::verify_using_metadata
/// [`ExpandedKey`]: crate::ln::inbound_payment::ExpandedKey
pub fn request_invoice_deriving_payer_id<
'a, 'b,
Expand Down
16 changes: 8 additions & 8 deletions lightning/src/offers/refund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,15 @@ macro_rules! refund_builder_methods { (
/// provided `node_id` is used for the payer id.
///
/// Also, sets the metadata when [`RefundBuilder::build`] is called such that it can be used by
/// [`Bolt12Invoice::verify`] to determine if the invoice was produced for the refund given an
/// [`ExpandedKey`]. However, if [`RefundBuilder::path`] is called, then the metadata must be
/// included in each [`BlindedPath`] instead. In this case, use
/// [`Bolt12Invoice::verify_using_metadata`] to determine if the invoice was produced for the
/// refund given an [`ExpandedKey`]. However, if [`RefundBuilder::path`] is called, then the
/// metadata must be included in each [`BlindedPath`] instead. In this case, use
/// [`Bolt12Invoice::verify_using_payer_data`].
///
/// The `payment_id` is encrypted in the metadata and should be unique. This ensures that only
/// one invoice will be paid for the refund and that payments can be uniquely identified.
///
/// [`Bolt12Invoice::verify`]: crate::offers::invoice::Bolt12Invoice::verify
/// [`Bolt12Invoice::verify_using_metadata`]: crate::offers::invoice::Bolt12Invoice::verify_using_metadata
/// [`Bolt12Invoice::verify_using_payer_data`]: crate::offers::invoice::Bolt12Invoice::verify_using_payer_data
/// [`ExpandedKey`]: crate::ln::inbound_payment::ExpandedKey
pub fn deriving_payer_id(
Expand Down Expand Up @@ -1045,7 +1045,7 @@ mod tests {
.unwrap()
.build().unwrap()
.sign(recipient_sign).unwrap();
match invoice.verify(&expanded_key, &secp_ctx) {
match invoice.verify_using_metadata(&expanded_key, &secp_ctx) {
Ok(payment_id) => assert_eq!(payment_id, PaymentId([1; 32])),
Err(()) => panic!("verification failed"),
}
Expand All @@ -1062,7 +1062,7 @@ mod tests {
.unwrap()
.build().unwrap()
.sign(recipient_sign).unwrap();
assert!(invoice.verify(&expanded_key, &secp_ctx).is_err());
assert!(invoice.verify_using_metadata(&expanded_key, &secp_ctx).is_err());

// Fails verification with altered metadata
let mut tlv_stream = refund.as_tlv_stream();
Expand All @@ -1077,7 +1077,7 @@ mod tests {
.unwrap()
.build().unwrap()
.sign(recipient_sign).unwrap();
assert!(invoice.verify(&expanded_key, &secp_ctx).is_err());
assert!(invoice.verify_using_metadata(&expanded_key, &secp_ctx).is_err());
}

#[test]
Expand Down Expand Up @@ -1110,7 +1110,7 @@ mod tests {
.unwrap()
.build().unwrap()
.sign(recipient_sign).unwrap();
assert!(invoice.verify(&expanded_key, &secp_ctx).is_err());
assert!(invoice.verify_using_metadata(&expanded_key, &secp_ctx).is_err());
assert!(invoice.verify_using_payer_data(payment_id, nonce, &expanded_key, &secp_ctx));

// Fails verification with altered fields
Expand Down

0 comments on commit 2280707

Please sign in to comment.