Expand From impls for CompressedPublicKey
What changed, and why it matters
This commit adds convenience conversion methods so that a CompressedPublicKey can be created directly from a secp256k1 public key or a keypair, matching the existing abilities of the regular PublicKey type. It is a routine API usability improvement with no apparent security relevance.
No security action required; review as normal API refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch introduces From
Changed components
bitcoin/src/crypto/key.rsCompressedPublicKeyPublicKeyInspect captured patch +10 / −3
diff --git a/bitcoin/src/crypto/key.rs b/bitcoin/src/crypto/key.rs
index 5f874926..364801fd 100644
--- a/bitcoin/src/crypto/key.rs
+++ b/bitcoin/src/crypto/key.rs
@@ -666,9 +666,7 @@ impl PublicKey {
pub fn from_private_key(sk: PrivateKey) -> Self { sk.to_public_key() }
/// Extracts the public key from a Keypair
- pub fn from_keypair(pair: &Keypair) -> Self {
- Self::from_secp(secp256k1::PublicKey::from_keypair(pair.as_inner()))
- }
+ pub fn from_keypair(pair: &Keypair) -> Self { CompressedPublicKey::from_keypair(pair).into() }
/// Checks that `sig` is a valid ECDSA signature for `msg` using this public key.
///
@@ -843,6 +841,11 @@ impl CompressedPublicKey {
sk.to_public_key().try_into()
}
+ /// Extracts the public key from a Keypair
+ pub fn from_keypair(pair: &Keypair) -> Self {
+ Self::from_secp(secp256k1::PublicKey::from_keypair(pair.as_inner()))
+ }
+
/// Checks that `sig` is a valid ECDSA signature for `msg` using this public key.
///
/// # Errors
@@ -889,6 +892,10 @@ impl TryFrom<PublicKey> for CompressedPublicKey {
}
}
+impl From<secp256k1::PublicKey> for CompressedPublicKey {
+ fn from(pk: secp256k1::PublicKey) -> Self { Self::from_secp(pk) }
+}
+
impl From<CompressedPublicKey> for PublicKey {
fn from(value: CompressedPublicKey) -> Self { Self::from_secp(value.to_inner()) }
}
Why this scored 18/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.