From 8c7c5e73943d7a3cde595242ff423028f603c23f Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 10 Nov 2022 11:28:04 +1100 Subject: [PATCH] Remove deprecated code We are currently on version 0.24.1 (i.e., next release is 0.25.0), we can comfortably remove any code deprecated in 0.23.x or earlier. --- src/constants.rs | 8 ---- src/ecdsa/mod.rs | 58 --------------------------- src/ecdsa/recovery.rs | 14 ------- src/key.rs | 92 ------------------------------------------- src/lib.rs | 19 --------- src/schnorr.rs | 74 ---------------------------------- 6 files changed, 265 deletions(-) diff --git a/src/constants.rs b/src/constants.rs index 803ecba..57cc441 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -37,17 +37,9 @@ pub const COMPACT_SIGNATURE_SIZE: usize = 64; /// The size of a Schnorr signature. pub const SCHNORR_SIGNATURE_SIZE: usize = 64; -/// The size of a Schnorr signature. -#[deprecated(since = "0.22.0", note = "Use SCHNORR_SIGNATURE_SIZE instead.")] -pub const SCHNORRSIG_SIGNATURE_SIZE: usize = SCHNORR_SIGNATURE_SIZE; - /// The size of a Schnorr public key. pub const SCHNORR_PUBLIC_KEY_SIZE: usize = 32; -/// The size of a Schnorr public key. -#[deprecated(since = "0.22.0", note = "Use SCHNORR_PUBLIC_KEY_SIZE instead.")] -pub const SCHNORRSIG_PUBLIC_KEY_SIZE: usize = SCHNORR_PUBLIC_KEY_SIZE; - /// The size of a key pair. pub const KEY_PAIR_SIZE: usize = 96; diff --git a/src/ecdsa/mod.rs b/src/ecdsa/mod.rs index d38a487..7ae1cb6 100644 --- a/src/ecdsa/mod.rs +++ b/src/ecdsa/mod.rs @@ -245,14 +245,6 @@ impl<'de> serde::Deserialize<'de> for Signature { } impl Secp256k1 { - - /// Constructs a signature for `msg` using the secret key `sk` and RFC6979 nonce - /// Requires a signing-capable context. - #[deprecated(since = "0.21.0", note = "Use sign_ecdsa instead.")] - pub fn sign(&self, msg: &Message, sk: &SecretKey) -> Signature { - self.sign_ecdsa(msg, sk) - } - fn sign_ecdsa_with_noncedata_pointer( &self, msg: &Message, @@ -324,17 +316,6 @@ impl Secp256k1 { } } - /// Constructs a signature for `msg` using the secret key `sk`, RFC6979 nonce - /// and "grinds" the nonce by passing extra entropy if necessary to produce - /// a signature that is less than 71 - `bytes_to_grind` bytes. The number - /// of signing operation performed by this function is exponential in the - /// number of bytes grinded. - /// Requires a signing capable context. - #[deprecated(since = "0.21.0", note = "Use sign_ecdsa_grind_r instead.")] - pub fn sign_grind_r(&self, msg: &Message, sk: &SecretKey, bytes_to_grind: usize) -> Signature { - self.sign_ecdsa_grind_r(msg, sk, bytes_to_grind) - } - /// Constructs a signature for `msg` using the secret key `sk`, RFC6979 nonce /// and "grinds" the nonce by passing extra entropy if necessary to produce /// a signature that is less than 71 - `bytes_to_grind` bytes. The number @@ -346,17 +327,6 @@ impl Secp256k1 { self.sign_grind_with_check(msg, sk, len_check) } - /// Constructs a signature for `msg` using the secret key `sk`, RFC6979 nonce - /// and "grinds" the nonce by passing extra entropy if necessary to produce - /// a signature that is less than 71 bytes and compatible with the low r - /// signature implementation of bitcoin core. In average, this function - /// will perform two signing operations. - /// Requires a signing capable context. - #[deprecated(since = "0.21.0", note = "Use sign_ecdsa_low_r instead.")] - pub fn sign_low_r(&self, msg: &Message, sk: &SecretKey) -> Signature { - self.sign_grind_with_check(msg, sk, compact_sig_has_zero_first_bit) - } - /// Constructs a signature for `msg` using the secret key `sk`, RFC6979 nonce /// and "grinds" the nonce by passing extra entropy if necessary to produce /// a signature that is less than 71 bytes and compatible with the low r @@ -369,34 +339,6 @@ impl Secp256k1 { } impl Secp256k1 { - /// Checks that `sig` is a valid ECDSA signature for `msg` using the public - /// key `pubkey`. Returns `Ok(())` on success. Note that this function cannot - /// be used for Bitcoin consensus checking since there may exist signatures - /// which OpenSSL would verify but not libsecp256k1, or vice-versa. Requires a - /// verify-capable context. - /// - /// ```rust - /// # #[cfg(all(feature = "std", feature = "rand-std"))] { - /// # use secp256k1::rand::thread_rng; - /// # use secp256k1::{Secp256k1, Message, Error}; - /// # - /// # let secp = Secp256k1::new(); - /// # let (secret_key, public_key) = secp.generate_keypair(&mut thread_rng()); - /// # - /// let message = Message::from_slice(&[0xab; 32]).expect("32 bytes"); - /// let sig = secp.sign(&message, &secret_key); - /// assert_eq!(secp.verify(&message, &sig, &public_key), Ok(())); - /// - /// let message = Message::from_slice(&[0xcd; 32]).expect("32 bytes"); - /// assert_eq!(secp.verify(&message, &sig, &public_key), Err(Error::IncorrectSignature)); - /// # } - /// ``` - #[inline] - #[deprecated(since = "0.21.0", note = "Use verify_ecdsa instead")] - pub fn verify(&self, msg: &Message, sig: &Signature, pk: &PublicKey) -> Result<(), Error> { - self.verify_ecdsa(msg, sig, pk) - } - /// Checks that `sig` is a valid ECDSA signature for `msg` using the public /// key `pubkey`. Returns `Ok(())` on success. Note that this function cannot /// be used for Bitcoin consensus checking since there may exist signatures diff --git a/src/ecdsa/recovery.rs b/src/ecdsa/recovery.rs index b8ac314..c60fdec 100644 --- a/src/ecdsa/recovery.rs +++ b/src/ecdsa/recovery.rs @@ -150,13 +150,6 @@ impl From for RecoverableSignature { } impl Secp256k1 { - /// Constructs a signature for `msg` using the secret key `sk` and RFC6979 nonce. - /// Requires a signing-capable context. - #[deprecated(since = "0.21.0", note = "Use sign_ecdsa_recoverable instead.")] - pub fn sign_recoverable(&self, msg: &Message, sk: &key::SecretKey) -> RecoverableSignature { - self.sign_ecdsa_recoverable(msg, sk) - } - fn sign_ecdsa_recoverable_with_noncedata_pointer( &self, msg: &Message, @@ -206,13 +199,6 @@ impl Secp256k1 { } impl Secp256k1 { - /// Determines the public key for which `sig` is a valid signature for - /// `msg`. Requires a verify-capable context. - #[deprecated(since = "0.21.0", note = "Use recover_ecdsa instead.")] - pub fn recover(&self, msg: &Message, sig: &RecoverableSignature) -> Result { - self.recover_ecdsa(msg, sig) - } - /// Determines the public key for which `sig` is a valid signature for /// `msg`. Requires a verify-capable context. pub fn recover_ecdsa(&self, msg: &Message, sig: &RecoverableSignature) diff --git a/src/key.rs b/src/key.rs index 62dce8c..6e11c83 100644 --- a/src/key.rs +++ b/src/key.rs @@ -259,13 +259,6 @@ impl SecretKey { self.0 } - /// Negates the secret key. - #[inline] - #[deprecated(since = "0.23.0", note = "Use negate instead")] - pub fn negate_assign(&mut self) { - *self = self.negate() - } - /// Negates the secret key. #[inline] #[must_use = "you forgot to use the negated secret key"] @@ -280,18 +273,6 @@ impl SecretKey { self } - /// Adds one secret key to another, modulo the curve order. - /// - /// # Errors - /// - /// Returns an error if the resulting key would be invalid. - #[inline] - #[deprecated(since = "0.23.0", note = "Use add_tweak instead")] - pub fn add_assign(&mut self, other: &Scalar) -> Result<(), Error> { - *self = self.add_tweak(other)?; - Ok(()) - } - /// Tweaks a [`SecretKey`] by adding `tweak` modulo the curve order. /// /// # Errors @@ -313,15 +294,6 @@ impl SecretKey { } } - /// Multiplies one secret key by another, modulo the curve order. Will - /// return an error if the resulting key would be invalid. - #[inline] - #[deprecated(since = "0.23.0", note = "Use mul_tweak instead")] - pub fn mul_assign(&mut self, other: &Scalar) -> Result<(), Error> { - *self = self.mul_tweak(other)?; - Ok(()) - } - /// Tweaks a [`SecretKey`] by multiplying by `tweak` modulo the curve order. /// /// # Errors @@ -561,13 +533,6 @@ impl PublicKey { debug_assert_eq!(ret_len, ret.len()); } - /// Negates the public key in place. - #[inline] - #[deprecated(since = "0.23.0", note = "Use negate instead")] - pub fn negate_assign(&mut self, secp: &Secp256k1) { - *self = self.negate(secp) - } - /// Negates the public key. #[inline] #[must_use = "you forgot to use the negated public key"] @@ -579,22 +544,6 @@ impl PublicKey { self } - /// Adds `other * G` to `self` in place. - /// - /// # Errors - /// - /// Returns an error if the resulting key would be invalid. - #[inline] - #[deprecated(since = "0.23.0", note = "Use add_exp_tweak instead")] - pub fn add_exp_assign( - &mut self, - secp: &Secp256k1, - other: &Scalar - ) -> Result<(), Error> { - *self = self.add_exp_tweak(secp, other)?; - Ok(()) - } - /// Tweaks a [`PublicKey`] by adding `tweak * G` modulo the curve order. /// /// # Errors @@ -615,22 +564,6 @@ impl PublicKey { } } - /// Muliplies the public key in place by the scalar `other`. - /// - /// # Errors - /// - /// Returns an error if the resulting key would be invalid. - #[deprecated(since = "0.23.0", note = "Use mul_tweak instead")] - #[inline] - pub fn mul_assign( - &mut self, - secp: &Secp256k1, - other: &Scalar, - ) -> Result<(), Error> { - *self = self.mul_tweak(secp, other)?; - Ok(()) - } - /// Tweaks a [`PublicKey`] by multiplying by `tweak` modulo the curve order. /// /// # Errors @@ -968,19 +901,6 @@ impl KeyPair { *SecretKey::from_keypair(self).as_ref() } - /// Tweaks a keypair by adding the given tweak to the secret key and updating the public key - /// accordingly. - #[inline] - #[deprecated(since = "0.23.0", note = "Use add_xonly_tweak instead")] - pub fn tweak_add_assign( - &mut self, - secp: &Secp256k1, - tweak: &Scalar, - ) -> Result<(), Error> { - *self = self.add_xonly_tweak(secp, tweak)?; - Ok(()) - } - /// Tweaks a keypair by first converting the public key to an xonly key and tweaking it. /// /// # Errors @@ -1282,18 +1202,6 @@ impl XOnlyPublicKey { ret } - /// Tweaks an x-only PublicKey by adding the generator multiplied with the given tweak to it. - #[deprecated(since = "0.23.0", note = "Use add_tweak instead")] - pub fn tweak_add_assign( - &mut self, - secp: &Secp256k1, - tweak: &Scalar, - ) -> Result { - let (tweaked, parity) = self.add_tweak(secp, tweak)?; - *self = tweaked; - Ok(parity) - } - /// Tweaks an [`XOnlyPublicKey`] by adding the generator multiplied with the given tweak to it. /// /// # Returns diff --git a/src/lib.rs b/src/lib.rs index b70c5be..1b8a7e4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -206,25 +206,6 @@ use crate::ffi::{CPtr, impl_array_newtype, types::AlignedType}; #[cfg(feature = "bitcoin_hashes")] use crate::hashes::Hash; -// Backwards compatible changes -/// Schnorr Signature related methods. -#[deprecated(since = "0.21.0", note = "Use schnorr instead.")] -pub mod schnorrsig { - #[deprecated(since = "0.21.0", note = "Use crate::XOnlyPublicKey instead.")] - /// backwards compatible re-export of xonly key - pub type PublicKey = crate::key::XOnlyPublicKey; - /// backwards compatible re-export of keypair - #[deprecated(since = "0.21.0", note = "Use crate::KeyPair instead.")] - pub type KeyPair = crate::key::KeyPair; - /// backwards compatible re-export of schnorr signatures - #[deprecated(since = "0.21.0", note = "Use schnorr::Signature instead.")] - pub type Signature = crate::schnorr::Signature; -} - -#[deprecated(since = "0.21.0", note = "Use ecdsa::Signature instead.")] -/// backwards compatible re-export of ecdsa signatures -pub type Signature = ecdsa::Signature; - /// Trait describing something that promises to be a 32-byte random number; in particular, /// it has negligible probability of being zero or overflowing the group order. Such objects /// may be converted to `Message`s without any error paths. diff --git a/src/schnorr.rs b/src/schnorr.rs index f5f602d..f4801d1 100644 --- a/src/schnorr.rs +++ b/src/schnorr.rs @@ -121,15 +121,6 @@ impl Secp256k1 { } } - /// Create a schnorr signature internally using the ThreadRng random number - /// generator to generate the auxiliary random data. - #[cfg(any(test, feature = "rand-std"))] - #[cfg_attr(docsrs, doc(cfg(feature = "rand-std")))] - #[deprecated(since = "0.21.0", note = "Use sign_schnorr instead.")] - pub fn schnorrsig_sign(&self, msg: &Message, keypair: &KeyPair) -> Signature { - self.sign_schnorr(msg, keypair) - } - /// Create a schnorr signature internally using the ThreadRng random number /// generator to generate the auxiliary random data. #[cfg(any(test, feature = "rand-std"))] @@ -138,16 +129,6 @@ impl Secp256k1 { self.sign_schnorr_with_rng(msg, keypair, &mut rand::thread_rng()) } - /// Create a schnorr signature without using any auxiliary random data. - #[deprecated(since = "0.21.0", note = "Use sign_schnorr_no_aux_rand instead.")] - pub fn schnorrsig_sign_no_aux_rand( - &self, - msg: &Message, - keypair: &KeyPair, - ) -> Signature { - self.sign_schnorr_no_aux_rand(msg, keypair) - } - /// Create a schnorr signature without using any auxiliary random data. pub fn sign_schnorr_no_aux_rand( &self, @@ -157,17 +138,6 @@ impl Secp256k1 { self.sign_schnorr_helper(msg, keypair, ptr::null()) } - /// Create a Schnorr signature using the given auxiliary random data. - #[deprecated(since = "0.21.0", note = "Use sign_schnorr_with_aux_rand instead.")] - pub fn schnorrsig_sign_with_aux_rand( - &self, - msg: &Message, - keypair: &KeyPair, - aux_rand: &[u8; 32], - ) -> Signature { - self.sign_schnorr_with_aux_rand(msg, keypair, aux_rand) - } - /// Create a Schnorr signature using the given auxiliary random data. pub fn sign_schnorr_with_aux_rand( &self, @@ -182,20 +152,6 @@ impl Secp256k1 { ) } - /// Create a schnorr signature using the given random number generator to - /// generate the auxiliary random data. - #[cfg(any(test, feature = "rand"))] - #[cfg_attr(docsrs, doc(cfg(feature = "rand")))] - #[deprecated(since = "0.21.0", note = "Use sign_schnorr_with_rng instead.")] - pub fn schnorrsig_sign_with_rng( - &self, - msg: &Message, - keypair: &KeyPair, - rng: &mut R, - ) -> Signature { - self.sign_schnorr_with_rng(msg, keypair, rng) - } - /// Create a schnorr signature using the given random number generator to /// generate the auxiliary random data. #[cfg(any(test, feature = "rand"))] @@ -213,17 +169,6 @@ impl Secp256k1 { } impl Secp256k1 { - /// Verify a Schnorr signature. - #[deprecated(since = "0.21.0", note = "Use verify_schnorr instead.")] - pub fn schnorrsig_verify( - &self, - sig: &Signature, - msg: &Message, - pubkey: &XOnlyPublicKey, - ) -> Result<(), Error> { - self.verify_schnorr(sig, msg, pubkey) - } - /// Verify a Schnorr signature. pub fn verify_schnorr( &self, @@ -249,25 +194,6 @@ impl Secp256k1 { } } -impl Secp256k1 { - /// Generates a random Schnorr `KeyPair` and its associated Schnorr `XOnlyPublicKey`. - /// - /// Convenience function for [KeyPair::new] and [KeyPair::public_key]. - /// Requires a signing-capable context. - #[inline] - #[cfg(any(test, feature = "rand"))] - #[cfg_attr(docsrs, doc(cfg(feature = "rand")))] - #[deprecated(since = "0.21.0", note = "Use kp = KeyPair::new() and kp.x_only_public_key().0")] - pub fn generate_schnorrsig_keypair( - &self, - rng: &mut R, - ) -> (KeyPair, XOnlyPublicKey) { - let sk = KeyPair::new(self, rng); - let (pubkey, _parity) = XOnlyPublicKey::from_keypair(&sk); - (sk, pubkey) - } -} - #[cfg(test)] #[allow(unused_imports)] mod tests {