@@ -26,6 +26,7 @@ use bitcoin::hash_types::WPubkeyHash;
2626
2727use bitcoin:: secp256k1:: key:: { SecretKey , PublicKey } ;
2828use bitcoin:: secp256k1:: { Secp256k1 , Signature , Signing } ;
29+ use bitcoin:: secp256k1:: recovery:: RecoverableSignature ;
2930use bitcoin:: secp256k1;
3031
3132use util:: { byte_utils, transaction_utils} ;
@@ -391,6 +392,12 @@ pub trait KeysInterface: Send + Sync {
391392 /// contain no versioning scheme. You may wish to include your own version prefix and ensure
392393 /// you've read all of the provided bytes to ensure no corruption occurred.
393394 fn read_chan_signer ( & self , reader : & [ u8 ] ) -> Result < Self :: Signer , DecodeError > ;
395+
396+ /// Sign an invoice's preimage (note that this is the preimage of the invoice, not the HTLC's
397+ /// preimage). By parameterizing by the preimage instead of the hash, we allow implementors of
398+ /// this trait to parse the invoice and make sure they're signing what they expect, rather than
399+ /// blindly signing the hash.
400+ fn sign_invoice ( & self , invoice_preimage : Vec < u8 > ) -> Result < RecoverableSignature , ( ) > ;
394401}
395402
396403#[ derive( Clone ) ]
@@ -1047,6 +1054,10 @@ impl KeysInterface for KeysManager {
10471054 fn read_chan_signer ( & self , reader : & [ u8 ] ) -> Result < Self :: Signer , DecodeError > {
10481055 InMemorySigner :: read ( & mut std:: io:: Cursor :: new ( reader) )
10491056 }
1057+
1058+ fn sign_invoice ( & self , invoice_preimage : Vec < u8 > ) -> Result < RecoverableSignature , ( ) > {
1059+ Ok ( self . secp_ctx . sign_recoverable ( & hash_to_message ! ( & Sha256 :: hash( & invoice_preimage) ) , & self . get_node_secret ( ) ) )
1060+ }
10501061}
10511062
10521063// Ensure that BaseSign can have a vtable
0 commit comments