Skip to content

Commit dab261e

Browse files
f derive keys from offer metadata
1 parent ec02b3d commit dab261e

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lightning/src/offers/offer.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,12 @@ impl Offer {
664664
pub fn expects_quantity(&self) -> bool {
665665
self.contents.expects_quantity()
666666
}
667+
668+
pub(super) fn verify<T: secp256k1::Signing>(
669+
&self, key: &ExpandedKey, secp_ctx: &Secp256k1<T>
670+
) -> Result<(OfferId, Option<Keypair>), ()> {
671+
self.contents.verify(&self.bytes, key, secp_ctx)
672+
}
667673
}
668674

669675
macro_rules! request_invoice_derived_payer_id { ($self: ident, $builder: ty) => {

lightning/src/offers/static_invoice.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use crate::blinded_path::BlindedPath;
1313
use crate::io;
1414
use crate::ln::features::{Bolt12InvoiceFeatures, OfferFeatures};
15+
use crate::ln::inbound_payment::ExpandedKey;
1516
use crate::ln::msgs::DecodeError;
1617
use crate::offers::invoice::{
1718
check_invoice_signing_pubkey, construct_payment_paths, filter_fallbacks, BlindedPathIter,
@@ -94,9 +95,10 @@ impl<'a> StaticInvoiceBuilder<'a> {
9495
///
9596
/// Unless [`StaticInvoiceBuilder::relative_expiry`] is set, the invoice will expire 24 hours
9697
/// after `created_at`.
97-
pub fn for_offer_using_keys(
98+
pub fn for_offer_using_keys<T: secp256k1::Signing>(
9899
offer: &'a Offer, payment_paths: Vec<(BlindedPayInfo, BlindedPath)>,
99-
message_paths: Vec<BlindedPath>, created_at: Duration, keys: Keypair,
100+
message_paths: Vec<BlindedPath>, created_at: Duration, expanded_key: &ExpandedKey,
101+
secp_ctx: &Secp256k1<T>,
100102
) -> Result<Self, Bolt12SemanticError> {
101103
if offer.chains().len() > 1 {
102104
return Err(Bolt12SemanticError::UnexpectedChain);
@@ -108,6 +110,13 @@ impl<'a> StaticInvoiceBuilder<'a> {
108110

109111
let offer_signing_pubkey =
110112
offer.signing_pubkey().ok_or(Bolt12SemanticError::MissingSigningPubkey)?;
113+
114+
let keys = offer
115+
.verify(&expanded_key, &secp_ctx)
116+
.map_err(|()| Bolt12SemanticError::InvalidMetadata)?
117+
.1
118+
.ok_or(Bolt12SemanticError::MissingSigningPubkey)?;
119+
111120
let signing_pubkey = keys.public_key();
112121
if signing_pubkey != offer_signing_pubkey {
113122
return Err(Bolt12SemanticError::InvalidSigningPubkey);

0 commit comments

Comments
 (0)