Skip to content

Commit 97524b2

Browse files
committed
Deprecate generate_schnorrsig_keypair
We have deprecated all other functions that use the identifier 'schnorrsig' but we missed `generate_schnorrsig_keypair`. This function is purely a helper function and serves no real purpose other than to reduce two lines of code to a single line. Downstream users can write this function themselves if they need it. Also, we recently added a new public method to `KeyPair` to get the public key in a slightly more ergonomic fashion. Use `kp.public_key()` when replacing usage of now deprecated `generate_schnorrsig_keypair` function.
1 parent 389abdd commit 97524b2

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

src/key.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,10 @@ mod test {
15531553
for _ in 0..10 {
15541554
let mut tweak = [0u8; 32];
15551555
thread_rng().fill_bytes(&mut tweak);
1556-
let (mut kp, mut pk) = s.generate_schnorrsig_keypair(&mut thread_rng());
1556+
1557+
let mut kp = KeyPair::new(&s, &mut thread_rng());
1558+
let mut pk = kp.public_key();
1559+
15571560
let orig_pk = pk;
15581561
kp.tweak_add_assign(&s, &tweak).expect("Tweak error");
15591562
let parity = pk.tweak_add_assign(&s, &tweak).expect("Tweak error");

src/schnorr.rs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,14 @@ impl<C: Verification> Secp256k1<C> {
248248
}
249249

250250
impl <C: Signing> Secp256k1<C> {
251-
252-
/// Generates a random Schnorr KeyPair and its associated Schnorr PublicKey.
253-
/// Convenience function for `schnorrsig::KeyPair::new` and
254-
/// `schnorrsig::PublicKey::from_keypair`; call those functions directly for
255-
/// batch key generation. Requires a signing-capable context. Requires compilation
256-
/// with the "rand" feature.
251+
/// Generates a random Schnorr `KeyPair` and its associated Schnorr `XOnlyPublicKey`.
252+
///
253+
/// Convenience function for [KeyPair::new] and [KeyPair::public_key].
254+
/// Requires a signing-capable context and requires compilation with the "rand" feature.
257255
#[inline]
258256
#[cfg(any(test, feature = "rand"))]
259257
#[cfg_attr(docsrs, doc(cfg(feature = "rand")))]
258+
#[deprecated(since = "0.21.0", note = "Use kp = KeyPair::new() and kp.public_key()")]
260259
pub fn generate_schnorrsig_keypair<R: Rng + ?Sized>(
261260
&self,
262261
rng: &mut R,
@@ -325,16 +324,18 @@ mod tests {
325324
let secp = Secp256k1::new();
326325

327326
let mut rng = thread_rng();
328-
let (seckey, pubkey) = secp.generate_schnorrsig_keypair(&mut rng);
327+
let kp = KeyPair::new(&secp, &mut rng);
328+
let pk = kp.public_key();
329+
329330
let mut msg = [0u8; 32];
330331

331332
for _ in 0..100 {
332333
rng.fill_bytes(&mut msg);
333334
let msg = Message::from_slice(&msg).unwrap();
334335

335-
let sig = sign(&secp, &msg, &seckey, &mut rng);
336+
let sig = sign(&secp, &msg, &kp, &mut rng);
336337

337-
assert!(secp.verify_schnorr(&sig, &msg, &pubkey).is_ok());
338+
assert!(secp.verify_schnorr(&sig, &msg, &pk).is_ok());
338339
}
339340
}
340341

@@ -390,10 +391,12 @@ mod tests {
390391
#[test]
391392
fn test_pubkey_serialize_roundtrip() {
392393
let secp = Secp256k1::new();
393-
let (_, pubkey) = secp.generate_schnorrsig_keypair(&mut thread_rng());
394-
let ser = pubkey.serialize();
394+
let kp = KeyPair::new(&secp, &mut thread_rng());
395+
let pk = kp.public_key();
396+
397+
let ser = pk.serialize();
395398
let pubkey2 = XOnlyPublicKey::from_slice(&ser).unwrap();
396-
assert_eq!(pubkey, pubkey2);
399+
assert_eq!(pk, pubkey2);
397400
}
398401

399402
#[test]
@@ -405,7 +408,7 @@ mod tests {
405408
assert_eq!(SecretKey::from_str(sk_str).unwrap(), sk);
406409
let pk = ::key::PublicKey::from_keypair(&keypair);
407410
assert_eq!(::key::PublicKey::from_secret_key(&secp, &sk), pk);
408-
let xpk = XOnlyPublicKey::from_keypair(&keypair);
411+
let xpk = keypair.public_key();
409412
assert_eq!(XOnlyPublicKey::from(pk), xpk);
410413
}
411414

@@ -445,12 +448,12 @@ mod tests {
445448
0x63, 0x63, 0x63, 0x63,
446449
];
447450

448-
let sk = KeyPair::from_seckey_slice(&secp, &SK_BYTES).expect("sk");
451+
let kp = KeyPair::from_seckey_slice(&secp, &SK_BYTES).expect("sk");
449452

450453
// In fuzzing mode secret->public key derivation is different, so
451454
// hard-code the epected result.
452455
#[cfg(not(fuzzing))]
453-
let pk = XOnlyPublicKey::from_keypair(&sk);
456+
let pk = kp.public_key();
454457
#[cfg(fuzzing)]
455458
let pk = XOnlyPublicKey::from_slice(&[0x18, 0x84, 0x57, 0x81, 0xf6, 0x31, 0xc4, 0x8f, 0x1c, 0x97, 0x09, 0xe2, 0x30, 0x92, 0x06, 0x7d, 0x06, 0x83, 0x7f, 0x30, 0xaa, 0x0c, 0xd0, 0x54, 0x4a, 0xc8, 0x87, 0xfe, 0x91, 0xdd, 0xd1, 0x66]).expect("pk");
456459

@@ -512,10 +515,11 @@ mod tests {
512515
}
513516
}
514517

515-
let s = Secp256k1::new();
516-
let (_, pubkey) = s.generate_schnorrsig_keypair(&mut DumbRng(0));
518+
let secp = Secp256k1::new();
519+
let kp = KeyPair::new(&secp, &mut DumbRng(0));
520+
let pk = kp.public_key();
517521
assert_eq!(
518-
&pubkey.serialize()[..],
522+
&pk.serialize()[..],
519523
&[
520524
124, 121, 49, 14, 253, 63, 197, 50, 39, 194, 107, 17, 193, 219, 108, 154, 126, 9,
521525
181, 248, 2, 12, 149, 233, 198, 71, 149, 134, 250, 184, 154, 229

0 commit comments

Comments
 (0)