What changed, and why it matters
This commit adds a new helper method, to_secret_bytes, to the PrivateKey type in the rust-bitcoin library. It returns a private key as a fixed 32-byte array instead of a variable-length vector. The existing to_secret_vec method is rewritten to use the new helper. There is no visible security fix or behavior change; it is a routine API convenience addition.
No security action needed. Treat as a normal API enhancement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change introduces PrivateKey::to_secret_bytes() returning [u8; 32] by delegating to the inner key’s to_secret_bytes(). The existing to_secret_vec() is refactored to call to_secret_bytes().to_vec(). The diff is +4/-1 lines and only affects bitcoin/src/crypto/key.rs. No memory-safety, cryptographic, or authorization behavior is altered.
Changed components
bitcoin/src/crypto/key.rsPrivateKey serialization APIInspect captured patch +4 / −1
diff --git a/bitcoin/src/crypto/key.rs b/bitcoin/src/crypto/key.rs
index 05df49a7..49056f01 100644
--- a/bitcoin/src/crypto/key.rs
+++ b/bitcoin/src/crypto/key.rs
@@ -924,7 +924,10 @@ impl PrivateKey {
pub fn to_bytes(self) -> Vec<u8> { self.to_secret_vec() }
/// Serializes the private key to bytes.
- pub fn to_secret_vec(self) -> Vec<u8> { self.as_inner()[..].to_vec() }
+ pub fn to_secret_vec(self) -> Vec<u8> { self.to_secret_bytes().to_vec() }
+
+ /// Serializes the private key to bytes.
+ pub fn to_secret_bytes(self) -> [u8; 32] { self.as_inner().to_secret_bytes() }
/// Deserializes a private key from a byte array.
///
Why this scored 16/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.