mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-24 15:02:20 +01:00
Rename Bolt12Invoice::verify
This commit is contained in:
parent
df5d7ea7b3
commit
718bc47664
5 changed files with 18 additions and 17 deletions
|
@ -4220,7 +4220,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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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"),
|
||||
}
|
||||
|
@ -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 (
|
||||
|
@ -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]
|
||||
|
@ -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
|
||||
|
|
|
@ -685,8 +685,9 @@ 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.
|
||||
///
|
||||
|
@ -694,7 +695,7 @@ macro_rules! request_invoice_derived_payer_id { ($self: ident, $builder: ty) =>
|
|||
///
|
||||
/// [`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,
|
||||
|
|
|
@ -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(
|
||||
|
@ -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"),
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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]
|
||||
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue