@@ -171,8 +171,11 @@ impl Readable for CounterpartyCommitmentSecrets {
171171 }
172172}
173173
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).
176179pub fn derive_private_key < T : secp256k1:: Signing > ( secp_ctx : & Secp256k1 < T > , per_commitment_point : & PublicKey , base_secret : & SecretKey ) -> Result < SecretKey , secp256k1:: Error > {
177180 let mut sha = Sha256 :: engine ( ) ;
178181 sha. input ( & per_commitment_point. serialize ( ) ) ;
@@ -184,7 +187,13 @@ pub fn derive_private_key<T: secp256k1::Signing>(secp_ctx: &Secp256k1<T>, per_co
184187 Ok ( key)
185188}
186189
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 > {
188197 let mut sha = Sha256 :: engine ( ) ;
189198 sha. input ( & per_commitment_point. serialize ( ) ) ;
190199 sha. input ( & base_point. serialize ( ) ) ;
@@ -194,10 +203,11 @@ pub(super) fn derive_public_key<T: secp256k1::Signing>(secp_ctx: &Secp256k1<T>,
194203 base_point. combine ( & hashkey)
195204}
196205
197- /// Derives a revocation key from its constituent parts.
206+ /// Derives a per-commitment-transaction revocation key from its constituent parts.
207+ ///
198208/// Note that this is infallible iff we trust that at least one of the two input keys are randomly
199209/// 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 > {
201211 let revocation_base_point = PublicKey :: from_secret_key ( & secp_ctx, & revocation_base_secret) ;
202212 let per_commitment_point = PublicKey :: from_secret_key ( & secp_ctx, & per_commitment_secret) ;
203213
@@ -224,7 +234,13 @@ pub(super) fn derive_private_revocation_key<T: secp256k1::Signing>(secp_ctx: &Se
224234 Ok ( part_a)
225235}
226236
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 > {
228244 let rev_append_commit_hash_key = {
229245 let mut sha = Sha256 :: engine ( ) ;
230246 sha. input ( & revocation_base_point. serialize ( ) ) ;
@@ -273,9 +289,9 @@ pub struct ChannelPublicKeys {
273289 /// on-chain channel lock-in 2-of-2 multisig output.
274290 pub funding_pubkey : PublicKey ,
275291 /// 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 .
279295 pub revocation_basepoint : PublicKey ,
280296 /// The public key which receives our immediately spendable primary channel balance in
281297 /// remote-broadcasted commitment transactions. This key is static across every commitment
@@ -311,9 +327,10 @@ impl TxCreationKeys {
311327 }
312328}
313329
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 {
317334 Builder :: new ( ) . push_opcode ( opcodes:: all:: OP_IF )
318335 . push_slice ( & revocation_key. serialize ( ) )
319336 . push_opcode ( opcodes:: all:: OP_ELSE )
0 commit comments