Skip to content

Commit c89dfb1

Browse files
f derive keys from offer metadata
1 parent ad8c56b commit c89dfb1

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

lightning/src/offers/static_invoice.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -607,13 +607,13 @@ mod tests {
607607
.build()
608608
.unwrap();
609609

610-
let (_offer_id, keys_opt) = offer.verify(&expanded_key, &secp_ctx).unwrap();
611610
let invoice = StaticInvoiceBuilder::for_offer_using_keys(
612611
&offer,
613612
payment_paths.clone(),
614613
vec![blinded_path()],
615614
now,
616-
keys_opt.unwrap(),
615+
&expanded_key,
616+
&secp_ctx,
617617
)
618618
.unwrap()
619619
.build_and_sign(&secp_ctx)
@@ -642,6 +642,7 @@ mod tests {
642642
assert!(invoice.fallbacks().is_empty());
643643
assert_eq!(invoice.invoice_features(), &Bolt12InvoiceFeatures::empty());
644644

645+
let keys_opt = offer.verify(&expanded_key, &secp_ctx).unwrap().1;
645646
let message = TaggedHash::from_valid_tlv_stream_bytes(SIGNATURE_TAG, &invoice.bytes);
646647
assert!(merkle::verify_signature(
647648
&invoice.signature,
@@ -674,13 +675,13 @@ mod tests {
674675
.build()
675676
.unwrap();
676677

677-
let (_offer_id, keys_opt) = valid_offer.verify(&expanded_key, &secp_ctx).unwrap();
678678
let invoice = StaticInvoiceBuilder::for_offer_using_keys(
679679
&valid_offer,
680680
payment_paths(),
681681
vec![blinded_path()],
682682
now,
683-
keys_opt.unwrap(),
683+
&expanded_key,
684+
&secp_ctx,
684685
)
685686
.unwrap()
686687
.build_and_sign(&secp_ctx)
@@ -694,13 +695,13 @@ mod tests {
694695
.absolute_expiry(past_expiry)
695696
.build()
696697
.unwrap();
697-
let (_offer_id, keys_opt) = expired_offer.verify(&expanded_key, &secp_ctx).unwrap();
698698
if let Err(e) = StaticInvoiceBuilder::for_offer_using_keys(
699699
&expired_offer,
700700
payment_paths(),
701701
vec![blinded_path()],
702702
now,
703-
keys_opt.unwrap(),
703+
&expanded_key,
704+
&secp_ctx,
704705
)
705706
.unwrap()
706707
.build_and_sign(&secp_ctx)
@@ -732,7 +733,8 @@ mod tests {
732733
Vec::new(),
733734
vec![blinded_path()],
734735
now,
735-
keys_opt.unwrap(),
736+
&expanded_key,
737+
&secp_ctx,
736738
) {
737739
assert_eq!(e, Bolt12SemanticError::MissingPaths);
738740
} else {
@@ -745,7 +747,8 @@ mod tests {
745747
payment_paths(),
746748
Vec::new(),
747749
now,
748-
keys_opt.unwrap(),
750+
&expanded_key,
751+
&secp_ctx,
749752
) {
750753
assert_eq!(e, Bolt12SemanticError::MissingPaths);
751754
} else {
@@ -764,7 +767,8 @@ mod tests {
764767
payment_paths(),
765768
vec![blinded_path()],
766769
now,
767-
keys_opt.unwrap(),
770+
&expanded_key,
771+
&secp_ctx,
768772
) {
769773
assert_eq!(e, Bolt12SemanticError::MissingPaths);
770774
} else {
@@ -785,7 +789,6 @@ mod tests {
785789
.path(blinded_path())
786790
.build()
787791
.unwrap();
788-
let (_offer_id, keys_opt) = valid_offer.verify(&expanded_key, &secp_ctx).unwrap();
789792

790793
// Error if offer signing pubkey is missing.
791794
let mut offer_missing_signing_pubkey = valid_offer.clone();
@@ -800,14 +803,15 @@ mod tests {
800803
payment_paths(),
801804
vec![blinded_path()],
802805
now,
803-
keys_opt.unwrap(),
806+
&expanded_key,
807+
&secp_ctx,
804808
) {
805809
assert_eq!(e, Bolt12SemanticError::MissingSigningPubkey);
806810
} else {
807811
panic!("expected error")
808812
}
809813

810-
// Error if the offer's signing pubkey doesn't match the invoice's.
814+
// Error if the offer's metadata cannot be verified.
811815
let mut offer_invalid_signing_pubkey = valid_offer.clone();
812816
let mut offer_tlv_stream = offer_invalid_signing_pubkey.as_tlv_stream();
813817
let invalid_node_id = payer_pubkey();
@@ -821,9 +825,10 @@ mod tests {
821825
payment_paths(),
822826
vec![blinded_path()],
823827
now,
824-
keys_opt.unwrap(),
828+
&expanded_key,
829+
&secp_ctx,
825830
) {
826-
assert_eq!(e, Bolt12SemanticError::InvalidSigningPubkey);
831+
assert_eq!(e, Bolt12SemanticError::InvalidMetadata);
827832
} else {
828833
panic!("expected error")
829834
}
@@ -844,15 +849,14 @@ mod tests {
844849
.chain(Network::Testnet)
845850
.build()
846851
.unwrap();
847-
let (_offer_id, keys_opt) =
848-
offer_with_extra_chain.verify(&expanded_key, &secp_ctx).unwrap();
849852

850853
if let Err(e) = StaticInvoiceBuilder::for_offer_using_keys(
851854
&offer_with_extra_chain,
852855
payment_paths(),
853856
vec![blinded_path()],
854857
now,
855-
keys_opt.unwrap(),
858+
&expanded_key,
859+
&secp_ctx,
856860
) {
857861
assert_eq!(e, Bolt12SemanticError::UnexpectedChain);
858862
} else {

0 commit comments

Comments
 (0)