@@ -171,8 +171,11 @@ impl Readable for CounterpartyCommitmentSecrets {
171
171
}
172
172
}
173
173
174
- /// Derives a per-commitment-transaction private key (eg an htlc key or payment key) from the base
175
- /// private key for that type of key and the per_commitment_point (available in TxCreationKeys)
174
+ /// Derives a per-commitment-transaction private key (eg an htlc key or delayed_payment key)
175
+ /// from the base secret and the per_commitment_point.
176
+ ///
177
+ /// Note that this is infallible iff we trust that at least one of the two input keys are randomly
178
+ /// generated (ie our own).
176
179
pub fn derive_private_key < T : secp256k1:: Signing > ( secp_ctx : & Secp256k1 < T > , per_commitment_point : & PublicKey , base_secret : & SecretKey ) -> Result < SecretKey , secp256k1:: Error > {
177
180
let mut sha = Sha256 :: engine ( ) ;
178
181
sha. input ( & per_commitment_point. serialize ( ) ) ;
@@ -184,7 +187,13 @@ pub fn derive_private_key<T: secp256k1::Signing>(secp_ctx: &Secp256k1<T>, per_co
184
187
Ok ( key)
185
188
}
186
189
187
- pub ( super ) fn derive_public_key < T : secp256k1:: Signing > ( secp_ctx : & Secp256k1 < T > , per_commitment_point : & PublicKey , base_point : & PublicKey ) -> Result < PublicKey , secp256k1:: Error > {
190
+ /// Derives a per-commitment-transaction public key (eg an htlc key or a delayed_payment key)
191
+ /// from the base point and the per_commitment_key. This is the public equivalent of
192
+ /// derive_private_key - using only public keys to derive a public key instead of private keys.
193
+ ///
194
+ /// Note that this is infallible iff we trust that at least one of the two input keys are randomly
195
+ /// generated (ie our own).
196
+ pub fn derive_public_key < T : secp256k1:: Signing > ( secp_ctx : & Secp256k1 < T > , per_commitment_point : & PublicKey , base_point : & PublicKey ) -> Result < PublicKey , secp256k1:: Error > {
188
197
let mut sha = Sha256 :: engine ( ) ;
189
198
sha. input ( & per_commitment_point. serialize ( ) ) ;
190
199
sha. input ( & base_point. serialize ( ) ) ;
@@ -194,10 +203,11 @@ pub(super) fn derive_public_key<T: secp256k1::Signing>(secp_ctx: &Secp256k1<T>,
194
203
base_point. combine ( & hashkey)
195
204
}
196
205
197
- /// Derives a revocation key from its constituent parts.
206
+ /// Derives a per-commitment-transaction revocation key from its constituent parts.
207
+ ///
198
208
/// Note that this is infallible iff we trust that at least one of the two input keys are randomly
199
209
/// generated (ie our own).
200
- pub ( super ) fn derive_private_revocation_key < T : secp256k1:: Signing > ( secp_ctx : & Secp256k1 < T > , per_commitment_secret : & SecretKey , revocation_base_secret : & SecretKey ) -> Result < SecretKey , secp256k1:: Error > {
210
+ pub fn derive_private_revocation_key < T : secp256k1:: Signing > ( secp_ctx : & Secp256k1 < T > , per_commitment_secret : & SecretKey , revocation_base_secret : & SecretKey ) -> Result < SecretKey , secp256k1:: Error > {
201
211
let revocation_base_point = PublicKey :: from_secret_key ( & secp_ctx, & revocation_base_secret) ;
202
212
let per_commitment_point = PublicKey :: from_secret_key ( & secp_ctx, & per_commitment_secret) ;
203
213
@@ -224,7 +234,13 @@ pub(super) fn derive_private_revocation_key<T: secp256k1::Signing>(secp_ctx: &Se
224
234
Ok ( part_a)
225
235
}
226
236
227
- pub ( super ) fn derive_public_revocation_key < T : secp256k1:: Verification > ( secp_ctx : & Secp256k1 < T > , per_commitment_point : & PublicKey , revocation_base_point : & PublicKey ) -> Result < PublicKey , secp256k1:: Error > {
237
+ /// Derives a per-commitment-transaction revocation public key from its constituent parts. This is
238
+ /// the public equivalend of derive_private_revocation_key - using only public keys to derive a
239
+ /// public key instead of private keys.
240
+ ///
241
+ /// Note that this is infallible iff we trust that at least one of the two input keys are randomly
242
+ /// generated (ie our own).
243
+ pub fn derive_public_revocation_key < T : secp256k1:: Verification > ( secp_ctx : & Secp256k1 < T > , per_commitment_point : & PublicKey , revocation_base_point : & PublicKey ) -> Result < PublicKey , secp256k1:: Error > {
228
244
let rev_append_commit_hash_key = {
229
245
let mut sha = Sha256 :: engine ( ) ;
230
246
sha. input ( & revocation_base_point. serialize ( ) ) ;
@@ -273,9 +289,9 @@ pub struct ChannelPublicKeys {
273
289
/// on-chain channel lock-in 2-of-2 multisig output.
274
290
pub funding_pubkey : PublicKey ,
275
291
/// The base point which is used (with derive_public_revocation_key) to derive per-commitment
276
- /// revocation keys. The per-commitment revocation private key is then revealed by the owner of
277
- /// a commitment transaction so that their counterparty can claim all available funds if they
278
- /// broadcast an old state .
292
+ /// revocation keys. This is combined with the per-commitment-secret generated by the
293
+ /// counterparty to create a secret which the counterparty can reveal to revoke previous
294
+ /// states .
279
295
pub revocation_basepoint : PublicKey ,
280
296
/// The public key which receives our immediately spendable primary channel balance in
281
297
/// remote-broadcasted commitment transactions. This key is static across every commitment
@@ -311,9 +327,10 @@ impl TxCreationKeys {
311
327
}
312
328
}
313
329
314
- /// Gets the "to_local" output redeemscript, ie the script which is time-locked or spendable by
315
- /// the revocation key
316
- pub ( super ) fn get_revokeable_redeemscript ( revocation_key : & PublicKey , to_self_delay : u16 , delayed_payment_key : & PublicKey ) -> Script {
330
+ /// A script either spendable by the revocation
331
+ /// key or the delayed_payment_key and satisfying the relative-locktime OP_CSV constrain.
332
+ /// Encumbering a `to_local` output on a commitment transaction or 2nd-stage HTLC transactions.
333
+ pub fn get_revokeable_redeemscript ( revocation_key : & PublicKey , to_self_delay : u16 , delayed_payment_key : & PublicKey ) -> Script {
317
334
Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_IF )
318
335
. push_slice ( & revocation_key. serialize ( ) )
319
336
. push_opcode ( opcodes:: all:: OP_ELSE )
0 commit comments