What changed, and why it matters
This commit is a pure code cleanup: it reorders where certain trait implementations (like FromStr, From, Display, Debug) appear in the source file so all types follow the same consistent pattern. No code behavior is changed, no security bug is fixed, and no vulnerability is introduced.
No action required; this is a non-functional style/refactoring change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff in crypto/src/key.rs only moves existing impl blocks and one struct definition (SortKey) around to enforce a uniform ordering: impl -> FromStr -> TryFrom -> From -> LowerHex -> Display -> Debug. All function bodies, signatures, attributes, and deprecation notes remain identical. There are no semantic changes.
Changed components
crypto/src/key.rsInspect captured patch +45 / −45
diff --git a/crypto/src/key.rs b/crypto/src/key.rs
index 673f3703..196503c8 100644
--- a/crypto/src/key.rs
+++ b/crypto/src/key.rs
@@ -783,25 +783,6 @@ impl LegacyPublicKey {
}
}
-impl From<secp256k1::PublicKey> for LegacyPublicKey {
- #[inline]
- fn from(pk: secp256k1::PublicKey) -> Self { Self::from_secp(pk) }
-}
-
-impl From<FullPublicKey> for LegacyPublicKey {
- #[inline]
- fn from(value: FullPublicKey) -> Self { Self::from_secp(value.to_inner()) }
-}
-
-/// An opaque return type for [`LegacyPublicKey::to_sort_key`].
-#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
-pub struct SortKey(ArrayVec<u8, 65>);
-
-impl fmt::Display for LegacyPublicKey {
- #[inline]
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.to_bytes().as_hex().fmt(f) }
-}
-
impl FromStr for LegacyPublicKey {
type Err = ParsePublicKeyError;
#[inline]
@@ -830,6 +811,25 @@ impl FromStr for LegacyPublicKey {
}
}
+impl From<secp256k1::PublicKey> for LegacyPublicKey {
+ #[inline]
+ fn from(pk: secp256k1::PublicKey) -> Self { Self::from_secp(pk) }
+}
+
+impl From<FullPublicKey> for LegacyPublicKey {
+ #[inline]
+ fn from(value: FullPublicKey) -> Self { Self::from_secp(value.to_inner()) }
+}
+
+impl fmt::Display for LegacyPublicKey {
+ #[inline]
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.to_bytes().as_hex().fmt(f) }
+}
+
+/// An opaque return type for [`LegacyPublicKey::to_sort_key`].
+#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
+pub struct SortKey(ArrayVec<u8, 65>);
+
hashes::hash_newtype! {
/// A hash of a public key.
pub struct PubkeyHash(hash160::Hash);
@@ -941,18 +941,6 @@ impl FullPublicKey {
}
}
-impl fmt::Display for FullPublicKey {
- #[inline]
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.to_bytes().as_hex().fmt(f) }
-}
-
-impl fmt::Debug for FullPublicKey {
- #[inline]
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- f.write_fmt(format_args!("FullPublicKey({})", self))
- }
-}
-
impl FromStr for FullPublicKey {
type Err = ParseFullPublicKeyError;
@@ -981,6 +969,18 @@ impl From<secp256k1::PublicKey> for FullPublicKey {
fn from(pk: secp256k1::PublicKey) -> Self { Self::from_secp(pk) }
}
+impl fmt::Display for FullPublicKey {
+ #[inline]
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.to_bytes().as_hex().fmt(f) }
+}
+
+impl fmt::Debug for FullPublicKey {
+ #[inline]
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ f.write_fmt(format_args!("FullPublicKey({})", self))
+ }
+}
+
impl PrivateKey {
/// Constructs a new compressed ECDSA private key using the secp256k1 algorithm and
/// a secure random number generator.
@@ -1431,6 +1431,20 @@ impl<'de> serde::Deserialize<'de> for FullPublicKey {
/// Untweaked BIP-0340 X-coord-only public key.
pub type UntweakedPublicKey = XOnlyPublicKey;
+impl TweakedPublicKey {
+ /// Returns the underlying public key.
+ #[inline]
+ #[doc(hidden)]
+ #[deprecated(since = "0.32.6", note = "use to_x_only_public_key() instead")]
+ pub fn to_inner(self) -> XOnlyPublicKey { self.to_x_only_public_key() }
+
+ /// Serializes the key as a byte-encoded x coordinate value (32 bytes).
+ #[inline]
+ pub fn serialize(&self) -> [u8; constants::SCHNORR_PUBLIC_KEY_SIZE] {
+ self.as_x_only_public_key().serialize().0
+ }
+}
+
impl fmt::LowerHex for TweakedPublicKey {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.as_x_only_public_key().fmt(f) }
@@ -1447,20 +1461,6 @@ impl fmt::Display for TweakedPublicKey {
/// Untweaked BIP-0340 key pair.
pub type UntweakedKeypair = Keypair;
-impl TweakedPublicKey {
- /// Returns the underlying public key.
- #[inline]
- #[doc(hidden)]
- #[deprecated(since = "0.32.6", note = "use to_x_only_public_key() instead")]
- pub fn to_inner(self) -> XOnlyPublicKey { self.to_x_only_public_key() }
-
- /// Serializes the key as a byte-encoded x coordinate value (32 bytes).
- #[inline]
- pub fn serialize(&self) -> [u8; constants::SCHNORR_PUBLIC_KEY_SIZE] {
- self.as_x_only_public_key().serialize().0
- }
-}
-
impl TweakedKeypair {
/// Returns the underlying key pair.
#[inline]
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.