Drop From<Keypair> for secp256k1::PublicKey
What changed, and why it matters
This commit removes a convenience conversion that let users turn a Bitcoin-style key pair directly into a lower-level secp256k1 public key. The change is defensive: it makes it slightly harder to accidentally mix the library's own key types with raw secp256k1 types, which can help prevent API misuse. There is no direct bug or exploit being fixed.
No urgent action. Treat as a minor API cleanup. Downstream users relying on `secp256k1::PublicKey::from(keypair)` should replace it with `keypair.to_public_key().to_inner()`.
Security signals we found
Removal of an implicit type conversion between library key types and raw secp256k1 types
Defensive API hardening to discourage mixing of abstraction layers
No memory safety, cryptographic, or authorization flaw is patched
Evidence from the diff
The patch deletes impl From<Keypair> for secp256k1::PublicKey from crypto/src/key.rs. That implementation simply called kp.to_public_key().to_inner(). The only in-tree caller was a test, which now performs those two calls explicitly. The commit message frames this as a design-hardening change to avoid trivial conversions from bitcoin types to secp types.
Changed components
crypto/src/key.rsbitcoin::crypto::key::Keypairsecp256k1::PublicKey conversion traitInspect captured patch +3 / −7
diff --git a/crypto/src/key.rs b/crypto/src/key.rs
index d48b6c87..e51dd2e9 100644
--- a/crypto/src/key.rs
+++ b/crypto/src/key.rs
@@ -558,10 +558,6 @@ impl From<secp256k1::Keypair> for Keypair {
fn from(pk: secp256k1::Keypair) -> Self { Self::from_secp(pk) }
}
-impl From<Keypair> for secp256k1::PublicKey {
- fn from(kp: Keypair) -> Self { kp.to_public_key().to_inner() }
-}
-
impl From<PrivateKey> for Keypair {
fn from(pk: PrivateKey) -> Self { Self::from(&pk) }
}
@@ -2000,10 +1996,10 @@ mod tests {
#[cfg(feature = "rand")]
#[cfg(feature = "std")]
fn public_key_constructors() {
- let kp = Keypair::generate();
+ let pk = Keypair::generate().to_public_key().to_inner();
- let _ = LegacyPublicKey::from_secp(kp.clone());
- let _ = LegacyPublicKey::from_secp_uncompressed(kp);
+ let _ = LegacyPublicKey::from_secp(pk);
+ let _ = LegacyPublicKey::from_secp_uncompressed(pk);
}
#[test]
Why this scored 16/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.