X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fsign%2Fmod.rs;h=1459151de1c043964d80d77ca4403fa92f6211aa;hb=d8021c7891ca039751b250511fbcc06da32e9e7e;hp=5912b7b84e16e393daffb3a144c6b12ee2e4331b;hpb=1f399b0984d591019320459d804cbad859c608ae;p=rust-lightning diff --git a/lightning/src/sign/mod.rs b/lightning/src/sign/mod.rs index 5912b7b8..1459151d 100644 --- a/lightning/src/sign/mod.rs +++ b/lightning/src/sign/mod.rs @@ -12,51 +12,73 @@ //! 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::bip32::{ChildNumber, ExtendedPrivKey, ExtendedPubKey}; +use bitcoin::blockdata::locktime::absolute::LockTime; use bitcoin::blockdata::opcodes; +use bitcoin::blockdata::script::{Builder, Script, ScriptBuf}; +use bitcoin::blockdata::transaction::{Transaction, TxIn, TxOut}; +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::sighash; +use bitcoin::sighash::EcdsaSighashType; use bitcoin::bech32::u5; -use bitcoin::hashes::{Hash, HashEngine}; +use bitcoin::hash_types::WPubkeyHash; use bitcoin::hashes::sha256::Hash as Sha256; use bitcoin::hashes::sha256d::Hash as Sha256dHash; -use bitcoin::hash_types::WPubkeyHash; +use bitcoin::hashes::{Hash, HashEngine}; -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, Txid}; +#[cfg(taproot)] +use bitcoin::secp256k1::All; +use bitcoin::secp256k1::{KeyPair, PublicKey, Scalar, Secp256k1, SecretKey, Signing}; +use bitcoin::{secp256k1, Sequence, Txid, Witness}; -use crate::util::transaction_utils; -use crate::util::crypto::{hkdf_extract_expand_twice, sign, sign_with_aux_rand}; -use crate::util::ser::{Writeable, Writer, Readable, ReadableArgs}; use crate::chain::transaction::OutPoint; +use crate::crypto::utils::{hkdf_extract_expand_twice, sign, sign_with_aux_rand}; +use crate::ln::chan_utils::{ + make_funding_redeemscript, ChannelPublicKeys, ChannelTransactionParameters, ClosingTransaction, + CommitmentTransaction, HTLCOutputInCommitment, HolderCommitmentTransaction, +}; 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, HtlcBasepoint, HtlcKey, RevocationBasepoint, + RevocationKey, +}; +#[cfg(taproot)] +use crate::ln::msgs::PartialSignatureWithNonce; use crate::ln::msgs::{UnsignedChannelAnnouncement, UnsignedGossipMessage}; use crate::ln::script::ShutdownScript; +use crate::ln::{chan_utils, PaymentPreimage}; use crate::offers::invoice::UnsignedBolt12Invoice; use crate::offers::invoice_request::UnsignedInvoiceRequest; +use crate::util::ser::{Readable, ReadableArgs, Writeable, Writer}; +use crate::util::transaction_utils; -use crate::prelude::*; -use core::convert::TryInto; -use core::ops::Deref; -use core::sync::atomic::{AtomicUsize, Ordering}; +use crate::crypto::chacha20::ChaCha20; use crate::io::{self, Error}; use crate::ln::features::ChannelTypeFeatures; use crate::ln::msgs::{DecodeError, MAX_VALUE_MSAT}; +use crate::prelude::*; +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::util::invoice::construct_invoice_preimage; +use core::ops::Deref; +use core::sync::atomic::{AtomicUsize, Ordering}; +#[cfg(taproot)] +use musig2::types::{PartialSignature, PublicNonce}; 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. /// @@ -80,7 +102,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], @@ -93,7 +115,8 @@ 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, { @@ -137,32 +160,28 @@ 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