+// This file is Copyright its original authors, visible in version control
+// history.
+//
+// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
+// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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};
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;
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") }
}
}
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())
}
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();
}
}