What changed, and why it matters
This commit adds a new convenience method called force_compressed to the PublicKey type in the rust-bitcoin library. It lets callers convert a public key into a compressed public key without handling a possible failure case. The change is purely additive (8 new lines, no deletions) and does not alter existing behavior or fix any bug. There is no indication of a security issue in the commit or supplied references.
No security action required. Treat as a normal API addition. Reviewers may want to confirm the documentation adequately warns callers that compressedness information is discarded, but this is a design/usability consideration rather than a vulnerability.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch adds PublicKey::force_compressed(self) -> CompressedPublicKey in bitcoin/src/crypto/key.rs. It delegates to CompressedPublicKey::from_secp(self.to_inner()), discarding the original compressedness flag. The existing fallible TryFrom path remains unchanged. No existing code is modified, no unsafe code is introduced, and no cryptographic operations are changed.
Changed components
bitcoin/src/crypto/key.rsPublicKeyCompressedPublicKeyInspect captured patch +8 / −0
diff --git a/bitcoin/src/crypto/key.rs b/bitcoin/src/crypto/key.rs
index 285bb3de..a70a63ea 100644
--- a/bitcoin/src/crypto/key.rs
+++ b/bitcoin/src/crypto/key.rs
@@ -528,6 +528,14 @@ impl PublicKey {
Ok(key.p2wpkh_script_code())
}
+ /// Converts this [`PublicKey`] into a [`CompressedPublicKey`] infallibly.
+ ///
+ /// Unlike the `TryFrom` implementation, this function will discard compressedness
+ /// information on the [`PublicKey`].
+ pub fn force_compressed(self) -> CompressedPublicKey {
+ CompressedPublicKey::from_secp(self.to_inner())
+ }
+
/// Writes the public key into a writer.
///
/// # Errors
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.