@@ -439,6 +439,7 @@ impl UnsignedBolt12Invoice {
439
439
bytes : self . bytes ,
440
440
contents : self . contents ,
441
441
signature,
442
+ tagged_hash : self . tagged_hash ,
442
443
} )
443
444
}
444
445
}
@@ -463,6 +464,7 @@ pub struct Bolt12Invoice {
463
464
bytes : Vec < u8 > ,
464
465
contents : InvoiceContents ,
465
466
signature : Signature ,
467
+ tagged_hash : TaggedHash ,
466
468
}
467
469
468
470
/// The contents of an [`Bolt12Invoice`] for responding to either an [`Offer`] or a [`Refund`].
@@ -707,7 +709,7 @@ impl Bolt12Invoice {
707
709
708
710
/// Hash that was used for signing the invoice.
709
711
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 ( )
711
713
}
712
714
713
715
/// 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 {
1212
1214
None => return Err ( Bolt12ParseError :: InvalidSemantics ( Bolt12SemanticError :: MissingSignature ) ) ,
1213
1215
Some ( signature) => signature,
1214
1216
} ;
1215
- let message = TaggedHash :: new ( SIGNATURE_TAG , & bytes) ;
1217
+ let tagged_hash = TaggedHash :: new ( SIGNATURE_TAG , & bytes) ;
1216
1218
let pubkey = contents. fields ( ) . signing_pubkey ;
1217
- merkle:: verify_signature ( & signature, message , pubkey) ?;
1219
+ merkle:: verify_signature ( & signature, & tagged_hash , pubkey) ?;
1218
1220
1219
- Ok ( Bolt12Invoice { bytes, contents, signature } )
1221
+ Ok ( Bolt12Invoice { bytes, contents, signature, tagged_hash } )
1220
1222
}
1221
1223
}
1222
1224
@@ -1431,7 +1433,7 @@ mod tests {
1431
1433
assert_eq ! ( invoice. signing_pubkey( ) , recipient_pubkey( ) ) ;
1432
1434
1433
1435
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( ) ) ;
1435
1437
1436
1438
let digest = Message :: from_slice ( & invoice. signable_hash ( ) ) . unwrap ( ) ;
1437
1439
let pubkey = recipient_pubkey ( ) . into ( ) ;
@@ -1528,7 +1530,7 @@ mod tests {
1528
1530
assert_eq ! ( invoice. signing_pubkey( ) , recipient_pubkey( ) ) ;
1529
1531
1530
1532
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( ) ) ;
1532
1534
1533
1535
assert_eq ! (
1534
1536
invoice. as_tlv_stream( ) ,
0 commit comments