examples: Use NetworkKind in call to PrivateKey::from_sec
What changed, and why it matters
This is a tiny documentation-style change to an example file. It swaps one way of saying 'use the Bitcoin main network' for another equivalent way, with no effect on actual code behavior or security.
No security action needed. Treat as a normal example/documentation improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit modifies bitcoin/examples/create-p2wpkh-address.rs to call PrivateKey::from_secp with NetworkKind::Main instead of Network::Bitcoin. The commit message states the change is purely to guide users toward the NetworkKind API and reflects the author’s personal confusion. The two values are semantically equivalent for this purpose, and no logic, validation, or cryptographic handling changes.
Changed components
bitcoin/examples/create-p2wpkh-address.rsInspect captured patch +3 / −2
diff --git a/bitcoin/examples/create-p2wpkh-address.rs b/bitcoin/examples/create-p2wpkh-address.rs
index 94a42180..80a1b654 100644
--- a/bitcoin/examples/create-p2wpkh-address.rs
+++ b/bitcoin/examples/create-p2wpkh-address.rs
@@ -1,5 +1,5 @@
use bitcoin::secp256k1::rand;
-use bitcoin::{Address, CompressedPublicKey, Network, PrivateKey};
+use bitcoin::{Address, CompressedPublicKey, Network, NetworkKind, PrivateKey};
/// Generate a P2WPKH (pay-to-witness-public-key-hash) address and print it
/// along with the associated private key needed to transact.
@@ -8,7 +8,8 @@ fn main() {
let (secret_key, public_key) = secp256k1::generate_keypair(&mut rand::rng());
// Create a Bitcoin private key to be used on the Bitcoin mainnet.
- let private_key = PrivateKey::from_secp(secret_key, Network::Bitcoin);
+ // Equivalent to `PrivateKey::from_secp(secret_key, Network::Bitcoin)`.
+ let private_key = PrivateKey::from_secp(secret_key, NetworkKind::Main);
// Create a compressed Bitcoin public key from the secp256k1 public key.
let public_key = CompressedPublicKey::from_secp(public_key);
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.