Merge pull request #618 from TheBlueMatt/2020-05-sample-c-bindings
[rust-lightning] / lightning / src / util / enforcing_trait_impls.rs
index a361973a43a20acf66ca37964a2faa997ec2071e..557f06b5df97e2ba7ecf1c830719bda5f2955f7b 100644 (file)
@@ -14,7 +14,7 @@ use chain::keysinterface::{ChannelKeys, InMemoryChannelKeys};
 use std::cmp;
 use std::sync::{Mutex, Arc};
 
-use bitcoin::blockdata::transaction::Transaction;
+use bitcoin::blockdata::transaction::{Transaction, SigHashType};
 use bitcoin::util::bip143;
 
 use bitcoin::secp256k1;
@@ -46,12 +46,12 @@ impl EnforcingChannelKeys {
                                                                       keys: &TxCreationKeys) {
                let remote_points = self.inner.remote_pubkeys();
 
-               let keys_expected = TxCreationKeys::new(secp_ctx,
-                                                       &keys.per_commitment_point,
-                                                       &remote_points.delayed_payment_basepoint,
-                                                       &remote_points.htlc_basepoint,
-                                                       &self.inner.pubkeys().revocation_basepoint,
-                                                       &self.inner.pubkeys().htlc_basepoint).unwrap();
+               let keys_expected = TxCreationKeys::derive_new(secp_ctx,
+                                                              &keys.per_commitment_point,
+                                                              &remote_points.delayed_payment_basepoint,
+                                                              &remote_points.htlc_basepoint,
+                                                              &self.inner.pubkeys().revocation_basepoint,
+                                                              &self.inner.pubkeys().htlc_basepoint).unwrap();
                if keys != &keys_expected { panic!("derived different per-tx keys") }
        }
 }
@@ -93,7 +93,7 @@ impl ChannelKeys for EnforcingChannelKeys {
                Ok(self.inner.sign_local_commitment(local_commitment_tx, secp_ctx).unwrap())
        }
 
-       #[cfg(test)]
+       #[cfg(any(test,feature = "unsafe_revoked_tx_signing"))]
        fn unsafe_sign_local_commitment<T: secp256k1::Signing + secp256k1::Verification>(&self, local_commitment_tx: &LocalCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
                Ok(self.inner.unsafe_sign_local_commitment(local_commitment_tx, secp_ctx).unwrap())
        }
@@ -108,7 +108,7 @@ impl ChannelKeys for EnforcingChannelKeys {
 
                                let htlc_redeemscript = chan_utils::get_htlc_redeemscript(&this_htlc.0, &local_commitment_tx.local_keys);
 
-                               let sighash = hash_to_message!(&bip143::SighashComponents::new(&htlc_tx).sighash_all(&htlc_tx.input[0], &htlc_redeemscript, this_htlc.0.amount_msat / 1000)[..]);
+                               let sighash = hash_to_message!(&bip143::SigHashCache::new(&htlc_tx).signature_hash(0, &htlc_redeemscript, this_htlc.0.amount_msat / 1000, SigHashType::All)[..]);
                                secp_ctx.verify(&sighash, this_htlc.1.as_ref().unwrap(), &local_commitment_tx.local_keys.b_htlc_key).unwrap();
                        }
                }