-
Notifications
You must be signed in to change notification settings - Fork 79
Adding descriptor generator #180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
09b4f4a
to
ebf6be3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work Amos.
Most of the fns in utils
should be in the handlers
file, while most of those in handlers
should be placed in the utils
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your work on this, @AmosOO7.
If possible, please revert the imports you removed, as this will help in tracking your imports. Also, kindly remove any unnecessary comments and squash your commits into logical groupings. I have also left comments on other specific areas for your review.
Thank you!
6bff257
to
31f256a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for continuing to work on this.
I have left a couple of comments.
15495c4
to
6c8e714
Compare
Pull Request Test Coverage Report for Build 17490529141Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @AmosOO7 for continuing to work on this.
The checks for path
and how a user can use it is a little bit confusing. I think we might need to split it into subcommands, similar to how key
has generate
, derive
and restore
. If you have any suggestions for the best subcategories, please feel free to share them in the conversation before continuing with the implementation. Otherwise, I will propose the subcategories this coming week to make it clearer. I've also left some additional comments for you.
Additionally, it would be a good idea to include documentation comments for each command option and parameter to help users better understand their functionalities.
Thank you.
After having a discussion with @tvpeter and following his suggestions. Breaking the Suggested Subcommands for
|
Subcommand | Description |
---|---|
from-key | Generate descriptors from a provided Xprv or Xpub |
from-mnemonic | Generate descriptors from a newly generated or provided BIP39 mnemonic |
multipath | Generate multipath (wildcard derivation) descriptors from a key |
info (optional/future) | Inspect a descriptor and show parsed structure (e.g., key origin, type, script) |
Detailed Breakdown
1. descriptor from-key
-
Input:
--type
,<XPRV | XPUB>
-
Optional:
--path m/84h/1h/0h
(for custom derivation base) -
Output: external/internal descriptor strings
-
Optionally support both single and multipath modes via
--multipath
2. descriptor from-mnemonic
-
Input:
--type
, -
Optional:
--mnemonic <WORDS>
(if not, generate randomly) -
Output: same as
from-key
, plus return mnemonic used
3. descriptor multipath
-
Input:
--type
,<XPRV | XPUB>
-
Output: wildcard descriptors (e.g.,
/0/*
and/1/*
)
4. (Optional) descriptor info
-
Input: descriptor string
-
Output: parsed structure, origin, derivation, checksum, script type, etc.
Example CLI Usage
From key
bdk-cli descriptor from-key --type 84 <XPRV | <XPUB>;
From mnemonic
bdk-cli descriptor from-mnemonic --type 86 (optional)<WORDS>
From key with multipath
bdk-cli descriptor multipath --type 44 <XPUB | <XPUB>;
Descriptor info (optional)
bdk-cli descriptor info "wpkh([abcd1234/84'/1'/0']xpub.../0/*)"
What do you think about the suggestions @tvpeter and @notmandatory ?
I think the following is more descriptive:
note:
Also, wait for confirmation from Notmandatory. |
@tvpeter I agree that having two Having the |
@AmosOO7, you should be able to update according to this. Thank you |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @AmosOO7,
Thanks for continuing to push this PR. I have left comments, when you address them, I will continue with testing.
Thank you
src/error.rs
Outdated
#[error("Invalid arguments: {0}")] | ||
InvalidArguments(String), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AmosOO7, can you please make time to update this PR? I was hoping it could make it into the next release. It would be great if you could push it forward. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your efforts on this PR @AmosOO7
I have left comments but don't worry, I will push changes so that it is easier for us to close the PR.
Thank you.
src/utils.rs
Outdated
let descriptor_type = match script_type { | ||
44 => Bip44, | ||
49 => Bip49, | ||
84 => Bip84, | ||
86 => Bip86, | ||
_ => return Err(Error::UnsupportedScriptType(script_type)), | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These were already validated in handle_descriptor_subcommand
fn in handlers.rs
src/utils.rs
Outdated
|
||
let desc_secret = DescriptorSecretKey::XPrv(desc_xprv.clone()); | ||
let (desc_key, keymap, _) = match descriptor_type { | ||
DescriptorType::Bip84 | DescriptorType::Bip49 | DescriptorType::Bip44 => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BIP44
is legacy and not Segwitv0
src/handlers.rs
Outdated
let descriptor_type = match script_type { | ||
44 => DescriptorType::Bip44, | ||
49 => DescriptorType::Bip49, | ||
84 => DescriptorType::Bip84, | ||
86 => DescriptorType::Bip86, | ||
_ => return Err(Error::UnsupportedScriptType(script_type)), | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant validation as this was already handled by the handle_descriptor_subcommand
fn
src/handlers.rs
Outdated
pub fn generate_standard_descriptor( | ||
network: &Network, | ||
script_type: u8, | ||
key: &str, | ||
) -> Result<Value, Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need for this fn as generate_descriptor_from_key_by_type
fn can be called directly in handle_descriptor_subcommand
passing the network, key, descriptor_type
(descriptor_type having already been validated)
src/utils.rs
Outdated
DescriptorType::Bip49 => format!( | ||
"{}([{}{}]{}{}))", | ||
external_fmt, origin, derivation_base, xprv_str, "/0" | ||
), | ||
_ => format!( | ||
"{}([{}{}]{}{})", | ||
external_fmt, origin, derivation_base, xprv_str, "/0" | ||
), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These descriptors will not have wildcard.
src/utils.rs
Outdated
pub fn generate_descriptor_from_key_by_type( | ||
network: &Network, | ||
key: &str, | ||
descriptor_type: DescriptorType, | ||
) -> Result<serde_json::Value, Error> { | ||
let derivation_path = match descriptor_type { | ||
DescriptorType::Bip44 => "m/44h/1h/0h", | ||
DescriptorType::Bip49 => "m/49h/1h/0h", | ||
DescriptorType::Bip84 => "m/84h/1h/0h", | ||
DescriptorType::Bip86 => "m/86h/1h/0h", | ||
}; | ||
|
||
generate_bip_descriptor_from_key(network, key, derivation_path, descriptor_type) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this fn is redundant
This allow users to generate wallet descriptors from either extended private keys (xprv), or fresh BIP39 mnemonics. It supports standard script types (BIP44, BIP49, BIP84, BIP86) and outputs both public and private descriptors for external and internal branches. The design improves developer and user experience by enabling easier wallet creation and script descriptor introspection. Closes bitcoindevkit#175
- Ensure you can generate different type of descriptor with mnemonic - Changed the Json output format - Added path subcommand for generating descriptors from keys - Set multipath to accept different types for descriptors - Set multipath default value to false and gave it a short of m - Set type default to 84 and gave it a short to t
- Created Subcommnds for the descriptor command; generate and info - Created function to get descriptors from mnemonics - Ensured consistent fingerprint when generating descriptors from both mnemonic and key - Removed the previously inserted path variable
and commands, and also deleted redundant errors that were created. - Updated the comment on the descriptor command, also added comments to the inputs for the subcommands. - Added possiblevalues for the descriptor types in the subcommand - Made the descriptor type format consistent - Fixed duplicated on invalidArguments call
- Updated the comment on the descriptor command, a> - Added possiblevalues for the descriptor types in> - Made the descriptor type format consistent - Fixed duplicated on invalidArguments call
37ce428
to
3ba1dc0
Compare
Pull Request: Add
descriptor
Subcommand (Generate & Info)Description
This PR introduces a new
descriptor
subcommand to the BDK CLI that enables users to generate and inspect Bitcoin wallet descriptors for internal and external paths, supporting common BIP standards (44, 49, 84, 86). It includes support for both single-path and multipath descriptors from extended keys (xprv
/xpub
ortprv
/tpub
).This resolves issue #175
Features Implemented
descriptor
subcommand with:generate
– generate new descriptorsinfo
– inspect and display descriptor metadata--multipath
for wildcard derivation paths--type
defaults to84
and a shortt
--network
defaulttestnet
--multipath
defaults tofalse
and a shortm
Usage Examples
1. Generate Descriptors from an Extended Private Key
2. Generate Descriptors from a Mnemonic (no key provided)
3. Generate Multipath Descriptors from an Extended Public Key or Private Key
4. Show Info about an Existing Descriptor
cargo run -- --network testnet descriptor info "wpkh([fingerprint/84h/1h/0h]xpub/0/*)"
cargo fmt
andcargo clippy
before committingNew Features:
CHANGELOG.md