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)]
/// # 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
/// [`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
>(
#[cfg(c_bindings)]
secp_ctx: &Secp256k1<secp256k1::All>,
) -> Result<VerifiedInvoiceRequest, ()> {
- 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))]
.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());
/// `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(
self.signing_pubkey
}
- pub(super) fn verify<T: secp256k1::Signing>(
+ pub(super) fn verify_using_metadata<T: secp256k1::Signing>(
&self, bytes: &[u8], key: &ExpandedKey, secp_ctx: &Secp256k1<T>
) -> Result<(OfferId, Option<Keypair>), ()> {
- 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<T: secp256k1::Signing>(
&self, bytes: &[u8], nonce: Nonce, key: &ExpandedKey, secp_ctx: &Secp256k1<T>
) -> Result<(OfferId, Option<Keypair>), ()> {
- 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<T: secp256k1::Signing>(
+ fn verify<T: secp256k1::Signing>(
&self, bytes: &[u8], metadata: Option<&Metadata>, key: &ExpandedKey, secp_ctx: &Secp256k1<T>
) -> Result<(OfferId, Option<Keypair>), ()> {
match metadata {
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"),
}
.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();
.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]
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();