@@ -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,8 @@ 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:: invoice:: UnsignedBolt12Invoice ;
46+ use crate :: offers:: invoice_request:: UnsignedInvoiceRequest ;
4447
4548use crate :: prelude:: * ;
4649use core:: convert:: TryInto ;
@@ -619,6 +622,36 @@ pub trait NodeSigner {
619622 /// Errors if the [`Recipient`] variant is not supported by the implementation.
620623 fn sign_invoice ( & self , hrp_bytes : & [ u8 ] , invoice_data : & [ u5 ] , recipient : Recipient ) -> Result < RecoverableSignature , ( ) > ;
621624
625+ /// Signs the [`TaggedHash`] of a BOLT 12 invoice request.
626+ ///
627+ /// May be called by a function passed to [`UnsignedInvoiceRequest::sign`] where
628+ /// `invoice_request` is the callee.
629+ ///
630+ /// Implementors may check that the `invoice_request` is expected rather than blindly signing
631+ /// the tagged hash. An `Ok` result should sign `invoice_request.tagged_hash().as_digest()` with
632+ /// the node's signing key or an ephemeral key to preserve privacy, whichever is associated with
633+ /// [`UnsignedInvoiceRequest::payer_id`].
634+ ///
635+ /// [`TaggedHash`]: crate::offers::merkle::TaggedHash
636+ fn sign_bolt12_invoice_request (
637+ & self , invoice_request : & UnsignedInvoiceRequest
638+ ) -> Result < schnorr:: Signature , ( ) > ;
639+
640+ /// Signs the [`TaggedHash`] of a BOLT 12 invoice.
641+ ///
642+ /// May be called by a function passed to [`UnsignedBolt12Invoice::sign`] where `invoice` is the
643+ /// callee.
644+ ///
645+ /// Implementors may check that the `invoice` is expected rather than blindly signing the tagged
646+ /// hash. An `Ok` result should sign `invoice.tagged_hash().as_digest()` with the node's signing
647+ /// key or an ephemeral key to preserve privacy, whichever is associated with
648+ /// [`UnsignedBolt12Invoice::signing_pubkey`].
649+ ///
650+ /// [`TaggedHash`]: crate::offers::merkle::TaggedHash
651+ fn sign_bolt12_invoice (
652+ & self , invoice : & UnsignedBolt12Invoice
653+ ) -> Result < schnorr:: Signature , ( ) > ;
654+
622655 /// Sign a gossip message.
623656 ///
624657 /// Note that if this fails, LDK may panic and the message will not be broadcast to the network
@@ -1449,6 +1482,24 @@ impl NodeSigner for KeysManager {
14491482 Ok ( self . secp_ctx . sign_ecdsa_recoverable ( & hash_to_message ! ( & Sha256 :: hash( & preimage) ) , secret) )
14501483 }
14511484
1485+ fn sign_bolt12_invoice_request (
1486+ & self , invoice_request : & UnsignedInvoiceRequest
1487+ ) -> Result < schnorr:: Signature , ( ) > {
1488+ let message = invoice_request. tagged_hash ( ) . as_digest ( ) ;
1489+ let keys = KeyPair :: from_secret_key ( & self . secp_ctx , & self . node_secret ) ;
1490+ let aux_rand = self . get_secure_random_bytes ( ) ;
1491+ Ok ( self . secp_ctx . sign_schnorr_with_aux_rand ( message, & keys, & aux_rand) )
1492+ }
1493+
1494+ fn sign_bolt12_invoice (
1495+ & self , invoice : & UnsignedBolt12Invoice
1496+ ) -> Result < schnorr:: Signature , ( ) > {
1497+ let message = invoice. tagged_hash ( ) . as_digest ( ) ;
1498+ let keys = KeyPair :: from_secret_key ( & self . secp_ctx , & self . node_secret ) ;
1499+ let aux_rand = self . get_secure_random_bytes ( ) ;
1500+ Ok ( self . secp_ctx . sign_schnorr_with_aux_rand ( message, & keys, & aux_rand) )
1501+ }
1502+
14521503 fn sign_gossip_message ( & self , msg : UnsignedGossipMessage ) -> Result < Signature , ( ) > {
14531504 let msg_hash = hash_to_message ! ( & Sha256dHash :: hash( & msg. encode( ) [ ..] ) [ ..] ) ;
14541505 Ok ( self . secp_ctx . sign_ecdsa ( & msg_hash, & self . node_secret ) )
@@ -1557,6 +1608,18 @@ impl NodeSigner for PhantomKeysManager {
15571608 Ok ( self . inner . secp_ctx . sign_ecdsa_recoverable ( & hash_to_message ! ( & Sha256 :: hash( & preimage) ) , secret) )
15581609 }
15591610
1611+ fn sign_bolt12_invoice_request (
1612+ & self , invoice_request : & UnsignedInvoiceRequest
1613+ ) -> Result < schnorr:: Signature , ( ) > {
1614+ self . inner . sign_bolt12_invoice_request ( invoice_request)
1615+ }
1616+
1617+ fn sign_bolt12_invoice (
1618+ & self , invoice : & UnsignedBolt12Invoice
1619+ ) -> Result < schnorr:: Signature , ( ) > {
1620+ self . inner . sign_bolt12_invoice ( invoice)
1621+ }
1622+
15601623 fn sign_gossip_message ( & self , msg : UnsignedGossipMessage ) -> Result < Signature , ( ) > {
15611624 self . inner . sign_gossip_message ( msg)
15621625 }
0 commit comments