@@ -12,6 +12,7 @@ use bitcoin::util::bip143;
12
12
use bitcoin_hashes:: { Hash , HashEngine } ;
13
13
use bitcoin_hashes:: sha256:: HashEngine as Sha256State ;
14
14
use bitcoin_hashes:: sha256:: Hash as Sha256 ;
15
+ use bitcoin_hashes:: sha256d:: Hash as Sha256dHash ;
15
16
use bitcoin_hashes:: hash160:: Hash as Hash160 ;
16
17
17
18
use secp256k1:: key:: { SecretKey , PublicKey } ;
@@ -20,9 +21,11 @@ use secp256k1;
20
21
21
22
use util:: byte_utils;
22
23
use util:: logger:: Logger ;
24
+ use util:: ser:: Writeable ;
23
25
24
26
use ln:: chan_utils;
25
27
use ln:: chan_utils:: { TxCreationKeys , HTLCOutputInCommitment } ;
28
+ use ln:: msgs;
26
29
27
30
use std:: sync:: Arc ;
28
31
use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
@@ -140,6 +143,14 @@ pub trait ChannelKeys : Send {
140
143
/// TODO: Add more input vars to enable better checking (preferably removing commitment_tx and
141
144
/// making the callee generate it via some util function we expose)!
142
145
fn sign_remote_commitment < T : secp256k1:: Signing > ( & self , channel_value_satoshis : u64 , channel_funding_script : & Script , feerate_per_kw : u64 , commitment_tx : & Transaction , keys : & TxCreationKeys , htlcs : & [ & HTLCOutputInCommitment ] , to_self_delay : u16 , secp_ctx : & Secp256k1 < T > ) -> Result < ( Signature , Vec < Signature > ) , ( ) > ;
146
+
147
+ /// Signs a channel announcement message with our funding key, proving it comes from one
148
+ /// of the channel participants.
149
+ ///
150
+ /// Note that if this fails or is rejected, the channel will not be publicly announced and
151
+ /// our counterparty may (though likely will not) close the channel on us for violating the
152
+ /// protocol.
153
+ fn sign_channel_announcement < T : secp256k1:: Signing > ( & self , msg : & msgs:: UnsignedChannelAnnouncement , secp_ctx : & Secp256k1 < T > ) -> Result < Signature , ( ) > ;
143
154
}
144
155
145
156
#[ derive( Clone ) ]
@@ -167,7 +178,6 @@ impl ChannelKeys for InMemoryChannelKeys {
167
178
fn htlc_base_key ( & self ) -> & SecretKey { & self . htlc_base_key }
168
179
fn commitment_seed ( & self ) -> & [ u8 ; 32 ] { & self . commitment_seed }
169
180
170
-
171
181
fn sign_remote_commitment < T : secp256k1:: Signing > ( & self , channel_value_satoshis : u64 , channel_funding_script : & Script , feerate_per_kw : u64 , commitment_tx : & Transaction , keys : & TxCreationKeys , htlcs : & [ & HTLCOutputInCommitment ] , to_self_delay : u16 , secp_ctx : & Secp256k1 < T > ) -> Result < ( Signature , Vec < Signature > ) , ( ) > {
172
182
if commitment_tx. input . len ( ) != 1 { return Err ( ( ) ) ; }
173
183
let commitment_sighash = hash_to_message ! ( & bip143:: SighashComponents :: new( & commitment_tx) . sighash_all( & commitment_tx. input[ 0 ] , & channel_funding_script, channel_value_satoshis) [ ..] ) ;
@@ -191,6 +201,11 @@ impl ChannelKeys for InMemoryChannelKeys {
191
201
192
202
Ok ( ( commitment_sig, htlc_sigs) )
193
203
}
204
+
205
+ fn sign_channel_announcement < T : secp256k1:: Signing > ( & self , msg : & msgs:: UnsignedChannelAnnouncement , secp_ctx : & Secp256k1 < T > ) -> Result < Signature , ( ) > {
206
+ let msghash = hash_to_message ! ( & Sha256dHash :: hash( & msg. encode( ) [ ..] ) [ ..] ) ;
207
+ Ok ( secp_ctx. sign ( & msghash, & self . funding_key ) )
208
+ }
194
209
}
195
210
196
211
impl_writeable ! ( InMemoryChannelKeys , 0 , {
0 commit comments