What changed, and why it matters
This commit is a pure code reorganization: it moves existing Rust 'From' conversion implementations so they sit directly underneath the type they produce, rather than being scattered near the source type. No logic, behavior, or public API changes are visible in the diff.
No security action needed; this is a non-functional refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch in crypto/src/key.rs relocates impl From
Changed components
crypto/src/key.rsInspect captured patch +44 / −44
diff --git a/crypto/src/key.rs b/crypto/src/key.rs
index e51dd2e9..99cd99f5 100644
--- a/crypto/src/key.rs
+++ b/crypto/src/key.rs
@@ -429,6 +429,22 @@ impl From<secp256k1::PublicKey> for XOnlyPublicKey {
}
}
+impl From<LegacyPublicKey> for XOnlyPublicKey {
+ fn from(pk: LegacyPublicKey) -> Self {
+ let (xonly, parity) = pk.to_inner().x_only_public_key();
+ Self::from_secp(xonly, parity)
+ }
+}
+
+impl From<FullPublicKey> for XOnlyPublicKey {
+ fn from(pk: FullPublicKey) -> Self { pk.to_inner().into() }
+}
+
+impl From<TweakedPublicKey> for XOnlyPublicKey {
+ #[inline]
+ fn from(pair: TweakedPublicKey) -> Self { pair.to_x_only_public_key() }
+}
+
impl fmt::LowerHex for XOnlyPublicKey {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::LowerHex::fmt(self.as_inner(), f) }
}
@@ -566,6 +582,16 @@ impl From<&PrivateKey> for Keypair {
fn from(pk: &PrivateKey) -> Self { Self::from_private_key(pk) }
}
+impl From<TweakedKeypair> for Keypair {
+ #[inline]
+ fn from(pair: TweakedKeypair) -> Self { pair.into_keypair() }
+}
+
+impl<'a> From<&'a TweakedKeypair> for &'a Keypair {
+ #[inline]
+ fn from(pair: &'a TweakedKeypair) -> Self { pair.as_keypair() }
+}
+
impl LegacyPublicKey {
/// Constructs a new compressed ECDSA public key from the provided generic secp256k1 public key.
#[deprecated(since = "TBD", note = "use `from_secp` instead")]
@@ -746,11 +772,8 @@ impl From<secp256k1::PublicKey> for LegacyPublicKey {
fn from(pk: secp256k1::PublicKey) -> Self { Self::from_secp(pk) }
}
-impl From<LegacyPublicKey> for XOnlyPublicKey {
- fn from(pk: LegacyPublicKey) -> Self {
- let (xonly, parity) = pk.to_inner().x_only_public_key();
- Self::from_secp(xonly, parity)
- }
+impl From<FullPublicKey> for LegacyPublicKey {
+ fn from(value: FullPublicKey) -> Self { Self::from_secp(value.to_inner()) }
}
/// An opaque return type for [`LegacyPublicKey::to_sort_key`].
@@ -809,6 +832,22 @@ impl From<&LegacyPublicKey> for PubkeyHash {
fn from(key: &LegacyPublicKey) -> Self { key.pubkey_hash() }
}
+impl From<FullPublicKey> for PubkeyHash {
+ fn from(key: FullPublicKey) -> Self { key.pubkey_hash() }
+}
+
+impl From<&FullPublicKey> for PubkeyHash {
+ fn from(key: &FullPublicKey) -> Self { key.pubkey_hash() }
+}
+
+impl From<FullPublicKey> for WPubkeyHash {
+ fn from(key: FullPublicKey) -> Self { key.wpubkey_hash() }
+}
+
+impl From<&FullPublicKey> for WPubkeyHash {
+ fn from(key: &FullPublicKey) -> Self { key.wpubkey_hash() }
+}
+
impl FullPublicKey {
/// Returns bitcoin 160-bit hash of the public key.
pub fn pubkey_hash(&self) -> PubkeyHash { PubkeyHash(hash160::Hash::hash(&self.to_bytes())) }
@@ -908,30 +947,6 @@ impl From<secp256k1::PublicKey> for FullPublicKey {
fn from(pk: secp256k1::PublicKey) -> Self { Self::from_secp(pk) }
}
-impl From<FullPublicKey> for LegacyPublicKey {
- fn from(value: FullPublicKey) -> Self { Self::from_secp(value.to_inner()) }
-}
-
-impl From<FullPublicKey> for XOnlyPublicKey {
- fn from(pk: FullPublicKey) -> Self { pk.to_inner().into() }
-}
-
-impl From<FullPublicKey> for PubkeyHash {
- fn from(key: FullPublicKey) -> Self { key.pubkey_hash() }
-}
-
-impl From<&FullPublicKey> for PubkeyHash {
- fn from(key: &FullPublicKey) -> Self { key.pubkey_hash() }
-}
-
-impl From<FullPublicKey> for WPubkeyHash {
- fn from(key: FullPublicKey) -> Self { key.wpubkey_hash() }
-}
-
-impl From<&FullPublicKey> for WPubkeyHash {
- fn from(key: &FullPublicKey) -> Self { key.wpubkey_hash() }
-}
-
impl PrivateKey {
/// Constructs a new compressed ECDSA private key using the secp256k1 algorithm and
/// a secure random number generator.
@@ -1373,21 +1388,6 @@ impl TweakedKeypair {
}
}
-impl From<TweakedPublicKey> for XOnlyPublicKey {
- #[inline]
- fn from(pair: TweakedPublicKey) -> Self { pair.to_x_only_public_key() }
-}
-
-impl From<TweakedKeypair> for Keypair {
- #[inline]
- fn from(pair: TweakedKeypair) -> Self { pair.into_keypair() }
-}
-
-impl<'a> From<&'a TweakedKeypair> for &'a Keypair {
- #[inline]
- fn from(pair: &'a TweakedKeypair) -> Self { pair.as_keypair() }
-}
-
impl From<TweakedKeypair> for TweakedPublicKey {
#[inline]
fn from(pair: TweakedKeypair) -> Self { Self::from(&pair) }
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.