@@ -31,26 +31,30 @@ macro_rules! doc_comment {
3131 } ;
3232}
3333macro_rules! basepoint_impl {
34- ( $BasepointT: ty) => {
34+ ( $BasepointT: ty $ ( , $KeyName : expr ) ? ) => {
3535 impl $BasepointT {
3636 /// Get inner Public Key
3737 pub fn to_public_key( & self ) -> PublicKey {
3838 self . 0
3939 }
4040
41- /// Derives the "tweak" used to calculate the per-commitment private key.
42- ///
43- /// The per-commitment private key is calculates a private key as:
44- /// `privkey = basepoint_secret + SHA256(per_commitment_point || basepoint)`
45- ///
46- /// This calculates the hash part in the tweak derivation process, which is used to
47- /// ensure that each key is unique and cannot be guessed by an external party.
48- pub fn derive_add_tweak( & self , per_commitment_point: & PublicKey ) -> Sha256 {
49- let mut sha = Sha256 :: engine( ) ;
50- sha. input( & per_commitment_point. serialize( ) ) ;
51- sha. input( & self . to_public_key( ) . serialize( ) ) ;
52- Sha256 :: from_engine( sha)
53- }
41+ $( doc_comment!(
42+ concat!(
43+ "Derives the \" tweak\" used in calculate [`" , $KeyName, "::from_basepoint`].\n " ,
44+ "\n " ,
45+ "[`" , $KeyName, "::from_basepoint`] calculates a private key as:\n " ,
46+ "`privkey = basepoint_secret + SHA256(per_commitment_point || basepoint)`\n " ,
47+ "\n " ,
48+ "This calculates the hash part in the tweak derivation process, which is used to\n " ,
49+ "ensure that each key is unique and cannot be guessed by an external party."
50+ ) ,
51+ pub fn derive_add_tweak( & self , per_commitment_point: & PublicKey ) -> Sha256 {
52+ let mut sha = Sha256 :: engine( ) ;
53+ sha. input( & per_commitment_point. serialize( ) ) ;
54+ sha. input( & self . to_public_key( ) . serialize( ) ) ;
55+ Sha256 :: from_engine( sha)
56+ } ) ;
57+ ) ?
5458 }
5559
5660 impl From <PublicKey > for $BasepointT {
@@ -110,7 +114,7 @@ macro_rules! key_read_write {
110114/// state broadcasted was previously revoked.
111115#[ derive( PartialEq , Eq , Clone , Copy , Debug , Hash ) ]
112116pub struct DelayedPaymentBasepoint ( pub PublicKey ) ;
113- basepoint_impl ! ( DelayedPaymentBasepoint ) ;
117+ basepoint_impl ! ( DelayedPaymentBasepoint , "DelayedPaymentKey" ) ;
114118key_read_write ! ( DelayedPaymentBasepoint ) ;
115119
116120/// A derived key built from a [`DelayedPaymentBasepoint`] and `per_commitment_point`.
@@ -137,7 +141,7 @@ key_read_write!(DelayedPaymentKey);
137141/// Thus, both channel counterparties' HTLC keys will appears in each HTLC output's script.
138142#[ derive( PartialEq , Eq , Clone , Copy , Debug , Hash ) ]
139143pub struct HtlcBasepoint ( pub PublicKey ) ;
140- basepoint_impl ! ( HtlcBasepoint ) ;
144+ basepoint_impl ! ( HtlcBasepoint , "HtlcKey" ) ;
141145key_read_write ! ( HtlcBasepoint ) ;
142146
143147/// A derived key built from a [`HtlcBasepoint`] and `per_commitment_point`.
0 commit comments