rust-bitcoin / rust-bitcoin/rust-miniscript

Helpers for constructing standard HD wallet descriptors

Open
#513 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
426
Forks
200
Avg merge
7d 17h
Merged PRs (30d)
8

Description

Constructing standard HD wallet descriptors takes a fair bit of code. For example, to construct a BIP-86 single-key taproot HD wallet descriptor:

let master_xkey = ExtendedPrivKey::new_master(network, &seed)?;

let fingerprint = master_xkey.fingerprint(&secp);

let derivation_path = DerivationPath::master()
  .child(ChildNumber::Hardened { index: 86 })
  .child(ChildNumber::Hardened { index: 0 })
  .child(ChildNumber::Hardened { index: 0 });

let derived_xkey = master_xkey.derive_priv(&secp, &derivation_path)?;

let secret_key = DescriptorSecretKey::XPrv(DescriptorXKey {
  origin: Some((fingerprint, derivation_path.clone())),
  xkey: derived_xkey,
  derivation_path: DerivationPath::master().child(ChildNumber::Normal { index: 0 }),
  wildcard: Wildcard::Unhardened,
});

let public_key = secret_key.to_public(&secp)?;

let mut key_map = std::collections::HashMap::new();
key_map.insert(public_key.clone(), secret_key);

let receive_desc = Descriptor::new_tr(public_key, None)?;

It could be nice to provide helpers that would create standard HD wallet descriptors from seeds, in this case something like:

impl Descriptor {
  fn new_bip_86(secp: &Secp256k1, network: Network, seed: [u8; 32], change: bool) -> Result<(Self, DescriptorSecretKey)> {
    let master_xkey = ExtendedPrivKey::new_master(network, &seed)?;

    let fingerprint = master_xkey.fingerprint(&secp);

    let derivation_path = DerivationPath::master()
      .child(ChildNumber::Hardened { index: 86 })
      .child(ChildNumber::Hardened { index: 0 })
      .child(ChildNumber::Hardened { index: 0 });

    let derived_xkey = master_xkey.derive_priv(&secp, &derivation_path)?;

    let secret_key = DescriptorSecretKey::XPrv(DescriptorXKey {
      origin: Some((fingerprint, derivation_path.clone())),
      xkey: derived_xkey,
      derivation_path: DerivationPath::master().child(ChildNumber::Normal { index: 0 }),
      wildcard: Wildcard::Unhardened,
    });

    let public_key = secret_key.to_public(&secp)?;

    (Descriptor::new_tr(public_key, None), secret_key)
  }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the BIP-86 example in the issue and trace the mentioned Descriptor, ExtendedPrivKey, DerivationPath, and DescriptorSecretKey APIs. Define the scope of the standard HD wallet helpers and verify that the resulting descriptor and secret key match the requested derivation and change behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cryptography
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.