@@ -439,6 +439,7 @@ impl UnsignedBolt12Invoice {
439439 bytes : self . bytes ,
440440 contents : self . contents ,
441441 signature,
442+ tagged_hash : self . tagged_hash ,
442443 } )
443444 }
444445}
@@ -463,6 +464,7 @@ pub struct Bolt12Invoice {
463464 bytes : Vec < u8 > ,
464465 contents : InvoiceContents ,
465466 signature : Signature ,
467+ tagged_hash : TaggedHash ,
466468}
467469
468470/// The contents of an [`Bolt12Invoice`] for responding to either an [`Offer`] or a [`Refund`].
@@ -707,7 +709,7 @@ impl Bolt12Invoice {
707709
708710 /// Hash that was used for signing the invoice.
709711 pub fn signable_hash ( & self ) -> [ u8 ; 32 ] {
710- merkle :: message_digest ( SIGNATURE_TAG , & self . bytes ) . as_ref ( ) . clone ( )
712+ self . tagged_hash . as_digest ( ) . as_ref ( ) . clone ( )
711713 }
712714
713715 /// Verifies that the invoice was for a request or refund created using the given key. Returns
@@ -1212,11 +1214,11 @@ impl TryFrom<ParsedMessage<FullInvoiceTlvStream>> for Bolt12Invoice {
12121214 None => return Err ( Bolt12ParseError :: InvalidSemantics ( Bolt12SemanticError :: MissingSignature ) ) ,
12131215 Some ( signature) => signature,
12141216 } ;
1215- let message = TaggedHash :: new ( SIGNATURE_TAG , & bytes) ;
1217+ let tagged_hash = TaggedHash :: new ( SIGNATURE_TAG , & bytes) ;
12161218 let pubkey = contents. fields ( ) . signing_pubkey ;
1217- merkle:: verify_signature ( & signature, message , pubkey) ?;
1219+ merkle:: verify_signature ( & signature, & tagged_hash , pubkey) ?;
12181220
1219- Ok ( Bolt12Invoice { bytes, contents, signature } )
1221+ Ok ( Bolt12Invoice { bytes, contents, signature, tagged_hash } )
12201222 }
12211223}
12221224
@@ -1431,7 +1433,7 @@ mod tests {
14311433 assert_eq ! ( invoice. signing_pubkey( ) , recipient_pubkey( ) ) ;
14321434
14331435 let message = TaggedHash :: new ( SIGNATURE_TAG , & invoice. bytes ) ;
1434- assert ! ( merkle:: verify_signature( & invoice. signature, message, recipient_pubkey( ) ) . is_ok( ) ) ;
1436+ assert ! ( merkle:: verify_signature( & invoice. signature, & message, recipient_pubkey( ) ) . is_ok( ) ) ;
14351437
14361438 let digest = Message :: from_slice ( & invoice. signable_hash ( ) ) . unwrap ( ) ;
14371439 let pubkey = recipient_pubkey ( ) . into ( ) ;
@@ -1528,7 +1530,7 @@ mod tests {
15281530 assert_eq ! ( invoice. signing_pubkey( ) , recipient_pubkey( ) ) ;
15291531
15301532 let message = TaggedHash :: new ( SIGNATURE_TAG , & invoice. bytes ) ;
1531- assert ! ( merkle:: verify_signature( & invoice. signature, message, recipient_pubkey( ) ) . is_ok( ) ) ;
1533+ assert ! ( merkle:: verify_signature( & invoice. signature, & message, recipient_pubkey( ) ) . is_ok( ) ) ;
15321534
15331535 assert_eq ! (
15341536 invoice. as_tlv_stream( ) ,
0 commit comments