@@ -26,9 +26,10 @@ use bitcoin::hashes::sha256::Hash as Sha256;
2626use bitcoin:: hashes:: sha256d:: Hash as Sha256dHash ;
2727use bitcoin:: hash_types:: WPubkeyHash ;
2828
29- use bitcoin:: secp256k1:: { PublicKey , Scalar , Secp256k1 , SecretKey , Signing } ;
29+ use bitcoin:: secp256k1:: { KeyPair , PublicKey , Scalar , Secp256k1 , SecretKey , Signing } ;
3030use bitcoin:: secp256k1:: ecdh:: SharedSecret ;
3131use bitcoin:: secp256k1:: ecdsa:: { RecoverableSignature , Signature } ;
32+ use bitcoin:: secp256k1:: schnorr;
3233use bitcoin:: { PackedLockTime , secp256k1, Sequence , Witness } ;
3334
3435use crate :: util:: transaction_utils;
@@ -41,6 +42,7 @@ use crate::ln::{chan_utils, PaymentPreimage};
4142use crate :: ln:: chan_utils:: { HTLCOutputInCommitment , make_funding_redeemscript, ChannelPublicKeys , HolderCommitmentTransaction , ChannelTransactionParameters , CommitmentTransaction , ClosingTransaction } ;
4243use crate :: ln:: msgs:: { UnsignedChannelAnnouncement , UnsignedGossipMessage } ;
4344use crate :: ln:: script:: ShutdownScript ;
45+ use crate :: offers:: merkle:: TaggedHash ;
4446
4547use crate :: prelude:: * ;
4648use core:: convert:: TryInto ;
@@ -619,6 +621,15 @@ pub trait NodeSigner {
619621 /// Errors if the [`Recipient`] variant is not supported by the implementation.
620622 fn sign_invoice ( & self , hrp_bytes : & [ u8 ] , invoice_data : & [ u5 ] , recipient : Recipient ) -> Result < RecoverableSignature , ( ) > ;
621623
624+ /// Signs a BOLT 12 message.
625+ ///
626+ /// See [`SignFunction`] for details.
627+ ///
628+ /// [`SignFunction`]: crate::offers::merkle::SignFunction
629+ fn sign_bolt12_message (
630+ & self , message : & TaggedHash , metadata : & [ u8 ]
631+ ) -> Result < schnorr:: Signature , ( ) > ;
632+
622633 /// Sign a gossip message.
623634 ///
624635 /// Note that if this fails, LDK may panic and the message will not be broadcast to the network
@@ -1449,6 +1460,14 @@ impl NodeSigner for KeysManager {
14491460 Ok ( self . secp_ctx . sign_ecdsa_recoverable ( & hash_to_message ! ( & Sha256 :: hash( & preimage) ) , secret) )
14501461 }
14511462
1463+ fn sign_bolt12_message (
1464+ & self , message : & TaggedHash , _metadata : & [ u8 ]
1465+ ) -> Result < schnorr:: Signature , ( ) > {
1466+ let keys = KeyPair :: from_secret_key ( & self . secp_ctx , & self . node_secret ) ;
1467+ let aux_rand = self . get_secure_random_bytes ( ) ;
1468+ Ok ( self . secp_ctx . sign_schnorr_with_aux_rand ( & message. to_digest ( ) , & keys, & aux_rand) )
1469+ }
1470+
14521471 fn sign_gossip_message ( & self , msg : UnsignedGossipMessage ) -> Result < Signature , ( ) > {
14531472 let msg_hash = hash_to_message ! ( & Sha256dHash :: hash( & msg. encode( ) [ ..] ) [ ..] ) ;
14541473 Ok ( self . secp_ctx . sign_ecdsa ( & msg_hash, & self . node_secret ) )
@@ -1557,6 +1576,12 @@ impl NodeSigner for PhantomKeysManager {
15571576 Ok ( self . inner . secp_ctx . sign_ecdsa_recoverable ( & hash_to_message ! ( & Sha256 :: hash( & preimage) ) , secret) )
15581577 }
15591578
1579+ fn sign_bolt12_message (
1580+ & self , message : & TaggedHash , metadata : & [ u8 ]
1581+ ) -> Result < schnorr:: Signature , ( ) > {
1582+ self . inner . sign_bolt12_message ( message, metadata)
1583+ }
1584+
15601585 fn sign_gossip_message ( & self , msg : UnsignedGossipMessage ) -> Result < Signature , ( ) > {
15611586 self . inner . sign_gossip_message ( msg)
15621587 }
0 commit comments