@@ -31,26 +31,30 @@ macro_rules! doc_comment {
31
31
} ;
32
32
}
33
33
macro_rules! basepoint_impl {
34
- ( $BasepointT: ty) => {
34
+ ( $BasepointT: ty $ ( , $KeyName : expr ) ? ) => {
35
35
impl $BasepointT {
36
36
/// Get inner Public Key
37
37
pub fn to_public_key( & self ) -> PublicKey {
38
38
self . 0
39
39
}
40
40
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
+ ) ?
54
58
}
55
59
56
60
impl From <PublicKey > for $BasepointT {
@@ -110,7 +114,7 @@ macro_rules! key_read_write {
110
114
/// state broadcasted was previously revoked.
111
115
#[ derive( PartialEq , Eq , Clone , Copy , Debug , Hash ) ]
112
116
pub struct DelayedPaymentBasepoint ( pub PublicKey ) ;
113
- basepoint_impl ! ( DelayedPaymentBasepoint ) ;
117
+ basepoint_impl ! ( DelayedPaymentBasepoint , "DelayedPaymentKey" ) ;
114
118
key_read_write ! ( DelayedPaymentBasepoint ) ;
115
119
116
120
/// A derived key built from a [`DelayedPaymentBasepoint`] and `per_commitment_point`.
@@ -137,7 +141,7 @@ key_read_write!(DelayedPaymentKey);
137
141
/// Thus, both channel counterparties' HTLC keys will appears in each HTLC output's script.
138
142
#[ derive( PartialEq , Eq , Clone , Copy , Debug , Hash ) ]
139
143
pub struct HtlcBasepoint ( pub PublicKey ) ;
140
- basepoint_impl ! ( HtlcBasepoint ) ;
144
+ basepoint_impl ! ( HtlcBasepoint , "HtlcKey" ) ;
141
145
key_read_write ! ( HtlcBasepoint ) ;
142
146
143
147
/// A derived key built from a [`HtlcBasepoint`] and `per_commitment_point`.
0 commit comments