@@ -922,8 +922,9 @@ mod tests {
922
922
use super :: { InvoiceRequest , InvoiceRequestTlvStreamRef , SIGNATURE_TAG , UnsignedInvoiceRequest } ;
923
923
924
924
use bitcoin:: blockdata:: constants:: ChainHash ;
925
+ use bitcoin:: hashes:: { sha256, Hash } ;
925
926
use bitcoin:: network:: constants:: Network ;
926
- use bitcoin:: secp256k1:: { KeyPair , Secp256k1 , SecretKey , self } ;
927
+ use bitcoin:: secp256k1:: { KeyPair , Message , Secp256k1 , SecretKey , self } ;
927
928
use core:: convert:: { Infallible , TryFrom } ;
928
929
use core:: num:: NonZeroU64 ;
929
930
#[ cfg( feature = "std" ) ]
@@ -934,7 +935,7 @@ mod tests {
934
935
use crate :: ln:: inbound_payment:: ExpandedKey ;
935
936
use crate :: ln:: msgs:: { DecodeError , MAX_VALUE_MSAT } ;
936
937
use crate :: offers:: invoice:: { Bolt12Invoice , SIGNATURE_TAG as INVOICE_SIGNATURE_TAG } ;
937
- use crate :: offers:: merkle:: { SignError , SignatureTlvStreamRef , TaggedHash , self } ;
938
+ use crate :: offers:: merkle:: { tagged_hash , SignError , SignatureTlvStreamRef , TaggedHash , self } ;
938
939
use crate :: offers:: offer:: { Amount , OfferBuilder , OfferTlvStreamRef , Quantity } ;
939
940
use crate :: offers:: parse:: { Bolt12ParseError , Bolt12SemanticError } ;
940
941
use crate :: offers:: payer:: PayerTlvStreamRef ;
@@ -1537,6 +1538,23 @@ mod tests {
1537
1538
assert_eq ! ( tlv_stream. payer_note, Some ( & String :: from( "baz" ) ) ) ;
1538
1539
}
1539
1540
1541
+ #[ test]
1542
+ fn compute_tagged_hash ( ) {
1543
+ let unsigned_invoice_request = OfferBuilder :: new ( "foo" . into ( ) , recipient_pubkey ( ) )
1544
+ . amount_msats ( 1000 )
1545
+ . build ( ) . unwrap ( )
1546
+ . request_invoice ( vec ! [ 1 ; 32 ] , payer_pubkey ( ) ) . unwrap ( )
1547
+ . payer_note ( "bar" . into ( ) )
1548
+ . build ( ) . unwrap ( ) ;
1549
+
1550
+ // Simply test that we can grab the tag and merkle root exposed by the accessor
1551
+ // functions, then use them tosuccesfully compute a tagged hash.
1552
+ let taggedhash = unsigned_invoice_request. as_ref ( ) ;
1553
+ let tag = sha256:: Hash :: hash ( taggedhash. tag ( ) . as_bytes ( ) ) ;
1554
+ let _ = Message :: from_slice ( & tagged_hash ( tag, taggedhash. merkle_root_hash ( ) ) )
1555
+ . unwrap ( ) ;
1556
+ }
1557
+
1540
1558
#[ test]
1541
1559
fn fails_signing_invoice_request ( ) {
1542
1560
match OfferBuilder :: new ( "foo" . into ( ) , recipient_pubkey ( ) )
0 commit comments