Skip to content

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

AmosOO7
Copy link

@AmosOO7 AmosOO7 commented May 2, 2025

Description

This PR introduces a new descriptor subcommand to the BDK CLI that enables users to generate 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 or tprv/tpub).

This resolves issue #175

Note: The --weak option for string-based key generation is intentionally excluded in this PR, pending further instruction.


Features Implemented

  • Adds new descriptor subcommand to the CLI
  • Supports BIP44, BIP49, BIP84, and BIP86 script types
  • Generates internal and external descriptors
  • Supports --multipath for wildcard derivation paths
  • Rejects mismatched key-network pairs (e.g., xprv on testnet)
  • Supports optional custom --path (e.g., m/84h/1h/0h) for non-multipath descriptors
  • Reasonable defaults:
    • --type defaults to 84 and a short t
    • --network default testnet
    • --multipath defaults to false and a short m

Usage Examples

1. Generate a New Key (Mnemonic)

cargo run key generate --entropy 12

2. Generate Descriptors from an Extended Private Key

cargo run -- --network testnet descriptor --type 84 <XPRV>

3. Generate Descriptors from a Mnemonic (no key provided)

cargo run -- --network testnet descriptor --type 86

4. Generate Multipath Descriptors from an Extended Public Key or Private Key

cargo run -- --network testnet descriptor --type 44 --multipath <XPUB/XPRIV>

5. Generate Descriptors from XPRV with a Custom Derivation Path

cargo run -- --network testnet descriptor --type 49 --path "m/84h/1h/2h" <XPRV>
  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature
  • I've updated CHANGELOG.md

@AmosOO7 AmosOO7 marked this pull request as ready for review May 7, 2025 14:17
@AmosOO7 AmosOO7 force-pushed the adding_descriptor_generator branch from 09b4f4a to ebf6be3 Compare May 7, 2025 16:23
@AmosOO7 AmosOO7 requested a review from tvpeter May 19, 2025 16:21
Copy link
Collaborator

@tvpeter tvpeter left a 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.

@AmosOO7 AmosOO7 requested a review from tvpeter May 22, 2025 12:31
@notmandatory notmandatory moved this to In Progress in BDK-CLI May 28, 2025
@notmandatory notmandatory added the enhancement New feature or request label May 28, 2025
@notmandatory notmandatory added this to the CLI 1.1.0 milestone May 28, 2025
Copy link
Collaborator

@tvpeter tvpeter left a 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!

@AmosOO7 AmosOO7 force-pushed the adding_descriptor_generator branch 7 times, most recently from 6bff257 to 31f256a Compare June 12, 2025 11:45
Copy link
Collaborator

@tvpeter tvpeter left a 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.

AmosOO7 added 3 commits June 21, 2025 17:53
This enhancement introduces a new `descriptor` subcommand to `bdk-cli`, allowing 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
@AmosOO7 AmosOO7 force-pushed the adding_descriptor_generator branch from 15495c4 to 6c8e714 Compare June 21, 2025 16:55
- 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
@AmosOO7 AmosOO7 requested a review from tvpeter June 22, 2025 08:33
@coveralls
Copy link

Pull Request Test Coverage Report for Build 15804707728

Details

  • 0 of 299 (0.0%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.6%) to 2.026%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/commands.rs 0 3 0.0%
src/handlers.rs 0 61 0.0%
src/utils.rs 0 235 0.0%
Totals Coverage Status
Change from base Build 15731603419: -0.6%
Covered Lines: 25
Relevant Lines: 1234

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

4 participants