Remove SecretKey from DynamicOutputP2WSH descriptor
[rust-lightning] / lightning / src / chain / keysinterface.rs
index fea11367eca56cb4fc6732ed1aa8c497b1e5b621..3a9c8168439852cfcfda719e2edfc2589701f158 100644 (file)
@@ -50,28 +50,39 @@ pub enum SpendableOutputDescriptor {
                output: TxOut,
        },
        /// An output to a P2WSH script which can be spent with a single signature after a CSV delay.
-       /// The private key which should be used to sign the transaction is provided, as well as the
-       /// full witness redeemScript which is hashed in the output script_pubkey.
+       ///
        /// The witness in the spending input should be:
-       /// <BIP 143 signature generated with the given key> <empty vector> (MINIMALIF standard rule)
-       /// <witness_script as provided>
-       /// Note that the nSequence field in the input must be set to_self_delay (which corresponds to
-       /// the transaction not being broadcastable until at least to_self_delay blocks after the input
-       /// confirms).
+       /// <BIP 143 signature> <empty vector> (MINIMALIF standard rule) <provided witnessScript>
+       ///
+       /// Note that the nSequence field in the spending input must be set to to_self_delay
+       /// (which means the transaction not being broadcastable until at least to_self_delay
+       /// blocks after the outpoint confirms).
+       ///
        /// These are generally the result of a "revocable" output to us, spendable only by us unless
        /// it is an output from us having broadcast an old state (which should never happen).
+       ///
+       /// WitnessScript may be regenerated by passing the revocation_pubkey, to_self_delay and
+       /// delayed_payment_pubkey to chan_utils::get_revokeable_redeemscript.
+       ///
+       /// To derive the delayed_payment key corresponding to the channel state, you must pass the
+       /// channel's delayed_payment_key and the provided per_commitment_point to
+       /// chan_utils::derive_private_key. The resulting key should be used to sign the spending
+       /// transaction.
        DynamicOutputP2WSH {
                /// The outpoint which is spendable
                outpoint: OutPoint,
-               /// The secret key which must be used to sign the spending transaction
-               key: SecretKey,
-               /// The witness redeemScript which is hashed to create the script_pubkey in the given output
-               witness_script: Script,
+               /// Per commitment point to derive delayed_payment_key by key holder
+               per_commitment_point: PublicKey,
                /// The nSequence value which must be set in the spending input to satisfy the OP_CSV in
                /// the witness_script.
                to_self_delay: u16,
                /// The output which is referenced by the given outpoint
                output: TxOut,
+               /// The channel keys state used to proceed to derivation of signing key. Must
+               /// be pass to KeysInterface::derive_channel_keys.
+               key_derivation_params: (u64, u64),
+               /// The remote_revocation_pubkey used to derive witnessScript
+               remote_revocation_pubkey: PublicKey
        },
        // TODO: Note that because key is now static and exactly what is provided by us, we should drop
        // this in favor of StaticOutput:
@@ -98,13 +109,15 @@ impl Writeable for SpendableOutputDescriptor {
                                outpoint.write(writer)?;
                                output.write(writer)?;
                        },
-                       &SpendableOutputDescriptor::DynamicOutputP2WSH { ref outpoint, ref key, ref witness_script, ref to_self_delay, ref output } => {
+                       &SpendableOutputDescriptor::DynamicOutputP2WSH { ref outpoint, ref per_commitment_point, ref to_self_delay, ref output, ref key_derivation_params, ref remote_revocation_pubkey } => {
                                1u8.write(writer)?;
                                outpoint.write(writer)?;
-                               key.write(writer)?;
-                               witness_script.write(writer)?;
+                               per_commitment_point.write(writer)?;
                                to_self_delay.write(writer)?;
                                output.write(writer)?;
+                               key_derivation_params.0.write(writer)?;
+                               key_derivation_params.1.write(writer)?;
+                               remote_revocation_pubkey.write(writer)?;
                        },
                        &SpendableOutputDescriptor::DynamicOutputP2WPKH { ref outpoint, ref key, ref output } => {
                                2u8.write(writer)?;
@@ -126,10 +139,11 @@ impl Readable for SpendableOutputDescriptor {
                        }),
                        1u8 => Ok(SpendableOutputDescriptor::DynamicOutputP2WSH {
                                outpoint: Readable::read(reader)?,
-                               key: Readable::read(reader)?,
-                               witness_script: Readable::read(reader)?,
+                               per_commitment_point: Readable::read(reader)?,
                                to_self_delay: Readable::read(reader)?,
                                output: Readable::read(reader)?,
+                               key_derivation_params: (Readable::read(reader)?, Readable::read(reader)?),
+                               remote_revocation_pubkey: Readable::read(reader)?,
                        }),
                        2u8 => Ok(SpendableOutputDescriptor::DynamicOutputP2WPKH {
                                outpoint: Readable::read(reader)?,