Skip to content

Commit dc04e55

Browse files
committed
Rename schnorrsig method
Recently we deprecated a bunch of functions/methods that used the term `schnorrsig`. Seems we left `generate_schnorrsig_keypair` in there, along with some stall docs on it. Rename `generate_schnorrsig_keypair` -> `generate_keypair_xonly`. Deprecate the old one and improve the function docs while we are at it.
1 parent d068fd7 commit dc04e55

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

src/key.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1547,7 +1547,7 @@ mod test {
15471547
for _ in 0..10 {
15481548
let mut tweak = [0u8; 32];
15491549
thread_rng().fill_bytes(&mut tweak);
1550-
let (mut kp, mut pk) = s.generate_schnorrsig_keypair(&mut thread_rng());
1550+
let (mut kp, mut pk) = s.generate_keypair_xonly(&mut thread_rng());
15511551
let orig_pk = pk;
15521552
kp.tweak_add_assign(&s, &tweak).expect("Tweak error");
15531553
let parity = pk.tweak_add_assign(&s, &tweak).expect("Tweak error");

src/schnorr.rs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -248,18 +248,35 @@ 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 `key::KeyPair::new` and `key::XOnlyPublicKey::from_keypair`; call
254+
/// those functions directly for batch key generation.
255+
///
256+
/// Requires a signing-capable context and requires compilation with the "rand" feature.
257257
#[inline]
258258
#[cfg(any(test, feature = "rand"))]
259259
#[cfg_attr(docsrs, doc(cfg(feature = "rand")))]
260+
#[deprecated(since = "0.21.0", note = "Use generate_keypair_xonly instead.")]
260261
pub fn generate_schnorrsig_keypair<R: Rng + ?Sized>(
261262
&self,
262263
rng: &mut R,
264+
) -> (KeyPair, XOnlyPublicKey) {
265+
self.generate_keypair_xonly(rng)
266+
}
267+
268+
/// Generates a random Schnorr `KeyPair` and its associated Schnorr `XOnlyPublicKey`.
269+
///
270+
/// Convenience function for `key::KeyPair::new` and `key::XOnlyPublicKey::from_keypair`; call
271+
/// those functions directly for batch key generation.
272+
///
273+
/// Requires a signing-capable context and requires compilation with the "rand" feature.
274+
#[inline]
275+
#[cfg(any(test, feature = "rand"))]
276+
#[cfg_attr(docsrs, doc(cfg(feature = "rand")))]
277+
pub fn generate_keypair_xonly<R: Rng + ?Sized>(
278+
&self,
279+
rng: &mut R,
263280
) -> (KeyPair, XOnlyPublicKey) {
264281
let sk = KeyPair::new(self, rng);
265282
let pubkey = XOnlyPublicKey::from_keypair(&sk);
@@ -325,7 +342,7 @@ mod tests {
325342
let secp = Secp256k1::new();
326343

327344
let mut rng = thread_rng();
328-
let (seckey, pubkey) = secp.generate_schnorrsig_keypair(&mut rng);
345+
let (seckey, pubkey) = secp.generate_keypair_xonly(&mut rng);
329346
let mut msg = [0u8; 32];
330347

331348
for _ in 0..100 {
@@ -390,7 +407,7 @@ mod tests {
390407
#[test]
391408
fn test_pubkey_serialize_roundtrip() {
392409
let secp = Secp256k1::new();
393-
let (_, pubkey) = secp.generate_schnorrsig_keypair(&mut thread_rng());
410+
let (_, pubkey) = secp.generate_keypair_xonly(&mut thread_rng());
394411
let ser = pubkey.serialize();
395412
let pubkey2 = XOnlyPublicKey::from_slice(&ser).unwrap();
396413
assert_eq!(pubkey, pubkey2);
@@ -513,7 +530,7 @@ mod tests {
513530
}
514531

515532
let s = Secp256k1::new();
516-
let (_, pubkey) = s.generate_schnorrsig_keypair(&mut DumbRng(0));
533+
let (_, pubkey) = s.generate_keypair_xonly(&mut DumbRng(0));
517534
assert_eq!(
518535
&pubkey.serialize()[..],
519536
&[

0 commit comments

Comments
 (0)