@@ -4,37 +4,37 @@ use std::{env, process};
4
4
use std:: str:: FromStr ;
5
5
6
6
use bitcoin:: secp256k1:: Secp256k1 ;
7
- use bitcoin:: { PrivateKey , PublicKey } ;
7
+ use bitcoin:: PublicKey ;
8
8
use bitcoin:: util:: bip32:: ExtendedPrivKey ;
9
9
use bitcoin:: util:: bip32:: ExtendedPubKey ;
10
10
use bitcoin:: util:: bip32:: DerivationPath ;
11
11
use bitcoin:: util:: bip32:: ChildNumber ;
12
12
use bitcoin:: util:: address:: Address ;
13
13
use bitcoin:: secp256k1:: ffi:: types:: AlignedType ;
14
+ use bitcoin:: hashes:: hex:: FromHex ;
14
15
15
16
fn main ( ) {
16
- // This example derives root xprv
17
- // from a 32-byte secret of the input WIF string,
17
+ // This example derives root xprv from a 32-byte seed,
18
18
// derives the child xprv with path m/84h/0h/0h,
19
19
// prints out corresponding xpub,
20
20
// calculates and prints out the first receiving segwit address.
21
- // Run this example with cargo and WIF argument:
22
- // cargo run --example bip32 L1HKVVLHXiUhecWnwFYF6L3shkf1E12HUmuZTESvBXUdx3yqVP1D
21
+ // Run this example with cargo and seed(hex-encoded) argument:
22
+ // cargo run --example bip32 7934c09359b234e076b9fa5a1abfd38e3dc2a9939745b7cc3c22a48d831d14bd
23
23
24
24
let args: Vec < String > = env:: args ( ) . collect ( ) ;
25
25
if args. len ( ) < 2 {
26
- eprintln ! ( "not enough arguments. usage: {} <WIF >" , & args[ 0 ] ) ;
26
+ eprintln ! ( "not enough arguments. usage: {} <hex-encoded 32-byte seed >" , & args[ 0 ] ) ;
27
27
process:: exit ( 1 ) ;
28
28
}
29
29
30
- let wif = PrivateKey :: from_wif ( & args[ 1 ] ) . unwrap ( ) ;
31
- println ! ( "Seed WIF : {}" , wif ) ;
30
+ let seed_hex = & args[ 1 ] ;
31
+ println ! ( "Seed: {}" , seed_hex ) ;
32
32
33
- // use the network from WIF key
34
- let network = wif . network ;
33
+ // default network as mainnet
34
+ let network = bitcoin :: Network :: Bitcoin ;
35
35
println ! ( "Network: {:?}" , network) ;
36
- // seed is a 32-byte secret in WIF
37
- let seed = wif . to_bytes ( ) ;
36
+
37
+ let seed = Vec :: from_hex ( seed_hex ) . unwrap ( ) ;
38
38
39
39
// we need secp256k1 context for key derivation
40
40
let mut buf: Vec < AlignedType > = Vec :: new ( ) ;
0 commit comments