You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// Master key used in conjunction with per_commitment_point to generate [`local_delayedpubkey`](https://github.com/lightning/bolts/blob/master/03-transactions.md#key-derivation) for the latest state of a channel.
96
-
/// A watcher can be given a [DelayedPaymentBasepoint] to generate per commitment [DelayedPaymentKey] to create justice transactions.
95
+
/// Base key used in conjunction with a `per_commitment_point` to generate a [`DelayedPaymentKey`].
96
+
///
97
+
/// The delayed payment key is used to pay the commitment state broadcaster their
98
+
/// non-HTLC-encumbered funds after a delay to give their counterparty a chance to punish if the
/// To allow a counterparty to contest a channel state published by a node, Lightning protocol sets delays for some of the outputs, before can be spend.
104
-
/// For example a commitment transaction has to_local output encumbered by a delay, negotiated at the channel establishment flow.
105
-
/// To spend from such output a node has to generate a script using, among others, a local delayed payment key.
105
+
106
+
/// A derived key built from a [`DelayedPaymentBasepoint`] and `per_commitment_point`.
107
+
///
108
+
/// The delayed payment key is used to pay the commitment state broadcaster their
109
+
/// non-HTLC-encumbered funds after a delay. This delay gives their counterparty a chance to
110
+
/// punish and claim all the channel funds if the state broadcasted was previously revoked.
/// Master key used in conjunction with per_commitment_point to generate a [localpubkey](https://github.com/lightning/bolts/blob/master/03-transactions.md#key-derivation) for the latest state of a channel.
115
-
/// Also used to generate a commitment number in a commitment transaction or as a Payment Key for a remote node (not us) in an anchor output if `option_static_remotekey` is enabled.
116
-
/// Shared by both nodes in a channel establishment message flow.
117
-
#[derive(PartialEq,Eq,Clone,Copy,Debug,Hash)]
118
-
pubstructPaymentBasepoint(pubPublicKey);
119
-
basepoint_impl!(PaymentBasepoint);
120
-
key_read_write!(PaymentBasepoint);
121
-
122
-
123
-
/// [localpubkey](https://github.com/lightning/bolts/blob/master/03-transactions.md#localpubkey-local_htlcpubkey-remote_htlcpubkey-local_delayedpubkey-and-remote_delayedpubkey-derivation) is a child key of a payment basepoint,
124
-
/// that enables a secure hash-lock for off-chain payments without risk of funds getting stuck or stolen. A payment key is normally shared with a counterparty so that it can generate
125
-
/// a commitment transaction's to_remote ouput, which our node can claim in case the counterparty force closes the channel.
126
-
#[derive(PartialEq,Eq,Clone,Copy,Debug)]
127
-
pubstructPaymentKey(pubPublicKey);
128
-
129
-
implPaymentKey{
130
-
key_impl!(PaymentBasepoint,"localpubkey");
131
-
}
132
-
key_read_write!(PaymentKey);
133
-
134
-
/// Master key used in conjunction with per_commitment_point to generate [htlcpubkey](https://github.com/lightning/bolts/blob/master/03-transactions.md#key-derivation) for the latest state of a channel.
123
+
/// Base key used in conjunction with a `per_commitment_point` to generate an [`HtlcKey`].
124
+
///
125
+
/// HTLC keys are used to ensure only the recipient of an HTLC can claim it on-chain with the HTLC
126
+
/// preimage and that only the sender of an HTLC can claim it on-chain after it has timed out.
127
+
/// Thus, both channel counterparties' HTLC keys will appears in each HTLC output's script.
135
128
#[derive(PartialEq,Eq,Clone,Copy,Debug,Hash)]
136
129
pubstructHtlcBasepoint(pubPublicKey);
137
130
basepoint_impl!(HtlcBasepoint);
138
131
key_read_write!(HtlcBasepoint);
139
132
140
-
141
-
/// [htlcpubkey](https://github.com/lightning/bolts/blob/master/03-transactions.md#localpubkey-local_htlcpubkey-remote_htlcpubkey-local_delayedpubkey-and-remote_delayedpubkey-derivation) is a child key of an htlc basepoint,
142
-
/// that enables secure routing of payments in onion scheme without a risk of them getting stuck or diverted. It is used to claim the funds in successful or timed out htlc outputs.
133
+
/// A derived key built from a [`HtlcBasepoint`] and `per_commitment_point`.
134
+
///
135
+
/// HTLC keys are used to ensure only the recipient of an HTLC can claim it on-chain with the HTLC
136
+
/// preimage and that only the sender of an HTLC can claim it on-chain after it has timed out.
137
+
/// Thus, both channel counterparties' HTLC keys will appears in each HTLC output's script.
/// [htlcpubkey](https://github.com/lightning/bolts/blob/master/03-transactions.md#localpubkey-local_htlcpubkey-remote_htlcpubkey-local_delayedpubkey-and-remote_delayedpubkey-derivation) is a child key of a revocation basepoint,
176
-
/// that enables a node to create a justice transaction punishing a counterparty for an attempt to steal funds. Used to in generation of commitment and htlc outputs.
173
+
/// The revocation key is used to allow a channel party to revoke their state - giving their
174
+
/// counterparty the required material to claim all of their funds if they broadcast that state.
175
+
///
176
+
/// Each commitment transaction has a revocation key based on the basepoint and
177
+
/// per_commitment_point which is used in both commitment and HTLC transactions.
let countersignatory_contrib = countersignatory_basepoint.to_public_key().mul_tweak(&secp_ctx,&Scalar::from_be_bytes(rev_append_commit_hash_key).unwrap())
215
+
.expect("Multiplying a valid public key by a hash is expected to never fail per secp256k1 docs");
216
+
let broadcaster_contrib = (&per_commitment_point).mul_tweak(&secp_ctx,&Scalar::from_be_bytes(commit_append_rev_hash_key).unwrap())
217
+
.expect("Multiplying a valid public key by a hash is expected to never fail per secp256k1 docs");
218
+
let pk = countersignatory_contrib.combine(&broadcaster_contrib)
219
+
.expect("Addition only fails if the tweak is the inverse of the key. This is not possible when the tweak commits to the key.");
220
+
Self(pk)
221
+
}
222
+
223
+
/// Get inner Public Key
224
+
pubfnto_public_key(&self) -> PublicKey{
225
+
self.0
226
+
}
225
227
}
226
228
key_read_write!(RevocationKey);
227
229
228
230
229
-
230
231
#[cfg(test)]
231
232
mod test {
232
-
use bitcoin::secp256k1::{Secp256k1,SecretKey,PublicKey};
233
-
use bitcoin::hashes::hex::FromHex;
234
-
usesuper::derive_public_key;
233
+
use bitcoin::secp256k1::{Secp256k1,SecretKey,PublicKey};
0 commit comments