@@ -223,11 +223,11 @@ impl<'a> UnsignedInvoiceRequest<'a> {
223
223
unsigned_tlv_stream. write ( & mut bytes) . unwrap ( ) ;
224
224
225
225
let pubkey = self . invoice_request . payer_id ;
226
- let signature = Some ( merkle:: sign_message ( sign, SIGNATURE_TAG , & bytes, pubkey) ?) ;
226
+ let signature = merkle:: sign_message ( sign, SIGNATURE_TAG , & bytes, pubkey) ?;
227
227
228
228
// Append the signature TLV record to the bytes.
229
229
let signature_tlv_stream = SignatureTlvStreamRef {
230
- signature : signature . as_ref ( ) ,
230
+ signature : Some ( & signature ) ,
231
231
} ;
232
232
signature_tlv_stream. write ( & mut bytes) . unwrap ( ) ;
233
233
@@ -249,7 +249,7 @@ impl<'a> UnsignedInvoiceRequest<'a> {
249
249
pub struct InvoiceRequest {
250
250
pub ( super ) bytes : Vec < u8 > ,
251
251
contents : InvoiceRequestContents ,
252
- signature : Option < Signature > ,
252
+ signature : Signature ,
253
253
}
254
254
255
255
/// The contents of an [`InvoiceRequest`], which may be shared with an `Invoice`.
@@ -311,7 +311,7 @@ impl InvoiceRequest {
311
311
/// Signature of the invoice request using [`payer_id`].
312
312
///
313
313
/// [`payer_id`]: Self::payer_id
314
- pub fn signature ( & self ) -> Option < Signature > {
314
+ pub fn signature ( & self ) -> Signature {
315
315
self . signature
316
316
}
317
317
@@ -320,7 +320,7 @@ impl InvoiceRequest {
320
320
let ( payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream) =
321
321
self . contents . as_tlv_stream ( ) ;
322
322
let signature_tlv_stream = SignatureTlvStreamRef {
323
- signature : self . signature . as_ref ( ) ,
323
+ signature : Some ( & self . signature ) ,
324
324
} ;
325
325
( payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream, signature_tlv_stream)
326
326
}
@@ -421,9 +421,11 @@ impl TryFrom<Vec<u8>> for InvoiceRequest {
421
421
( payer_tlv_stream, offer_tlv_stream, invoice_request_tlv_stream)
422
422
) ?;
423
423
424
- if let Some ( signature) = & signature {
425
- merkle:: verify_signature ( signature, SIGNATURE_TAG , & bytes, contents. payer_id ) ?;
426
- }
424
+ let signature = match signature {
425
+ None => return Err ( ParseError :: InvalidSemantics ( SemanticError :: MissingSignature ) ) ,
426
+ Some ( signature) => signature,
427
+ } ;
428
+ merkle:: verify_signature ( & signature, SIGNATURE_TAG , & bytes, contents. payer_id ) ?;
427
429
428
430
Ok ( InvoiceRequest { bytes, contents, signature } )
429
431
}
@@ -471,7 +473,7 @@ impl TryFrom<PartialInvoiceRequestTlvStream> for InvoiceRequestContents {
471
473
472
474
#[ cfg( test) ]
473
475
mod tests {
474
- use super :: { InvoiceRequest , InvoiceRequestTlvStreamRef } ;
476
+ use super :: { InvoiceRequest , InvoiceRequestTlvStreamRef , SIGNATURE_TAG } ;
475
477
476
478
use bitcoin:: blockdata:: constants:: ChainHash ;
477
479
use bitcoin:: network:: constants:: Network ;
@@ -483,7 +485,7 @@ mod tests {
483
485
use core:: time:: Duration ;
484
486
use crate :: ln:: features:: InvoiceRequestFeatures ;
485
487
use crate :: ln:: msgs:: { DecodeError , MAX_VALUE_MSAT } ;
486
- use crate :: offers:: merkle:: { SignError , SignatureTlvStreamRef } ;
488
+ use crate :: offers:: merkle:: { SignError , SignatureTlvStreamRef , self } ;
487
489
use crate :: offers:: offer:: { Amount , OfferBuilder , OfferTlvStreamRef , Quantity } ;
488
490
use crate :: offers:: parse:: { ParseError , SemanticError } ;
489
491
use crate :: offers:: payer:: PayerTlvStreamRef ;
@@ -536,7 +538,11 @@ mod tests {
536
538
assert_eq ! ( invoice_request. quantity( ) , None ) ;
537
539
assert_eq ! ( invoice_request. payer_id( ) , payer_pubkey( ) ) ;
538
540
assert_eq ! ( invoice_request. payer_note( ) , None ) ;
539
- assert ! ( invoice_request. signature( ) . is_some( ) ) ;
541
+ assert ! (
542
+ merkle:: verify_signature(
543
+ & invoice_request. signature, SIGNATURE_TAG , & invoice_request. bytes, payer_pubkey( )
544
+ ) . is_ok( )
545
+ ) ;
540
546
541
547
assert_eq ! (
542
548
invoice_request. as_tlv_stream( ) ,
@@ -563,7 +569,7 @@ mod tests {
563
569
payer_id: Some ( & payer_pubkey( ) ) ,
564
570
payer_note: None ,
565
571
} ,
566
- SignatureTlvStreamRef { signature: invoice_request. signature( ) . as_ref ( ) } ,
572
+ SignatureTlvStreamRef { signature: Some ( & invoice_request. signature( ) ) } ,
567
573
) ,
568
574
) ;
569
575
@@ -1222,7 +1228,7 @@ mod tests {
1222
1228
}
1223
1229
1224
1230
#[ test]
1225
- fn parses_invoice_request_without_signature ( ) {
1231
+ fn fails_parsing_invoice_request_without_signature ( ) {
1226
1232
let mut buffer = Vec :: new ( ) ;
1227
1233
OfferBuilder :: new ( "foo" . into ( ) , recipient_pubkey ( ) )
1228
1234
. amount_msats ( 1000 )
@@ -1232,8 +1238,9 @@ mod tests {
1232
1238
. invoice_request
1233
1239
. write ( & mut buffer) . unwrap ( ) ;
1234
1240
1235
- if let Err ( e) = InvoiceRequest :: try_from ( buffer) {
1236
- panic ! ( "error parsing invoice_request: {:?}" , e) ;
1241
+ match InvoiceRequest :: try_from ( buffer) {
1242
+ Ok ( _) => panic ! ( "expected error" ) ,
1243
+ Err ( e) => assert_eq ! ( e, ParseError :: InvalidSemantics ( SemanticError :: MissingSignature ) ) ,
1237
1244
}
1238
1245
}
1239
1246
0 commit comments