Skip to content

Optional description for Offer and Refund #3018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Allow parsing Offer without signing_pubkey
If an offer has at least one path, it may omit the signing pubkey and
use the blinded node id of the last hop of a path to sign an invoice.
Allow parsing such offers but not yet creating them.
  • Loading branch information
jkczyz committed Apr 26, 2024
commit 94d5af663d74177079124f15b40b65e16fbb1b27
36 changes: 31 additions & 5 deletions lightning/src/offers/offer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,12 @@ macro_rules! offer_builder_test_methods { (
$return_value
}

#[cfg_attr(c_bindings, allow(dead_code))]
pub(crate) fn clear_signing_pubkey($($self_mut)* $self: $self_type) -> $return_type {
$self.offer.signing_pubkey = None;
$return_value
}

#[cfg_attr(c_bindings, allow(dead_code))]
pub(super) fn build_unchecked($self: $self_type) -> Offer {
$self.build_without_checks()
Expand Down Expand Up @@ -1093,9 +1099,10 @@ impl TryFrom<OfferTlvStream> for OfferContents {
Some(n) => Quantity::Bounded(NonZeroU64::new(n).unwrap()),
};

let signing_pubkey = match node_id {
None => return Err(Bolt12SemanticError::MissingSigningPubkey),
Some(node_id) => Some(node_id),
let (signing_pubkey, paths) = match (node_id, paths) {
(None, None) => return Err(Bolt12SemanticError::MissingSigningPubkey),
(_, Some(paths)) if paths.is_empty() => return Err(Bolt12SemanticError::MissingPaths),
(node_id, paths) => (node_id, paths),
};

Ok(OfferContents {
Expand Down Expand Up @@ -1662,12 +1669,31 @@ mod tests {
panic!("error parsing offer: {:?}", e);
}

let offer = OfferBuilder::new("foo".into(), pubkey(42))
.path(BlindedPath {
introduction_node: IntroductionNode::NodeId(pubkey(40)),
blinding_point: pubkey(41),
blinded_hops: vec![
BlindedHop { blinded_node_id: pubkey(43), encrypted_payload: vec![0; 43] },
BlindedHop { blinded_node_id: pubkey(44), encrypted_payload: vec![0; 44] },
],
})
.clear_signing_pubkey()
.build()
.unwrap();
if let Err(e) = offer.to_string().parse::<Offer>() {
panic!("error parsing offer: {:?}", e);
}

let mut builder = OfferBuilder::new("foo".into(), pubkey(42));
builder.offer.paths = Some(vec![]);

let offer = builder.build().unwrap();
if let Err(e) = offer.to_string().parse::<Offer>() {
panic!("error parsing offer: {:?}", e);
match offer.to_string().parse::<Offer>() {
Ok(_) => panic!("expected error"),
Err(e) => {
assert_eq!(e, Bolt12ParseError::InvalidSemantics(Bolt12SemanticError::MissingPaths));
},
}
}

Expand Down