File tree 1 file changed +20
-0
lines changed
1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -139,6 +139,26 @@ impl KeyPair {
139
139
& mut self . 0
140
140
}
141
141
142
+ /// Creates a Schnorr KeyPair directly from generic Secp256k1 secret key
143
+ ///
144
+ /// Panics if internal representation of the provided [`SecretKey`] does not
145
+ /// holds correct secret key value obtained from Secp256k1 library
146
+ /// previously
147
+ #[ inline]
148
+ pub fn from_secret_key < C : Signing > (
149
+ secp : & Secp256k1 < C > ,
150
+ sk : :: key:: SecretKey ,
151
+ ) -> KeyPair {
152
+ unsafe {
153
+ let mut kp = ffi:: KeyPair :: new ( ) ;
154
+ if ffi:: secp256k1_keypair_create ( secp. ctx , & mut kp, sk. as_c_ptr ( ) ) == 1 {
155
+ KeyPair ( kp)
156
+ } else {
157
+ panic ! ( "the provided secret key is invalid: it is corrupted or was not produced by Secp256k1 library" )
158
+ }
159
+ }
160
+ }
161
+
142
162
/// Creates a Schnorr KeyPair directly from a secret key slice
143
163
#[ inline]
144
164
pub fn from_seckey_slice < C : Signing > (
You can’t perform that action at this time.
0 commit comments