@@ -18,6 +18,7 @@ use bitcoin::network::constants::Network;
1818use bitcoin:: util:: bip32:: { ExtendedPrivKey , ExtendedPubKey , ChildNumber } ;
1919use bitcoin:: util:: bip143;
2020
21+ use bitcoin:: bech32:: u5;
2122use bitcoin:: hashes:: { Hash , HashEngine } ;
2223use bitcoin:: hashes:: sha256:: HashEngine as Sha256State ;
2324use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
@@ -42,6 +43,7 @@ use prelude::*;
4243use core:: sync:: atomic:: { AtomicUsize , Ordering } ;
4344use io:: { self , Error } ;
4445use ln:: msgs:: { DecodeError , MAX_VALUE_MSAT } ;
46+ use util:: invoice:: construct_invoice_preimage;
4547
4648/// Used as initial key material, to be expanded into multiple secret keys (but not to be used
4749/// directly). This is used within LDK to encrypt/decrypt inbound payment data.
@@ -398,11 +400,12 @@ pub trait KeysInterface {
398400 /// you've read all of the provided bytes to ensure no corruption occurred.
399401 fn read_chan_signer ( & self , reader : & [ u8 ] ) -> Result < Self :: Signer , DecodeError > ;
400402
401- /// Sign an invoice's preimage (note that this is the preimage of the invoice, not the HTLC's
402- /// preimage). By parameterizing by the preimage instead of the hash, we allow implementors of
403+ /// Sign an invoice.
404+ /// By parameterizing by the raw invoice bytes instead of the hash, we allow implementors of
403405 /// this trait to parse the invoice and make sure they're signing what they expect, rather than
404406 /// blindly signing the hash.
405- fn sign_invoice ( & self , invoice_preimage : Vec < u8 > ) -> Result < RecoverableSignature , ( ) > ;
407+ /// The hrp is ascii bytes, while the invoice data is base32.
408+ fn sign_invoice ( & self , hrp_bytes : & [ u8 ] , invoice_data : & [ u5 ] ) -> Result < RecoverableSignature , ( ) > ;
406409
407410 /// Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
408411 ///
@@ -1092,8 +1095,9 @@ impl KeysInterface for KeysManager {
10921095 InMemorySigner :: read ( & mut io:: Cursor :: new ( reader) )
10931096 }
10941097
1095- fn sign_invoice ( & self , invoice_preimage : Vec < u8 > ) -> Result < RecoverableSignature , ( ) > {
1096- Ok ( self . secp_ctx . sign_recoverable ( & hash_to_message ! ( & Sha256 :: hash( & invoice_preimage) ) , & self . get_node_secret ( ) ) )
1098+ fn sign_invoice ( & self , hrp_bytes : & [ u8 ] , invoice_data : & [ u5 ] ) -> Result < RecoverableSignature , ( ) > {
1099+ let preimage = construct_invoice_preimage ( & hrp_bytes, & invoice_data) ;
1100+ Ok ( self . secp_ctx . sign_recoverable ( & hash_to_message ! ( & Sha256 :: hash( & preimage) ) , & self . get_node_secret ( ) ) )
10971101 }
10981102}
10991103
0 commit comments