Skip to content

Commit ebf6be3

Browse files
committed
Added the descriptor generator function
1 parent 2fa18a0 commit ebf6be3

File tree

6 files changed

+436
-5
lines changed

6 files changed

+436
-5
lines changed

Cargo.lock

Lines changed: 13 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ log = "0.4"
2020
serde_json = "1.0"
2121
thiserror = "2.0.11"
2222
tokio = { version = "1", features = ["full"] }
23+
anyhow = "1.0"
24+
serde = { version = "1.0", features = ["derive"] }
25+
miniscript = "12.3.2"
2326

2427
# Optional dependencies
2528
bdk_bitcoind_rpc = { version = "0.18.0", optional = true }

src/commands.rs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
//! All subcommands are defined in the below enums.
1414
1515
#![allow(clippy::large_enum_variant)]
16-
1716
use bdk_wallet::bitcoin::{
1817
bip32::{DerivationPath, Xpriv},
1918
Address, Network, OutPoint, ScriptBuf,
@@ -109,8 +108,48 @@ pub enum CliSubCommand {
109108
#[command(flatten)]
110109
wallet_opts: WalletOpts,
111110
},
111+
/// Generate a random Bitcoin descriptor and mnemonic.
112+
///
113+
/// This function generates a new 12-word BIP39 mnemonic phrase and uses it to derive a BIP32
114+
/// extended private key (XPRV). It constructs two BIP86-compatible single-sig descriptors:
115+
/// - An **external descriptor** used for receiving funds (`/0/*`)
116+
/// - An **internal descriptor** used for change outputs (`/1/*`)
117+
///
118+
/// These descriptors follow the standard derivation path `m/86h/0h/0h` for mainnet (or `86h/1h/0h`
119+
/// for testnet), and use `wpkh` (native SegWit) script format.
120+
///
121+
/// The output includes both the public and private forms of the descriptors, along with the mnemonic.
122+
///
123+
/// > ⚠️ This feature is **EXPERIMENTAL** and is intended for testing or development. Do **not** use
124+
/// > this output to secure real Bitcoin funds on mainnet.
125+
///
126+
/// Returns a JSON object containing:
127+
/// - `mnemonic`: the 12-word phrase
128+
/// - `external_descriptor`: public and private forms for receive addresses
129+
/// - `internal_descriptor`: public and private forms for change addresses.
130+
Descriptor(GenerateDescriptorArgs),
112131
}
132+
#[derive(Debug, Clone, PartialEq, Args)]
133+
pub struct GenerateDescriptorArgs {
134+
#[clap(long)]
135+
pub network: Network,
136+
137+
#[clap(long, value_parser = clap::value_parser!(u8).range(44..=86))]
138+
pub r#type: u8, // 44, 49, 84, 86
139+
140+
#[clap(long)]
141+
pub multipath: bool,
113142

143+
pub key: Option<String>, // Positional argument (tprv/tpub/xprv/xpub)
144+
}
145+
146+
#[derive(Debug, Clone, PartialEq, ValueEnum)]
147+
pub enum ScriptType {
148+
Bip44,
149+
Bip49,
150+
Bip84,
151+
Bip86,
152+
}
114153
/// Wallet operation subcommands.
115154
#[derive(Debug, Subcommand, Clone, PartialEq)]
116155
pub enum WalletSubCommand {

0 commit comments

Comments
 (0)