1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//! # bip0032
//!
//! [][actions]
//! [][docs.rs]
//! [][crates.io]
//! [][crates.io]
//! [][crates.io]
//! [][whatrustisit]
//!
//! [actions]: https://github.com/koushiro/rust-bips/actions
//! [docs.rs]: https://docs.rs/bip0032
//! [crates.io]: https://crates.io/crates/bip0032
//! [whatrustisit]: https://www.whatrustisit.com
//!
//! Another Rust implementation of [BIP-0032](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) standard.
//!
//! ## Support curves and features
//!
//! | Curve | Feature | Backends | Hardened | Non-hardened (private) | Non-hardened (public) | Serialization |
//! | --- | --- | --- | --- | --- | --- | --- |
//! | secp256k1 | `k256` \| `secp256k1` | k256, secp256k1 | yes | yes | yes | yes |
//!
//! ## Usage
//!
//! Seed material is typically derived from a BIP-0039 mnemonic (for example, via
//! [bip0039](https://crates.io/crates/bip0039)).
//!
//! ```rust,ignore
//! use bip0039::{Count, English, Mnemonic};
//!
//! let mnemonic = <Mnemonic<English>>::generate(Count::Words12);
//! let seed = mnemonic.to_seed("");
//! ```
//!
//! The examples below assume the `seed` from above.
//!
//! 1. Private parent key -> private child key (supports hardened).
//!
//! ```rust
//! use bip0032::{DerivationPath, ExtendedPrivateKey, Version, curve::secp256k1::*};
//!
//! # let seed = [0u8; 64];
//! let master = ExtendedPrivateKey::<Secp256k1Curve<K256Backend>>::new(&seed).unwrap();
//! let path: DerivationPath = "m/0H/1".parse().unwrap();
//! let child = master.derive_path(&path).unwrap();
//! let xprv = child
//! .encode_with(Version::XPRV)
//! .unwrap()
//! .to_string();
//! ```
//!
//! 2. Private parent key -> public child key.
//!
//! ```rust
//! use bip0032::{DerivationPath, ExtendedPrivateKey, Version, curve::secp256k1::*};
//!
//! # let seed = [0u8; 64];
//! let master = ExtendedPrivateKey::<Secp256k1Curve<K256Backend>>::new(&seed).unwrap();
//! let path: DerivationPath = "m/0H/1".parse().unwrap();
//! let child = master.derive_path(&path).unwrap();
//! let xpub = child
//! .public_key()
//! .encode_with(Version::XPUB)
//! .unwrap()
//! .to_string();
//! ```
//!
//! 3. Public parent key -> public child key (non-hardened only).
//!
//! ```rust
//! use bip0032::{DerivationPath, ExtendedPublicKey, Version, curve::secp256k1::*};
//!
//! let parent_xpub = "xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8";
//! let parent: ExtendedPublicKey<Secp256k1Curve<K256Backend>> = parent_xpub.parse().unwrap();
//! let path: DerivationPath = "m/0/1".parse().unwrap();
//! let child = parent.derive_path(&path).unwrap();
//! let xpub = child
//! .encode_with(Version::XPUB)
//! .unwrap()
//! .to_string();
//! ```
//!
//! 4. Public parent key -> private child key: impossible (BIP-0032 does not allow it).
//!
//! # SLIP-0010 (optional)
//!
//! SLIP-0010 support is available behind the `slip10` feature. It shares the same
//! `ExtendedPrivateKey`/`ExtendedPublicKey` types but uses SLIP-0010 derivation
//! rules.
extern crate alloc;
pub use slip10;
pub use ;