Skip to content

Commit ec47198

Browse files
committed
Remove ONE_KEY
The `ONE_KEY` is only used in two rustdoc examples, as such it unnecessarily pollutes the crate root namespace. We can use `SecretKey::from_str()` with no loss of clarity and remove the `ONE_KEY`. While we are touching the import statements in `secret.rs` elect to remove the hide (use of `#`) for import statements relating to this library. Doing so gives devs all the information they need in one place if they are using the examples to copy code. It is also in line with the rest of the codebase.
1 parent d546c16 commit ec47198

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/key.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ impl str::FromStr for SecretKey {
7474
}
7575
}
7676

77-
/// The number 1 encoded as a secret key.
78-
pub const ONE_KEY: SecretKey = SecretKey(constants::ONE);
79-
8077
/// A Secp256k1 public key, used for verification of signatures.
8178
///
8279
/// # Serde support

src/secret.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ impl SecretKey {
118118
///
119119
/// ```
120120
/// # #[cfg(feature = "std")] {
121-
/// let key = secp256k1::ONE_KEY;
121+
/// # use std::str::FromStr;
122+
/// use secp256k1::SecretKey;
123+
/// let key = SecretKey::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap();
122124
///
123125
/// // Normal debug hides value (`Display` is not implemented for `SecretKey`).
124126
/// // E.g., `format!("{:?}", key)` prints "SecretKey(#2518682f7819fb2d)".
@@ -152,12 +154,11 @@ impl KeyPair {
152154
///
153155
/// ```
154156
/// # #[cfg(feature = "std")] {
155-
/// use secp256k1::ONE_KEY;
156-
/// use secp256k1::KeyPair;
157-
/// use secp256k1::Secp256k1;
157+
/// # use std::str::FromStr;
158+
/// use secp256k1::{KeyPair, Secp256k1, SecretKey};
158159
///
159160
/// let secp = Secp256k1::new();
160-
/// let key = ONE_KEY;
161+
/// let key = SecretKey::from_str("0000000000000000000000000000000000000000000000000000000000000001").unwrap();
161162
/// let key = KeyPair::from_secret_key(&secp, &key);
162163
/// // Here we explicitly display the secret value:
163164
/// assert_eq!(
@@ -190,7 +191,7 @@ impl SharedSecret {
190191
/// # #[cfg(not(fuzzing))]
191192
/// # #[cfg(feature = "std")] {
192193
/// # use std::str::FromStr;
193-
/// # use secp256k1::{SecretKey, PublicKey};
194+
/// use secp256k1::{SecretKey, PublicKey};
194195
/// use secp256k1::ecdh::SharedSecret;
195196
///
196197
/// # let pk = PublicKey::from_slice(&[3, 23, 183, 225, 206, 31, 159, 148, 195, 42, 67, 115, 146, 41, 248, 140, 11, 3, 51, 41, 111, 180, 110, 143, 114, 134, 88, 73, 198, 174, 52, 184, 78]).expect("hard coded slice should parse correctly");

0 commit comments

Comments
 (0)