use bitcoin::secp256k1;
use util::byte_utils;
-use util::logger::Logger;
use util::ser::{Writeable, Writer, Readable};
use ln::chan_utils;
use ln::chan_utils::{TxCreationKeys, HTLCOutputInCommitment, make_funding_redeemscript, ChannelPublicKeys, LocalCommitmentTransaction};
use ln::msgs;
-use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::io::Error;
use ln::msgs::DecodeError;
/// return value must contain a signature.
fn sign_local_commitment_htlc_transactions<T: secp256k1::Signing + secp256k1::Verification>(&self, local_commitment_tx: &LocalCommitmentTransaction, local_csv: u16, secp_ctx: &Secp256k1<T>) -> Result<Vec<Option<Signature>>, ()>;
+ /// Create a signature for a transaction spending an HTLC or commitment transaction output
+ /// when our counterparty broadcast an old state.
+ ///
+ /// Justice transaction may claim multiples outputs at same time if timelock are similar.
+ /// It may be called multiples time for same output(s) if a fee-bump is needed with regards
+ /// to an upcoming timelock expiration.
+ ///
+ /// Witness_script is a revokable witness script as defined in BOLT3 for `to_local`/HTLC
+ /// outputs.
+ ///
+ /// Input index is a pointer towards outpoint spent, commited by sigs (BIP 143).
+ ///
+ /// Amount is value of the output spent by this input, committed by sigs (BIP 143).
+ ///
+ /// Per_commitment key is revocation secret such as provided by remote party while
+ /// revocating detected onchain transaction. It's not a _local_ secret key, therefore
+ /// it may cross interfaces, a node compromise won't allow to spend revoked output without
+ /// also compromissing revocation key.
+ //TODO: dry-up witness_script and pass pubkeys
+ fn sign_justice_transaction<T: secp256k1::Signing>(&self, justice_tx: &Transaction, input: usize, witness_script: &Script, amount: u64, per_commitment_key: &SecretKey, revocation_pubkey: &PublicKey, is_htlc: bool, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()>;
+
/// Create a signature for a (proposed) closing transaction.
///
/// Note that, due to rounding, there may be one "missing" satoshi, and either party may have
local_commitment_tx.get_htlc_sigs(&self.htlc_base_key, local_csv, secp_ctx)
}
+ fn sign_justice_transaction<T: secp256k1::Signing>(&self, justice_tx: &Transaction, input: usize, witness_script: &Script, amount: u64, per_commitment_key: &SecretKey, revocation_pubkey: &PublicKey, is_htlc: bool, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
+ if let Ok(revocation_key) = chan_utils::derive_private_revocation_key(&secp_ctx, &per_commitment_key, &self.revocation_base_key) {
+ let sighash_parts = bip143::SighashComponents::new(&justice_tx);
+ let sighash = hash_to_message!(&sighash_parts.sighash_all(&justice_tx.input[input], &witness_script, amount)[..]);
+ return Ok(secp_ctx.sign(&sighash, &revocation_key))
+ }
+ Err(())
+ }
+
fn sign_closing_transaction<T: secp256k1::Signing>(&self, closing_tx: &Transaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
if closing_tx.input.len() != 1 { return Err(()); }
if closing_tx.input[0].witness.len() != 0 { return Err(()); }
channel_id_child_index: AtomicUsize,
unique_start: Sha256State,
- logger: Arc<Logger>,
}
impl KeysManager {
/// Note that until the 0.1 release there is no guarantee of backward compatibility between
/// versions. Once the library is more fully supported, the docs will be updated to include a
/// detailed description of the guarantee.
- pub fn new(seed: &[u8; 32], network: Network, logger: Arc<Logger>, starting_time_secs: u64, starting_time_nanos: u32) -> KeysManager {
+ pub fn new(seed: &[u8; 32], network: Network, starting_time_secs: u64, starting_time_nanos: u32) -> KeysManager {
let secp_ctx = Secp256k1::signing_only();
match ExtendedPrivKey::new_master(network.clone(), seed) {
Ok(master_key) => {
channel_id_child_index: AtomicUsize::new(0),
unique_start,
- logger,
}
},
Err(_) => panic!("Your rng is busted"),