Skip to content

update deprecation versions and bump minor version #809

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo-minimal.lock
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2"

[[package]]
name = "secp256k1"
version = "0.31.0"
version = "0.31.1"
dependencies = [
"bincode",
"bitcoin_hashes",
Expand Down
2 changes: 1 addition & 1 deletion Cargo-recent.lock
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294"

[[package]]
name = "secp256k1"
version = "0.31.0"
version = "0.31.1"
dependencies = [
"bincode",
"bitcoin_hashes",
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "secp256k1"
version = "0.31.0"
version = "0.31.1"
authors = [ "Dawid Ciężarkiewicz <[email protected]>",
"Andrew Poelstra <[email protected]>" ]
license = "CC0-1.0"
Expand Down
6 changes: 3 additions & 3 deletions examples/sign_verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn verify<C: Verification>(
pubkey: [u8; 33],
) -> Result<bool, Error> {
let msg = sha256::Hash::hash(msg);
let msg = Message::from_digest_slice(msg.as_ref())?;
let msg = Message::from_digest(msg.to_byte_array());
let sig = ecdsa::Signature::from_compact(&sig)?;
let pubkey = PublicKey::from_slice(&pubkey)?;

Expand All @@ -24,8 +24,8 @@ fn sign<C: Signing>(
seckey: [u8; 32],
) -> Result<ecdsa::Signature, Error> {
let msg = sha256::Hash::hash(msg);
let msg = Message::from_digest_slice(msg.as_ref())?;
let seckey = SecretKey::from_slice(&seckey)?;
let msg = Message::from_digest(msg.to_byte_array());
let seckey = SecretKey::from_byte_array(seckey)?;
Ok(secp.sign_ecdsa(msg, &seckey))
}

Expand Down
6 changes: 3 additions & 3 deletions examples/sign_verify_recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn recover<C: Verification>(
recovery_id: u8,
) -> Result<PublicKey, Error> {
let msg = sha256::Hash::hash(msg);
let msg = Message::from_digest_slice(msg.as_ref())?;
let msg = Message::from_digest(msg.to_byte_array());
let id = ecdsa::RecoveryId::try_from(i32::from(recovery_id))?;
let sig = ecdsa::RecoverableSignature::from_compact(&sig, id)?;

Expand All @@ -24,8 +24,8 @@ fn sign_recovery<C: Signing>(
seckey: [u8; 32],
) -> Result<ecdsa::RecoverableSignature, Error> {
let msg = sha256::Hash::hash(msg);
let msg = Message::from_digest_slice(msg.as_ref())?;
let seckey = SecretKey::from_slice(&seckey)?;
let msg = Message::from_digest(msg.to_byte_array());
let seckey = SecretKey::from_byte_array(seckey)?;
Ok(secp.sign_ecdsa_recoverable(msg, &seckey))
}

Expand Down
6 changes: 3 additions & 3 deletions src/ecdh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl SharedSecret {
pub fn from_bytes(bytes: [u8; SHARED_SECRET_SIZE]) -> SharedSecret { SharedSecret(bytes) }

/// Creates a shared secret from `bytes` slice.
#[deprecated(since = "TBD", note = "Use `from_bytes` instead.")]
#[deprecated(since = "0.31.0", note = "Use `from_bytes` instead.")]
#[inline]
pub fn from_slice(bytes: &[u8]) -> Result<SharedSecret, Error> {
match bytes.len() {
Expand Down Expand Up @@ -178,7 +178,7 @@ impl<'de> ::serde::Deserialize<'de> for SharedSecret {
} else {
d.deserialize_bytes(super::serde_util::BytesVisitor::new(
"raw 32 bytes SharedSecret",
SharedSecret::from_slice,
|x| x.try_into().map(SharedSecret::from_bytes),
))
}
}
Expand Down Expand Up @@ -263,7 +263,7 @@ mod tests {
];
static STR: &str = "01010101010101010001020304050607ffff0000ffff00006363636363636363";

let secret = SharedSecret::from_slice(&BYTES).unwrap();
let secret = SharedSecret::from_bytes(BYTES);

assert_tokens(&secret.compact(), &[Token::BorrowedBytes(&BYTES[..])]);
assert_tokens(&secret.compact(), &[Token::Bytes(&BYTES)]);
Expand Down
24 changes: 12 additions & 12 deletions src/ecdsa/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ mod tests {
let full = Secp256k1::new();

let msg = crate::random_32_bytes(&mut rand::rng());
let msg = Message::from_digest_slice(&msg).unwrap();
let msg = Message::from_digest(msg);

// Try key generation
let (sk, pk) = full.generate_keypair(&mut rand::rng());
Expand Down Expand Up @@ -302,8 +302,8 @@ mod tests {
let mut s = Secp256k1::new();
s.randomize(&mut rand::rng());

let sk = SecretKey::from_slice(&ONE).unwrap();
let msg = Message::from_digest_slice(&ONE).unwrap();
let sk = SecretKey::from_byte_array(ONE).unwrap();
let msg = Message::from_digest(ONE);

let sig = s.sign_ecdsa_recoverable(msg, &sk);

Expand All @@ -327,8 +327,8 @@ mod tests {
let mut s = Secp256k1::new();
s.randomize(&mut rand::rng());

let sk = SecretKey::from_slice(&ONE).unwrap();
let msg = Message::from_digest_slice(&ONE).unwrap();
let sk = SecretKey::from_byte_array(ONE).unwrap();
let msg = Message::from_digest(ONE);
let noncedata = [42u8; 32];

let sig = s.sign_ecdsa_recoverable_with_noncedata(msg, &sk, &noncedata);
Expand All @@ -352,15 +352,15 @@ mod tests {
s.randomize(&mut rand::rng());

let msg = crate::random_32_bytes(&mut rand::rng());
let msg = Message::from_digest_slice(&msg).unwrap();
let msg = Message::from_digest(msg);

let (sk, pk) = s.generate_keypair(&mut rand::rng());

let sigr = s.sign_ecdsa_recoverable(msg, &sk);
let sig = sigr.to_standard();

let msg = crate::random_32_bytes(&mut rand::rng());
let msg = Message::from_digest_slice(&msg).unwrap();
let msg = Message::from_digest(msg);
assert_eq!(s.verify_ecdsa(&sig, msg, &pk), Err(Error::IncorrectSignature));

let recovered_key = s.recover_ecdsa(msg, &sigr).unwrap();
Expand All @@ -374,7 +374,7 @@ mod tests {
s.randomize(&mut rand::rng());

let msg = crate::random_32_bytes(&mut rand::rng());
let msg = Message::from_digest_slice(&msg).unwrap();
let msg = Message::from_digest(msg);

let (sk, pk) = s.generate_keypair(&mut rand::rng());

Expand All @@ -390,7 +390,7 @@ mod tests {
s.randomize(&mut rand::rng());

let msg = crate::random_32_bytes(&mut rand::rng());
let msg = Message::from_digest_slice(&msg).unwrap();
let msg = Message::from_digest(msg);

let noncedata = [42u8; 32];

Expand All @@ -407,7 +407,7 @@ mod tests {
let mut s = Secp256k1::new();
s.randomize(&mut rand::rng());

let msg = Message::from_digest_slice(&[0x55; 32]).unwrap();
let msg = Message::from_digest([0x55; 32]);

// Zero is not a valid sig
let sig = RecoverableSignature::from_compact(&[0; 64], RecoveryId::Zero).unwrap();
Expand Down Expand Up @@ -478,8 +478,8 @@ mod benches {
pub fn bench_recover(bh: &mut Bencher) {
let s = Secp256k1::new();
let msg = crate::random_32_bytes(&mut rand::rng());
let msg = Message::from_digest_slice(&msg).unwrap();
let (sk, _) = s.generate_keypair(&mut rand::rng());
let msg = Message::from_digest(msg);
let (sk, _) = s.generate_keypair(&mut rand::thread_rng());
let sig = s.sign_ecdsa_recoverable(&msg, &sk);

bh.iter(|| {
Expand Down
2 changes: 1 addition & 1 deletion src/ecdsa/serialized_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl PartialEq<SerializedSignature> for [u8] {

impl PartialOrd for SerializedSignature {
fn partial_cmp(&self, other: &SerializedSignature) -> Option<core::cmp::Ordering> {
Some((**self).cmp(&**other))
Some(self.cmp(other))
}
}

Expand Down
14 changes: 8 additions & 6 deletions src/ellswift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ mod tests {
// Test that we can round trip an ElligatorSwift encoding
let secp = crate::Secp256k1::new();
let public_key =
PublicKey::from_secret_key(&secp, &SecretKey::from_slice(&[1u8; 32]).unwrap());
PublicKey::from_secret_key(&secp, &SecretKey::from_byte_array([1u8; 32]).unwrap());

let ell = ElligatorSwift::from_pubkey(public_key);
let pk = PublicKey::from_ellswift(ell);
Expand All @@ -391,9 +391,11 @@ mod tests {
let secp = crate::Secp256k1::new();
let rand32 = [1u8; 32];
let priv32 = [1u8; 32];
let ell = ElligatorSwift::from_seckey(&secp, SecretKey::from_slice(&rand32).unwrap(), None);
let ell =
ElligatorSwift::from_seckey(&secp, SecretKey::from_byte_array(rand32).unwrap(), None);
let pk = PublicKey::from_ellswift(ell);
let expected = PublicKey::from_secret_key(&secp, &SecretKey::from_slice(&priv32).unwrap());
let expected =
PublicKey::from_secret_key(&secp, &SecretKey::from_byte_array(priv32).unwrap());

assert_eq!(pk, expected);
}
Expand All @@ -406,13 +408,13 @@ mod tests {
let priv32 = [2u8; 32];
let ell = ElligatorSwift::from_seckey(
&secp,
SecretKey::from_slice(&rand32).unwrap(),
SecretKey::from_byte_array(rand32).unwrap(),
Some(rand32),
);
let pk = ElligatorSwift::shared_secret_with_hasher(
ell,
ell,
SecretKey::from_slice(&priv32).unwrap(),
SecretKey::from_byte_array(priv32).unwrap(),
Party::Initiator,
|_, _, _| ElligatorSwiftSharedSecret([0xff; 32]),
);
Expand Down Expand Up @@ -626,7 +628,7 @@ mod tests {
ElligatorSwift::from_array(ellswift_theirs),
)
};
let sec_key = SecretKey::from_slice(&my_secret).unwrap();
let sec_key = SecretKey::from_byte_array(my_secret).unwrap();
let initiator = if initiator == 0 { Party::Responder } else { Party::Initiator };

let shared = ElligatorSwift::shared_secret(el_a, el_b, sec_key, initiator, None);
Expand Down
43 changes: 23 additions & 20 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl SecretKey {
/// use secp256k1::SecretKey;
/// let sk = SecretKey::from_slice(&[0xcd; 32]).expect("32 bytes, within curve order");
/// ```
#[deprecated(since = "TBD", note = "Use `from_byte_array` instead.")]
#[deprecated(since = "0.31.0", note = "Use `from_byte_array` instead.")]
#[inline]
pub fn from_slice(data: &[u8]) -> Result<SecretKey, Error> {
match <[u8; constants::SECRET_KEY_SIZE]>::try_from(data) {
Expand Down Expand Up @@ -402,10 +402,10 @@ impl<'de> serde::Deserialize<'de> for SecretKey {
"a hex string representing 32 byte SecretKey",
))
} else {
let visitor =
super::serde_util::Tuple32Visitor::new("raw 32 bytes SecretKey", |bytes| {
SecretKey::from_byte_array(bytes)
});
let visitor = super::serde_util::Tuple32Visitor::new(
"raw 32 bytes SecretKey",
SecretKey::from_byte_array,
);
d.deserialize_tuple(constants::SECRET_KEY_SIZE, visitor)
}
}
Expand Down Expand Up @@ -791,10 +791,10 @@ impl<'de> serde::Deserialize<'de> for PublicKey {
"an ASCII hex string representing a public key",
))
} else {
let visitor =
super::serde_util::Tuple33Visitor::new("33 bytes compressed public key", |bytes| {
PublicKey::from_byte_array_compressed(bytes)
});
let visitor = super::serde_util::Tuple33Visitor::new(
"33 bytes compressed public key",
PublicKey::from_byte_array_compressed,
);
d.deserialize_tuple(constants::PUBLIC_KEY_SIZE, visitor)
}
}
Expand Down Expand Up @@ -861,7 +861,7 @@ impl Keypair {
///
/// [`Error::InvalidSecretKey`] if the slice is not exactly 32 bytes long,
/// or if the encoded number is an invalid scalar.
#[deprecated(since = "TBD", note = "Use `from_seckey_byte_array` instead.")]
#[deprecated(since = "0.31.0", note = "Use `from_seckey_byte_array` instead.")]
#[inline]
pub fn from_seckey_slice<C: Signing>(
secp: &Secp256k1<C>,
Expand Down Expand Up @@ -1240,7 +1240,7 @@ impl XOnlyPublicKey {
///
/// Returns [`Error::InvalidPublicKey`] if the length of the data slice is not 32 bytes or the
/// slice does not represent a valid Secp256k1 point x coordinate.
#[deprecated(since = "TBD", note = "Use `from_byte_array` instead.")]
#[deprecated(since = "0.31.0", note = "Use `from_byte_array` instead.")]
#[inline]
pub fn from_slice(data: &[u8]) -> Result<XOnlyPublicKey, Error> {
match <[u8; constants::SCHNORR_PUBLIC_KEY_SIZE]>::try_from(data) {
Expand Down Expand Up @@ -1673,6 +1673,7 @@ mod test {
use crate::{constants, from_hex, to_hex, Scalar};

#[test]
#[allow(deprecated)]
fn skey_from_slice() {
let sk = SecretKey::from_slice(&[1; 31]);
assert_eq!(sk, Err(InvalidSecretKey));
Expand Down Expand Up @@ -1707,7 +1708,7 @@ mod test {
let s = Secp256k1::new();

let (sk1, pk1) = s.generate_keypair(&mut rand::rng());
assert_eq!(SecretKey::from_slice(&sk1[..]), Ok(sk1));
assert_eq!(SecretKey::from_byte_array(sk1.secret_bytes()), Ok(sk1));
assert_eq!(PublicKey::from_slice(&pk1.serialize()[..]), Ok(pk1));
assert_eq!(PublicKey::from_slice(&pk1.serialize_uncompressed()[..]), Ok(pk1));
}
Expand All @@ -1727,22 +1728,22 @@ mod test {
#[rustfmt::skip]
fn invalid_secret_key() {
// Zero
assert_eq!(SecretKey::from_slice(&[0; 32]), Err(InvalidSecretKey));
assert_eq!(SecretKey::from_byte_array([0; 32]), Err(InvalidSecretKey));
assert_eq!(
SecretKey::from_str("0000000000000000000000000000000000000000000000000000000000000000"),
Err(InvalidSecretKey)
);
// -1
assert_eq!(SecretKey::from_slice(&[0xff; 32]), Err(InvalidSecretKey));
assert_eq!(SecretKey::from_byte_array([0xff; 32]), Err(InvalidSecretKey));
// Top of range
assert!(SecretKey::from_slice(&[
assert!(SecretKey::from_byte_array([
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B,
0xBF, 0xD2, 0x5E, 0x8C, 0xD0, 0x36, 0x41, 0x40,
]).is_ok());
// One past top of range
assert!(SecretKey::from_slice(&[
assert!(SecretKey::from_byte_array([
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE,
0xBA, 0xAE, 0xDC, 0xE6, 0xAF, 0x48, 0xA0, 0x3B,
Expand Down Expand Up @@ -1811,6 +1812,7 @@ mod test {
}

#[test]
#[allow(deprecated)]
fn test_seckey_from_bad_slice() {
// Bad sizes
assert_eq!(
Expand Down Expand Up @@ -1864,7 +1866,7 @@ mod test {

#[cfg(not(secp256k1_fuzz))]
let s = Secp256k1::signing_only();
let sk = SecretKey::from_slice(&SK_BYTES).expect("sk");
let sk = SecretKey::from_byte_array(SK_BYTES).expect("sk");

// In fuzzing mode secret->public key derivation is different, so
// hard-code the expected result.
Expand Down Expand Up @@ -2219,7 +2221,7 @@ mod test {

#[cfg(not(secp256k1_fuzz))]
let s = Secp256k1::new();
let sk = SecretKey::from_slice(&SK_BYTES).unwrap();
let sk = SecretKey::from_byte_array(SK_BYTES).unwrap();

// In fuzzing mode secret->public key derivation is different, so
// hard-code the expected result.
Expand Down Expand Up @@ -2359,10 +2361,11 @@ mod test {
pk_bytes[0] = 0x02; // Use positive Y co-ordinate.
pk_bytes[1..].clone_from_slice(&PK_BYTES);

let sk = SecretKey::from_slice(&SK_BYTES).expect("failed to parse sk bytes");
let sk = SecretKey::from_byte_array(SK_BYTES).expect("failed to parse sk bytes");
let pk = PublicKey::from_slice(&pk_bytes).expect("failed to create pk from iterator");
let kp = Keypair::from_secret_key(&secp, &sk);
let xonly = XOnlyPublicKey::from_slice(&PK_BYTES).expect("failed to get xonly from slice");
let xonly =
XOnlyPublicKey::from_byte_array(PK_BYTES).expect("failed to get xonly from slice");

(sk, pk, kp, xonly)
}
Expand Down
Loading
Loading