Add _secret_ to functions that take and return secret bytes
What changed, and why it matters
This commit is a routine API rename with no security bug. It renames functions in the Rust Bitcoin library that handle private key bytes so their names include the word 'secret' (for example, 'to_vec' becomes 'to_secret_vec' and 'from_byte_array' becomes 'from_secret_bytes'). The goal is to make it more obvious to developers when they are working with sensitive secret material. The actual behavior of the code is unchanged.
No security action needed. Developers using the library should update call sites from the old names to the new names when upgrading, as the old names are deprecated.
Security signals we found
No security vulnerability present
Pure API rename for clarity
No changes to cryptographic logic, validation, or memory safety
Deprecation notes updated to point to new names
Evidence from the diff
The diff modifies bitcoin/src/crypto/key.rs to rename PrivateKey/Keypair methods that take or return secret bytes. to_vec() is renamed to to_secret_vec(), from_byte_array() to from_secret_bytes(), and internal call sites and deprecation notes are updated accordingly. No cryptographic logic, validation, memory handling, or access control changes. This is a pure naming/API clarity refactor.
Changed components
bitcoin/src/crypto/key.rsPrivateKey::to_secret_vec (formerly to_vec)PrivateKey::from_secret_bytes (formerly from_byte_array)PrivateKey::from_slice deprecation noteInspect captured patch +9 / −9
diff --git a/bitcoin/src/crypto/key.rs b/bitcoin/src/crypto/key.rs
index 6924741f..f887beb2 100644
--- a/bitcoin/src/crypto/key.rs
+++ b/bitcoin/src/crypto/key.rs
@@ -908,11 +908,11 @@ impl PrivateKey {
}
/// Serializes the private key to bytes.
- #[deprecated(since = "TBD", note = "use to_vec instead")]
- pub fn to_bytes(self) -> Vec<u8> { self.to_vec() }
+ #[deprecated(since = "TBD", note = "use to_secret_vec instead")]
+ pub fn to_bytes(self) -> Vec<u8> { self.to_secret_vec() }
/// Serializes the private key to bytes.
- pub fn to_vec(self) -> Vec<u8> { self.as_inner()[..].to_vec() }
+ pub fn to_secret_vec(self) -> Vec<u8> { self.as_inner()[..].to_vec() }
/// Deserializes a private key from a byte array.
///
@@ -920,7 +920,7 @@ impl PrivateKey {
///
/// Errors when the secret key is invalid: when it is all-zeros or would exceed
/// the curve order when interpreted as a big-endian unsigned integer.
- pub fn from_byte_array(
+ pub fn from_secret_bytes(
data: [u8; 32],
network: impl Into<NetworkKind>,
) -> Result<Self, secp256k1::Error> {
@@ -932,16 +932,16 @@ impl PrivateKey {
/// # Errors
///
/// [`secp256k1::Error::InvalidSecretKey`] if the slice is not 32 bytes long.
- /// See [`from_byte_array`] for other errors.
+ /// See [`from_secret_bytes`] for other errors.
///
- /// [`from_byte_array`]: PrivateKey::from_byte_array
- #[deprecated(since = "TBD", note = "use from_byte_array instead")]
+ /// [`from_secret_bytes`]: PrivateKey::from_secret_bytes
+ #[deprecated(since = "TBD", note = "use from_secret_bytes instead")]
pub fn from_slice(
data: &[u8],
network: impl Into<NetworkKind>,
) -> Result<Self, secp256k1::Error> {
let array = data.try_into().map_err(|_| secp256k1::Error::InvalidSecretKey)?;
- Self::from_byte_array(array, network)
+ Self::from_secret_bytes(array, network)
}
/// Formats the private key to WIF format.
@@ -2154,7 +2154,7 @@ mod tests {
"1ede31b0e7e47c2afc65ffd158b1b1b9d3b752bba8fd117dc8b9e944a390e8d9",
)
.unwrap();
- let sk = PrivateKey::from_byte_array(bytes, NetworkKind::Test).unwrap();
+ let sk = PrivateKey::from_secret_bytes(bytes, NetworkKind::Test).unwrap();
Keypair::from_secret_key(sk.as_inner())
};
Why this scored 20/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.