X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Futil%2Fenforcing_trait_impls.rs;h=557f06b5df97e2ba7ecf1c830719bda5f2955f7b;hb=253af8dd617161b2bd79173f9da3ecc0b0991f7e;hp=9f297b4810318862b450f20c572e3da080575d34;hpb=d2e6f2ac18159f4d9b3b1cbc30bebd03030f0304;p=rust-lightning diff --git a/lightning/src/util/enforcing_trait_impls.rs b/lightning/src/util/enforcing_trait_impls.rs index 9f297b48..557f06b5 100644 --- a/lightning/src/util/enforcing_trait_impls.rs +++ b/lightning/src/util/enforcing_trait_impls.rs @@ -1,3 +1,12 @@ +// This file is Copyright its original authors, visible in version control +// history. +// +// This file is licensed under the Apache License, Version 2.0 or the MIT license +// , at your option. +// You may not use this file except in accordance with one or both of these +// licenses. + use ln::chan_utils::{HTLCOutputInCommitment, TxCreationKeys, ChannelPublicKeys, LocalCommitmentTransaction, PreCalculatedTxCreationKeys}; use ln::{chan_utils, msgs}; use chain::keysinterface::{ChannelKeys, InMemoryChannelKeys}; @@ -5,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; @@ -37,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") } } } @@ -84,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(&self, local_commitment_tx: &LocalCommitmentTransaction, secp_ctx: &Secp256k1) -> Result { Ok(self.inner.unsafe_sign_local_commitment(local_commitment_tx, secp_ctx).unwrap()) } @@ -99,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(); } }