Merge pull request #3036 from TheBlueMatt/2024-05-filter-color
[rust-lightning] / lightning / src / sign / mod.rs
index 8148c88e1042758d58e6cd7f2e592be6c99ddee4..abc40607dfc056aae2a9b3ea2e2eee45e2debca0 100644 (file)
@@ -39,6 +39,7 @@ use bitcoin::{secp256k1, Sequence, Txid, Witness};
 
 use crate::chain::transaction::OutPoint;
 use crate::crypto::utils::{hkdf_extract_expand_twice, sign, sign_with_aux_rand};
+use crate::ln::chan_utils;
 use crate::ln::chan_utils::{
        get_revokeable_redeemscript, make_funding_redeemscript, ChannelPublicKeys,
        ChannelTransactionParameters, ClosingTransaction, CommitmentTransaction,
@@ -53,7 +54,7 @@ use crate::ln::channel_keys::{
 use crate::ln::msgs::PartialSignatureWithNonce;
 use crate::ln::msgs::{UnsignedChannelAnnouncement, UnsignedGossipMessage};
 use crate::ln::script::ShutdownScript;
-use crate::ln::{chan_utils, PaymentPreimage};
+use crate::ln::types::PaymentPreimage;
 use crate::offers::invoice::UnsignedBolt12Invoice;
 use crate::offers::invoice_request::UnsignedInvoiceRequest;
 use crate::util::ser::{Readable, ReadableArgs, Writeable, Writer};
@@ -64,7 +65,7 @@ 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};
+use crate::sign::ecdsa::EcdsaChannelSigner;
 #[cfg(taproot)]
 use crate::sign::taproot::TaprootChannelSigner;
 use crate::util::atomic_counter::AtomicCounter;
@@ -110,8 +111,8 @@ pub struct DelayedPaymentOutputDescriptor {
        pub channel_keys_id: [u8; 32],
        /// The value of the channel which this output originated from, possibly indirectly.
        pub channel_value_satoshis: u64,
-       /// The channel public keys and other parameters needed to generate a spending transaction or to provide to a re-derived signer through
-       /// [`ChannelSigner::provide_channel_parameters`].
+       /// The channel public keys and other parameters needed to generate a spending transaction or
+       /// to provide to a re-derived signer through [`ChannelSigner::provide_channel_parameters`].
        ///
        /// Added as optional, but always `Some` if the descriptor was produced in v0.0.123 or later.
        pub channel_transaction_parameters: Option<ChannelTransactionParameters>,
@@ -144,6 +145,10 @@ pub(crate) const P2WPKH_WITNESS_WEIGHT: u64 = 1 /* num stack items */ +
        1 /* pubkey length */ +
        33 /* pubkey */;
 
+/// Witness weight for satisying a P2TR key-path spend.
+pub(crate) const P2TR_KEY_PATH_WITNESS_WEIGHT: u64 = 1 /* witness items */
+       + 1 /* schnorr sig len */ + 64 /* schnorr sig */;
+
 /// Information about a spendable output to our "payment key".
 ///
 /// See [`SpendableOutputDescriptor::StaticPaymentOutput`] for more details on how to spend this.
@@ -704,9 +709,7 @@ impl HTLCDescriptor {
        }
 
        /// Derives the channel signer required to sign the HTLC input.
-       pub fn derive_channel_signer<S: WriteableEcdsaChannelSigner, SP: Deref>(
-               &self, signer_provider: &SP,
-       ) -> S
+       pub fn derive_channel_signer<S: EcdsaChannelSigner, SP: Deref>(&self, signer_provider: &SP) -> S
        where
                SP::Target: SignerProvider<EcdsaSigner = S>,
        {
@@ -919,6 +922,8 @@ pub trait OutputSpender {
 
 // Primarily needed in doctests because of https://github.com/rust-lang/rust/issues/67295
 /// A dynamic [`SignerProvider`] temporarily needed for doc tests.
+///
+/// This is not exported to bindings users as it is not intended for public consumption.
 #[cfg(taproot)]
 #[doc(hidden)]
 #[deprecated(note = "Remove once taproot cfg is removed")]
@@ -926,6 +931,8 @@ pub type DynSignerProvider =
        dyn SignerProvider<EcdsaSigner = InMemorySigner, TaprootSigner = InMemorySigner>;
 
 /// A dynamic [`SignerProvider`] temporarily needed for doc tests.
+///
+/// This is not exported to bindings users as it is not intended for public consumption.
 #[cfg(not(taproot))]
 #[doc(hidden)]
 #[deprecated(note = "Remove once taproot cfg is removed")]
@@ -933,8 +940,8 @@ pub type DynSignerProvider = dyn SignerProvider<EcdsaSigner = InMemorySigner>;
 
 /// A trait that can return signer instances for individual channels.
 pub trait SignerProvider {
-       /// A type which implements [`WriteableEcdsaChannelSigner`] which will be returned by [`Self::derive_channel_signer`].
-       type EcdsaSigner: WriteableEcdsaChannelSigner;
+       /// A type which implements [`EcdsaChannelSigner`] which will be returned by [`Self::derive_channel_signer`].
+       type EcdsaSigner: EcdsaChannelSigner;
        #[cfg(taproot)]
        /// A type which implements [`TaprootChannelSigner`]
        type TaprootSigner: TaprootChannelSigner;
@@ -961,7 +968,7 @@ pub trait SignerProvider {
 
        /// Reads a [`Signer`] for this [`SignerProvider`] from the given input stream.
        /// This is only called during deserialization of other objects which contain
-       /// [`WriteableEcdsaChannelSigner`]-implementing objects (i.e., [`ChannelMonitor`]s and [`ChannelManager`]s).
+       /// [`EcdsaChannelSigner`]-implementing objects (i.e., [`ChannelMonitor`]s and [`ChannelManager`]s).
        /// The bytes are exactly those which `<Self::Signer as Writeable>::write()` writes, and
        /// contain no versioning scheme. You may wish to include your own version prefix and ensure
        /// you've read all of the provided bytes to ensure no corruption occurred.
@@ -1005,7 +1012,7 @@ pub trait ChangeDestinationSource {
        fn get_change_destination_script(&self) -> Result<ScriptBuf, ()>;
 }
 
-/// A simple implementation of [`WriteableEcdsaChannelSigner`] that just keeps the private keys in memory.
+/// A simple implementation of [`EcdsaChannelSigner`] that just keeps the private keys in memory.
 ///
 /// This implementation performs no policy checks and is insufficient by itself as
 /// a secure external signer.
@@ -1733,8 +1740,6 @@ const SERIALIZATION_VERSION: u8 = 1;
 
 const MIN_SERIALIZATION_VERSION: u8 = 1;
 
-impl WriteableEcdsaChannelSigner for InMemorySigner {}
-
 impl Writeable for InMemorySigner {
        fn write<W: Writer>(&self, writer: &mut W) -> Result<(), Error> {
                write_ver_prefix!(writer, SERIALIZATION_VERSION, MIN_SERIALIZATION_VERSION);
@@ -1930,7 +1935,7 @@ impl KeysManager {
                self.node_secret
        }
 
-       /// Derive an old [`WriteableEcdsaChannelSigner`] containing per-channel secrets based on a key derivation parameters.
+       /// Derive an old [`EcdsaChannelSigner`] containing per-channel secrets based on a key derivation parameters.
        pub fn derive_channel_keys(
                &self, channel_value_satoshis: u64, params: &[u8; 32],
        ) -> InMemorySigner {