invoice.verify_using_metadata(expanded_key, secp_ctx)
},
OffersContext::OutboundPayment { payment_id, nonce } => {
- invoice
- .verify_using_payer_data(*payment_id, *nonce, expanded_key, secp_ctx)
- .then(|| *payment_id)
- .ok_or(())
+ invoice.verify_using_payer_data(*payment_id, *nonce, expanded_key, secp_ctx)
},
_ => Err(()),
}
/// sent through.
pub fn verify_using_payer_data<T: secp256k1::Signing>(
&self, payment_id: PaymentId, nonce: Nonce, key: &ExpandedKey, secp_ctx: &Secp256k1<T>
- ) -> bool {
+ ) -> Result<PaymentId, ()> {
let metadata = Metadata::payer_data(payment_id, nonce, key);
- match self.contents.verify(TlvStream::new(&self.bytes), &metadata, key, secp_ctx) {
- Ok(extracted_payment_id) => payment_id == extracted_payment_id,
- Err(()) => false,
- }
+ self.contents.verify(TlvStream::new(&self.bytes), &metadata, key, secp_ctx)
+ .and_then(|extracted_payment_id| (payment_id == extracted_payment_id)
+ .then(|| payment_id)
+ .ok_or(())
+ )
}
pub(crate) fn as_tlv_stream(&self) -> FullInvoiceTlvStreamRef {
Ok(payment_id) => assert_eq!(payment_id, PaymentId([1; 32])),
Err(()) => panic!("verification failed"),
}
- assert!(!invoice.verify_using_payer_data(payment_id, nonce, &expanded_key, &secp_ctx));
+ assert!(
+ invoice.verify_using_payer_data(payment_id, nonce, &expanded_key, &secp_ctx).is_err()
+ );
// Fails verification with altered fields
let (
.build().unwrap()
.sign(recipient_sign).unwrap();
assert!(invoice.verify_using_metadata(&expanded_key, &secp_ctx).is_err());
- assert!(invoice.verify_using_payer_data(payment_id, nonce, &expanded_key, &secp_ctx));
+ assert!(
+ invoice.verify_using_payer_data(payment_id, nonce, &expanded_key, &secp_ctx).is_ok()
+ );
// Fails verification with altered fields
let (
signature_tlv_stream.write(&mut encoded_invoice).unwrap();
let invoice = Bolt12Invoice::try_from(encoded_invoice).unwrap();
- assert!(!invoice.verify_using_payer_data(payment_id, nonce, &expanded_key, &secp_ctx));
+ assert!(
+ invoice.verify_using_payer_data(payment_id, nonce, &expanded_key, &secp_ctx).is_err()
+ );
// Fails verification with altered payer id
let (
signature_tlv_stream.write(&mut encoded_invoice).unwrap();
let invoice = Bolt12Invoice::try_from(encoded_invoice).unwrap();
- assert!(!invoice.verify_using_payer_data(payment_id, nonce, &expanded_key, &secp_ctx));
+ assert!(
+ invoice.verify_using_payer_data(payment_id, nonce, &expanded_key, &secp_ctx).is_err()
+ );
}
#[test]
Ok(payment_id) => assert_eq!(payment_id, PaymentId([1; 32])),
Err(()) => panic!("verification failed"),
}
- assert!(!invoice.verify_using_payer_data(payment_id, nonce, &expanded_key, &secp_ctx));
+ assert!(
+ invoice.verify_using_payer_data(payment_id, nonce, &expanded_key, &secp_ctx).is_err()
+ );
let mut tlv_stream = refund.as_tlv_stream();
tlv_stream.2.amount = Some(2000);
.build().unwrap()
.sign(recipient_sign).unwrap();
assert!(invoice.verify_using_metadata(&expanded_key, &secp_ctx).is_err());
- assert!(invoice.verify_using_payer_data(payment_id, nonce, &expanded_key, &secp_ctx));
+ assert!(
+ invoice.verify_using_payer_data(payment_id, nonce, &expanded_key, &secp_ctx).is_ok()
+ );
// Fails verification with altered fields
let mut tlv_stream = refund.as_tlv_stream();
.unwrap()
.build().unwrap()
.sign(recipient_sign).unwrap();
- assert!(!invoice.verify_using_payer_data(payment_id, nonce, &expanded_key, &secp_ctx));
+ assert!(
+ invoice.verify_using_payer_data(payment_id, nonce, &expanded_key, &secp_ctx).is_err()
+ );
// Fails verification with altered payer_id
let mut tlv_stream = refund.as_tlv_stream();
.unwrap()
.build().unwrap()
.sign(recipient_sign).unwrap();
- assert!(!invoice.verify_using_payer_data(payment_id, nonce, &expanded_key, &secp_ctx));
+ assert!(
+ invoice.verify_using_payer_data(payment_id, nonce, &expanded_key, &secp_ctx).is_err()
+ );
}
#[test]