@@ -26,9 +26,10 @@ use bitcoin::hashes::sha256::Hash as Sha256;
26
26
use bitcoin:: hashes:: sha256d:: Hash as Sha256dHash ;
27
27
use bitcoin:: hash_types:: WPubkeyHash ;
28
28
29
- use bitcoin:: secp256k1:: { PublicKey , Scalar , Secp256k1 , SecretKey , Signing } ;
29
+ use bitcoin:: secp256k1:: { KeyPair , PublicKey , Scalar , Secp256k1 , SecretKey , Signing } ;
30
30
use bitcoin:: secp256k1:: ecdh:: SharedSecret ;
31
31
use bitcoin:: secp256k1:: ecdsa:: { RecoverableSignature , Signature } ;
32
+ use bitcoin:: secp256k1:: schnorr;
32
33
use bitcoin:: { PackedLockTime , secp256k1, Sequence , Witness } ;
33
34
34
35
use crate :: util:: transaction_utils;
@@ -41,6 +42,7 @@ use crate::ln::{chan_utils, PaymentPreimage};
41
42
use crate :: ln:: chan_utils:: { HTLCOutputInCommitment , make_funding_redeemscript, ChannelPublicKeys , HolderCommitmentTransaction , ChannelTransactionParameters , CommitmentTransaction , ClosingTransaction } ;
42
43
use crate :: ln:: msgs:: { UnsignedChannelAnnouncement , UnsignedGossipMessage } ;
43
44
use crate :: ln:: script:: ShutdownScript ;
45
+ use crate :: offers:: invoice:: UnsignedBolt12Invoice ;
44
46
45
47
use crate :: prelude:: * ;
46
48
use core:: convert:: TryInto ;
@@ -619,6 +621,20 @@ pub trait NodeSigner {
619
621
/// Errors if the [`Recipient`] variant is not supported by the implementation.
620
622
fn sign_invoice ( & self , hrp_bytes : & [ u8 ] , invoice_data : & [ u5 ] , recipient : Recipient ) -> Result < RecoverableSignature , ( ) > ;
621
623
624
+ /// Signs the [`TaggedHash`] of a BOLT 12 invoice.
625
+ ///
626
+ /// May be called by a function passed to [`UnsignedBolt12Invoice::sign`] where `invoice` is the
627
+ /// callee.
628
+ ///
629
+ /// Implementors may check that the `invoice` is expected rather than blindly signing the tagged
630
+ /// hash. An `Ok` result should sign `invoice.tagged_hash().as_digest()` with the node's signing
631
+ /// key.
632
+ ///
633
+ /// [`TaggedHash`]: crate::offers::merkle::TaggedHash
634
+ fn sign_bolt12_invoice (
635
+ & self , invoice : & UnsignedBolt12Invoice
636
+ ) -> Result < schnorr:: Signature , ( ) > ;
637
+
622
638
/// Sign a gossip message.
623
639
///
624
640
/// Note that if this fails, LDK may panic and the message will not be broadcast to the network
@@ -1449,6 +1465,15 @@ impl NodeSigner for KeysManager {
1449
1465
Ok ( self . secp_ctx . sign_ecdsa_recoverable ( & hash_to_message ! ( & Sha256 :: hash( & preimage) ) , secret) )
1450
1466
}
1451
1467
1468
+ fn sign_bolt12_invoice (
1469
+ & self , invoice : & UnsignedBolt12Invoice
1470
+ ) -> Result < schnorr:: Signature , ( ) > {
1471
+ let message = invoice. tagged_hash ( ) . as_digest ( ) ;
1472
+ let keys = KeyPair :: from_secret_key ( & self . secp_ctx , & self . node_secret ) ;
1473
+ let aux_rand = self . get_secure_random_bytes ( ) ;
1474
+ Ok ( self . secp_ctx . sign_schnorr_with_aux_rand ( message, & keys, & aux_rand) )
1475
+ }
1476
+
1452
1477
fn sign_gossip_message ( & self , msg : UnsignedGossipMessage ) -> Result < Signature , ( ) > {
1453
1478
let msg_hash = hash_to_message ! ( & Sha256dHash :: hash( & msg. encode( ) [ ..] ) [ ..] ) ;
1454
1479
Ok ( self . secp_ctx . sign_ecdsa ( & msg_hash, & self . node_secret ) )
@@ -1557,6 +1582,12 @@ impl NodeSigner for PhantomKeysManager {
1557
1582
Ok ( self . inner . secp_ctx . sign_ecdsa_recoverable ( & hash_to_message ! ( & Sha256 :: hash( & preimage) ) , secret) )
1558
1583
}
1559
1584
1585
+ fn sign_bolt12_invoice (
1586
+ & self , invoice : & UnsignedBolt12Invoice
1587
+ ) -> Result < schnorr:: Signature , ( ) > {
1588
+ self . inner . sign_bolt12_invoice ( invoice)
1589
+ }
1590
+
1560
1591
fn sign_gossip_message ( & self , msg : UnsignedGossipMessage ) -> Result < Signature , ( ) > {
1561
1592
self . inner . sign_gossip_message ( msg)
1562
1593
}
0 commit comments