Skip to content

Commit 0ecd2a2

Browse files
committed
Merge #779: doc: Keypair constructors
aaf5fee fix: Invalid secret key (Christian Lewe) d1d4ff9 doc: Keypair constructors accept odd keys (Christian Lewe) Pull request description: Clarify the conditions when `Keypair` construction fails and correct the error variant that is returned in one of the constructors. Fixes #758 ACKs for top commit: Kixunil: ACK aaf5fee apoelstra: ACK aaf5fee; successfully ran local tests Tree-SHA512: 9b27c4ee1424619f9041183801e7c1214838f0b8d529e9c10a3e1f55264624b6b42b881e369bd9521bfa117d3dd5ce072caed4b8ee51c40e1016fc5be59a2894
2 parents e66bd11 + aaf5fee commit 0ecd2a2

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/key.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -858,8 +858,8 @@ impl Keypair {
858858
///
859859
/// # Errors
860860
///
861-
/// [`Error::InvalidSecretKey`] if the provided data has an incorrect length, exceeds Secp256k1
862-
/// field `p` value or the corresponding public key is not even.
861+
/// [`Error::InvalidSecretKey`] if the slice is not exactly 32 bytes long,
862+
/// or if the encoded number exceeds the Secp256k1 field `p` value.
863863
#[inline]
864864
pub fn from_seckey_slice<C: Signing>(
865865
secp: &Secp256k1<C>,
@@ -883,22 +883,24 @@ impl Keypair {
883883
///
884884
/// # Errors
885885
///
886-
/// [`Error::InvalidSecretKey`] if corresponding public key for the provided secret key is not even.
886+
/// [`Error::InvalidSecretKey`] if the string does not consist of exactly 64 hex characters,
887+
/// or if the encoded number exceeds the Secp256k1 field `p` value.
887888
#[inline]
888889
pub fn from_seckey_str<C: Signing>(secp: &Secp256k1<C>, s: &str) -> Result<Keypair, Error> {
889890
let mut res = [0u8; constants::SECRET_KEY_SIZE];
890891
match from_hex(s, &mut res) {
891892
Ok(constants::SECRET_KEY_SIZE) =>
892893
Keypair::from_seckey_slice(secp, &res[0..constants::SECRET_KEY_SIZE]),
893-
_ => Err(Error::InvalidPublicKey),
894+
_ => Err(Error::InvalidSecretKey),
894895
}
895896
}
896897

897898
/// Creates a [`Keypair`] directly from a secret key string and the global [`SECP256K1`] context.
898899
///
899900
/// # Errors
900901
///
901-
/// [`Error::InvalidSecretKey`] if corresponding public key for the provided secret key is not even.
902+
/// [`Error::InvalidSecretKey`] if the string does not consist of exactly 64 hex characters,
903+
/// or if the encoded number exceeds the Secp256k1 field `p` value.
902904
#[inline]
903905
#[cfg(feature = "global-context")]
904906
pub fn from_seckey_str_global(s: &str) -> Result<Keypair, Error> {

0 commit comments

Comments
 (0)