Skip to content

Multipath descriptor support (BIP 389) #275

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 1 commit into
base: master
Choose a base branch
from

Conversation

schjonhaug
Copy link

Description

Key Features:

  • New API: Wallet::create_multipath(descriptor) following the same pattern as create() and create_single()
  • BIP 389 compliance with exactly 2-path validation (receive and change)
  • Robust validation with clear error messages
  • Pattern consistency with existing wallet creation methods

Usage Example:

let multipath_desc = "wpkh([9a6a2580/84'/1'/0']tpub.../‹0;1›/*)";
let wallet = Wallet::create_multipath(multipath_desc)
      .network(Network::Testnet)
      .create_wallet_no_persist()?;

// Automatically creates separate receive and change descriptors
let receive_addr = wallet.peek_address(KeychainKind::External, 0);  // Uses path /0/*
let change_addr = wallet.peek_address(KeychainKind::Internal, 0);   // Uses path /1/*

Notes to the reviewers

Design Decisions:

  1. Pattern Consistency: Uses make_multipath_descriptor_to_extract() helper following the same pattern as existing make_descriptor_to_extract() function
  2. Lazy Evaluation: Descriptor parsing only happens when needed during wallet creation, not during parameter setup - this maintains performance and follows Rust's lazy evaluation patterns
  3. Strict Validation: Only allows exactly 2-path multipath descriptors to ensure proper receive/change separation
  4. API Consistency: The create_multipath() method returns CreateParams just like create() and create_single(), maintaining the fluent builder pattern

Implementation Notes:

  • The function calls make_multipath_descriptor_to_extract() twice (once for receive, once for change) which is intentional and follows the established pattern of lazy evaluation
  • Validation occurs in the descriptor extraction closures, providing clear error messages when descriptors are actually processed
  • All existing functionality remains unchanged - this is a purely additive feature

Changelog notice

Added:

  • Wallet::create_multipath() method for creating wallets from BIP 389 multipath descriptors
  • CreateParams::new_multipath() for multipath descriptor parameter creation
  • Support for 2-path multipath descriptors with automatic receive/change separation
  • Enhanced validation for multipath descriptors with descriptive error messages

Checklists

All Submissions:

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

Bugfixes:

  • This pull request breaks the existing API
  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

Closes #11

@coveralls
Copy link

coveralls commented Jul 3, 2025

Pull Request Test Coverage Report for Build 16072648456

Details

  • 111 of 112 (99.11%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.2%) to 84.947%

Changes Missing Coverage Covered Lines Changed/Added Lines %
wallet/src/descriptor/error.rs 0 1 0.0%
Totals Coverage Status
Change from base Build 16052072493: 0.2%
Covered Lines: 6687
Relevant Lines: 7872

💛 - Coveralls

@ValuedMammal
Copy link
Collaborator

Thanks for working on this @schjonhaug.

@schjonhaug
Copy link
Author

Glad to contribute, @ValuedMammal. Let me know if there’s anything I can improve!

@schjonhaug schjonhaug force-pushed the feature/multipath-descriptor-support branch from 5893601 to 2911658 Compare July 4, 2025 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Support multipath descriptors
3 participants