X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fsign%2Fmod.rs;h=17a907d19d6313103750274910ed96e652cf099e;hb=c39c398f0618835201fb741b1976952c3f9180fa;hp=04c4446e2c0c8c75bd4f2f7e3b415b8f35296cf2;hpb=7aefa3131c6b0ee826ba4d86510745c9b2f95d1d;p=rust-lightning diff --git a/lightning/src/sign/mod.rs b/lightning/src/sign/mod.rs index 04c4446e..17a907d1 100644 --- a/lightning/src/sign/mod.rs +++ b/lightning/src/sign/mod.rs @@ -12,13 +12,16 @@ //! The provided output descriptors follow a custom LDK data format and are currently not fully //! compatible with Bitcoin Core output descriptors. -use bitcoin::blockdata::transaction::{Transaction, TxOut, TxIn, EcdsaSighashType}; -use bitcoin::blockdata::script::{Script, Builder}; +use bitcoin::blockdata::locktime::absolute::LockTime; +use bitcoin::blockdata::transaction::{Transaction, TxOut, TxIn}; +use bitcoin::blockdata::script::{Script, ScriptBuf, Builder}; use bitcoin::blockdata::opcodes; +use bitcoin::ecdsa::Signature as EcdsaSignature; use bitcoin::network::constants::Network; use bitcoin::psbt::PartiallySignedTransaction; -use bitcoin::util::bip32::{ExtendedPrivKey, ExtendedPubKey, ChildNumber}; -use bitcoin::util::sighash; +use bitcoin::bip32::{ExtendedPrivKey, ExtendedPubKey, ChildNumber}; +use bitcoin::sighash; +use bitcoin::sighash::EcdsaSighashType; use bitcoin::bech32::u5; use bitcoin::hashes::{Hash, HashEngine}; @@ -26,21 +29,25 @@ use bitcoin::hashes::sha256::Hash as Sha256; use bitcoin::hashes::sha256d::Hash as Sha256dHash; use bitcoin::hash_types::WPubkeyHash; +#[cfg(taproot)] +use bitcoin::secp256k1::All; use bitcoin::secp256k1::{KeyPair, PublicKey, Scalar, Secp256k1, SecretKey, Signing}; use bitcoin::secp256k1::ecdh::SharedSecret; use bitcoin::secp256k1::ecdsa::{RecoverableSignature, Signature}; use bitcoin::secp256k1::schnorr; -use bitcoin::{PackedLockTime, secp256k1, Sequence, Witness}; +use bitcoin::{secp256k1, Sequence, Witness, Txid}; use crate::util::transaction_utils; -use crate::util::crypto::{hkdf_extract_expand_twice, sign, sign_with_aux_rand}; +use crate::crypto::utils::{hkdf_extract_expand_twice, sign, sign_with_aux_rand}; use crate::util::ser::{Writeable, Writer, Readable, ReadableArgs}; use crate::chain::transaction::OutPoint; -use crate::events::bump_transaction::HTLCDescriptor; use crate::ln::channel::ANCHOR_OUTPUT_VALUE_SATOSHI; use crate::ln::{chan_utils, PaymentPreimage}; use crate::ln::chan_utils::{HTLCOutputInCommitment, make_funding_redeemscript, ChannelPublicKeys, HolderCommitmentTransaction, ChannelTransactionParameters, CommitmentTransaction, ClosingTransaction}; +use crate::ln::channel_keys::{DelayedPaymentBasepoint, DelayedPaymentKey, HtlcKey, HtlcBasepoint, RevocationKey, RevocationBasepoint}; use crate::ln::msgs::{UnsignedChannelAnnouncement, UnsignedGossipMessage}; +#[cfg(taproot)] +use crate::ln::msgs::PartialSignatureWithNonce; use crate::ln::script::ShutdownScript; use crate::offers::invoice::UnsignedBolt12Invoice; use crate::offers::invoice_request::UnsignedInvoiceRequest; @@ -49,15 +56,24 @@ use crate::prelude::*; use core::convert::TryInto; use core::ops::Deref; use core::sync::atomic::{AtomicUsize, Ordering}; +#[cfg(taproot)] +use musig2::types::{PartialSignature, PublicNonce}; use crate::io::{self, Error}; use crate::ln::features::ChannelTypeFeatures; use crate::ln::msgs::{DecodeError, MAX_VALUE_MSAT}; +use crate::sign::ecdsa::{EcdsaChannelSigner, WriteableEcdsaChannelSigner}; +#[cfg(taproot)] +use crate::sign::taproot::TaprootChannelSigner; use crate::util::atomic_counter::AtomicCounter; -use crate::util::chacha20::ChaCha20; +use crate::crypto::chacha20::ChaCha20; use crate::util::invoice::construct_invoice_preimage; pub(crate) mod type_resolver; +pub mod ecdsa; +#[cfg(taproot)] +pub mod taproot; + /// Used as initial key material, to be expanded into multiple secret keys (but not to be used /// directly). This is used within LDK to encrypt/decrypt inbound payment data. /// @@ -81,7 +97,7 @@ pub struct DelayedPaymentOutputDescriptor { pub output: TxOut, /// The revocation point specific to the commitment transaction which was broadcast. Used to /// derive the witnessScript for this output. - pub revocation_pubkey: PublicKey, + pub revocation_pubkey: RevocationKey, /// Arbitrary identification information returned by a call to [`ChannelSigner::channel_keys_id`]. /// This may be useful in re-deriving keys used in the channel to spend the output. pub channel_keys_id: [u8; 32], @@ -94,7 +110,7 @@ impl DelayedPaymentOutputDescriptor { /// shorter. // Calculated as 1 byte length + 73 byte signature, 1 byte empty vec push, 1 byte length plus // redeemscript push length. - pub const MAX_WITNESS_LENGTH: usize = 1 + 73 + 1 + chan_utils::REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH + 1; + pub const MAX_WITNESS_LENGTH: u64 = 1 + 73 + 1 + chan_utils::REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH as u64 + 1; } impl_writeable_tlv_based!(DelayedPaymentOutputDescriptor, { @@ -138,7 +154,7 @@ impl StaticPaymentOutputDescriptor { /// /// Note that this will only return `Some` for [`StaticPaymentOutputDescriptor`]s that /// originated from an anchor outputs channel, as they take the form of a P2WSH script. - pub fn witness_script(&self) -> Option