X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fchain%2Fkeysinterface.rs;h=2a68299c248caabc0045244d3e8cb03a5fa6d7f1;hb=b1ed0ee0339db7cb1820c14a920d294a264037c7;hp=58624d219c475fa9dc4de448e6fbc2f08f3faadf;hpb=ae16c5ca3411e5f37de738eaaa7e28465a305eb4;p=rust-lightning diff --git a/lightning/src/chain/keysinterface.rs b/lightning/src/chain/keysinterface.rs index 58624d219..2a68299c2 100644 --- a/lightning/src/chain/keysinterface.rs +++ b/lightning/src/chain/keysinterface.rs @@ -12,6 +12,7 @@ use bitcoin::util::bip143; use bitcoin_hashes::{Hash, HashEngine}; use bitcoin_hashes::sha256::HashEngine as Sha256State; use bitcoin_hashes::sha256::Hash as Sha256; +use bitcoin_hashes::sha256d::Hash as Sha256dHash; use bitcoin_hashes::hash160::Hash as Hash160; use secp256k1::key::{SecretKey, PublicKey}; @@ -20,9 +21,11 @@ use secp256k1; use util::byte_utils; use util::logger::Logger; +use util::ser::Writeable; use ln::chan_utils; use ln::chan_utils::{TxCreationKeys, HTLCOutputInCommitment}; +use ln::msgs; use std::sync::Arc; use std::sync::atomic::{AtomicUsize, Ordering}; @@ -140,6 +143,14 @@ pub trait ChannelKeys : Send { /// TODO: Add more input vars to enable better checking (preferably removing commitment_tx and /// making the callee generate it via some util function we expose)! fn sign_remote_commitment(&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) -> Result<(Signature, Vec), ()>; + + /// Signs a channel announcement message with our funding key, proving it comes from one + /// of the channel participants. + /// + /// Note that if this fails or is rejected, the channel will not be publicly announced and + /// our counterparty may (though likely will not) close the channel on us for violating the + /// protocol. + fn sign_channel_announcement(&self, msg: &msgs::UnsignedChannelAnnouncement, secp_ctx: &Secp256k1) -> Result; } #[derive(Clone)] @@ -167,7 +178,6 @@ impl ChannelKeys for InMemoryChannelKeys { fn htlc_base_key(&self) -> &SecretKey { &self.htlc_base_key } fn commitment_seed(&self) -> &[u8; 32] { &self.commitment_seed } - fn sign_remote_commitment(&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) -> Result<(Signature, Vec), ()> { if commitment_tx.input.len() != 1 { return Err(()); } 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 { Ok((commitment_sig, htlc_sigs)) } + + fn sign_channel_announcement(&self, msg: &msgs::UnsignedChannelAnnouncement, secp_ctx: &Secp256k1) -> Result { + let msghash = hash_to_message!(&Sha256dHash::hash(&msg.encode()[..])[..]); + Ok(secp_ctx.sign(&msghash, &self.funding_key)) + } } impl_writeable!(InMemoryChannelKeys, 0, {