Introduce from_secp constructor for Keypair
What changed, and why it matters
This commit is a routine code cleanup. It adds a new public constructor method called from_secp for the Keypair type and makes the existing From conversion use that constructor. It also moves an existing inner accessor method to a different spot in the file. There is no security fix or behavior change.
No security action needed. Treat as normal refactoring/API ergonomics improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch introduces Keypair::from_secp(keypair: impl Into
Changed components
bitcoin/src/crypto/key.rsKeypair typeInspect captured patch +9 / −5
diff --git a/bitcoin/src/crypto/key.rs b/bitcoin/src/crypto/key.rs
index 397f650e..622c4d16 100644
--- a/bitcoin/src/crypto/key.rs
+++ b/bitcoin/src/crypto/key.rs
@@ -150,6 +150,14 @@ impl fmt::Display for XOnlyPublicKey {
pub struct Keypair(secp256k1::Keypair);
impl Keypair {
+ /// Constructs a keypair from a provided secp256k1 keypair.
+ #[inline]
+ pub fn from_secp(keypair: impl Into<secp256k1::Keypair>) -> Self { Self(keypair.into()) }
+
+ /// Returns the inner [`secp256k1::Keypair`].
+ #[inline]
+ pub fn to_inner(self) -> secp256k1::Keypair { self.0 }
+
/// Generates a new random key pair.
///
/// # Examples
@@ -173,10 +181,6 @@ impl Keypair {
Self::from(secp256k1::Keypair::from_secret_key(sk))
}
- /// Returns the inner [`secp256k1::Keypair`].
- #[inline]
- pub fn to_inner(self) -> secp256k1::Keypair { self.0 }
-
/// Returns the [`PrivateKey`] for this [`Keypair`].
///
/// This is equivalent to using [`secp256k1::SecretKey::from_keypair`] on the inner value.
@@ -212,7 +216,7 @@ impl FromStr for Keypair {
}
impl From<secp256k1::Keypair> for Keypair {
- fn from(pk: secp256k1::Keypair) -> Self { Self(pk) }
+ fn from(pk: secp256k1::Keypair) -> Self { Self::from_secp(pk) }
}
impl From<Keypair> for secp256k1::PublicKey {
Why this scored 15/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.