-use ln::chan_utils::{HTLCOutputInCommitment, TxCreationKeys, ChannelPublicKeys};
-use ln::msgs;
-use chain::keysinterface::{ChannelKeys, InMemoryChannelKeys};
-
-use std::cmp;
-use std::sync::Mutex;
-
-use bitcoin::blockdata::transaction::Transaction;
-use bitcoin::blockdata::script::Script;
-
-use secp256k1;
-use secp256k1::key::{SecretKey, PublicKey};
-use secp256k1::{Secp256k1, Signature};
-
-/// Enforces some rules on ChannelKeys calls. Eventually we will probably want to expose a variant
-/// of this which would essentially be what you'd want to run on a hardware wallet.
-pub struct EnforcingChannelKeys {
- pub inner: InMemoryChannelKeys,
- commitment_number_obscure_and_last: Mutex<(Option<u64>, u64)>,
+// 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, ChannelPublicKeys, HolderCommitmentTransaction, CommitmentTransaction, ChannelTransactionParameters, TrustedCommitmentTransaction, ClosingTransaction};
+use ln::{chan_utils, msgs};
+use chain::keysinterface::{Sign, InMemorySigner, BaseSign};
+
+use prelude::*;
+use core::cmp;
+use sync::{Mutex, Arc};
+#[cfg(test)] use sync::MutexGuard;
+
+use bitcoin::blockdata::transaction::{Transaction, SigHashType};
+use bitcoin::util::bip143;
+
+use bitcoin::secp256k1;
+use bitcoin::secp256k1::key::{SecretKey, PublicKey};
+use bitcoin::secp256k1::{Secp256k1, Signature};
+use util::ser::{Writeable, Writer};
+use io::Error;
+
+/// Initial value for revoked commitment downward counter
+pub const INITIAL_REVOKED_COMMITMENT_NUMBER: u64 = 1 << 48;
+
+/// An implementation of Sign that enforces some policy checks. The current checks
+/// are an incomplete set. They include:
+///
+/// - When signing, the holder transaction has not been revoked
+/// - When revoking, the holder transaction has not been signed
+/// - The holder commitment number is monotonic and without gaps
+/// - The revoked holder commitment number is monotonic and without gaps
+/// - There is at least one unrevoked holder transaction at all times
+/// - The counterparty commitment number is monotonic and without gaps
+/// - The pre-derived keys and pre-built transaction in CommitmentTransaction were correctly built
+///
+/// Eventually we will probably want to expose a variant of this which would essentially
+/// be what you'd want to run on a hardware wallet.
+///
+/// Note that counterparty signatures on the holder transaction are not checked, but it should
+/// be in a complete implementation.
+///
+/// Note that before we do so we should ensure its serialization format has backwards- and
+/// forwards-compatibility prefix/suffixes!
+#[derive(Clone)]
+pub struct EnforcingSigner {
+ pub inner: InMemorySigner,
+ /// Channel state used for policy enforcement
+ pub state: Arc<Mutex<EnforcementState>>,
+ pub disable_revocation_policy_check: bool,