Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,16 @@ pub fn get_test_wpkh_and_change_desc() -> (&'static str, &'static str) {
"wpkh(tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7h6Eziw3SpThFfczTDh5rW2krkqffa11UpX3XkeTTB2FvzZKWXqPY54Y6Rq4AQ5R8L/84'/1'/0'/1/*)")
}

/// `wpkh` two-path descriptor
/// `wpkh` public two-path descriptor
pub fn get_test_two_path_wpkh() -> &'static str {
"wpkh(tpubDDks68wKK1xKaVVVbNmXUAx68K1K817M6KwjvjEyCrjdU7xMvjKnfYAtZjfZcrfPfGFzqmibuVqMzKJGbBnK7mo7WSJri8Y9QgM7aNQ3fCp/<0;1>/*)"
}

/// `wpkh` private two-path descriptor
pub fn get_test_two_path_private_wpkh() -> &'static str {
"tr(tprv8ZgxMBicQKsPdfqH2fGKQkBAMXpqCpC6v6WhYnEZC7TbpcEavC1N27tHbFP16eLm9XdFDW6cqnGChit8gWXyyT1zQ3xFqUWgHTS9XBQw3j5/<0;1>/*)"
}

/// `wsh` descriptor with policy `and(pk(A),older(6))`
pub fn get_test_single_sig_csv() -> &'static str {
"wsh(and_v(v:pk(cVpPVruEDdmutPzisEsYvtST1usBR3ntr8pXSyt6D2YYqXRyPcFW),older(6)))"
Expand Down
10 changes: 5 additions & 5 deletions src/wallet/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,12 @@ impl LoadParams {
}

/// Checks that the provided two-path descriptor matches exactly what is loaded for both the
/// external and internal keychains.
/// external and internal keychains. Note that you can only use this method with public extended
/// keys (`xpub` prefix) to create watch-only wallets.
///
/// # Note
///
/// You must also specify [`extract_keys`](Self::extract_keys) if you wish to add a signer
/// for an expected descriptor containing secrets.
/// # Errors
/// Returns an error if the descriptor is invalid, not a 2-path multipath descriptor, or if
/// the descriptor provided contains an extended private key (`xprv` prefix).
pub fn two_path_descriptor<D>(mut self, expected_descriptor: D) -> Self
where
D: IntoWalletDescriptor + Send + Clone + 'static,
Expand Down
20 changes: 19 additions & 1 deletion tests/persisted_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use bdk_chain::{
keychain_txout::DEFAULT_LOOKAHEAD, ChainPosition, ConfirmationBlockTime, DescriptorExt,
};
use bdk_wallet::coin_selection::InsufficientFunds;
use bdk_wallet::descriptor::IntoWalletDescriptor;
use bdk_wallet::descriptor::{DescriptorError, IntoWalletDescriptor};
use bdk_wallet::error::CreateTxError;
use bdk_wallet::test_utils::*;
use bdk_wallet::{
Expand Down Expand Up @@ -450,6 +450,24 @@ fn two_path_descriptor_wallet_persist_and_recover() {
.unwrap()
.expect("wallet must exist");
assert_eq!(loaded.derivation_index(KeychainKind::External), Some(2));

// A private multipath descriptor can't be converted to a public key, so loading fails.
// You get a Miniscript(Unexpected("Can't make an extended private key with multiple paths into
// a public key.")) error.
let private_two_path_descriptor = get_test_two_path_private_wpkh();
let err = Wallet::load()
.two_path_descriptor(private_two_path_descriptor)
.check_network(Network::Testnet4)
.load_wallet(&mut db);
assert_matches!(
err,
Err(LoadWithPersistError::InvalidChangeSet(
LoadError::Descriptor(DescriptorError::Miniscript(miniscript::Error::Unexpected(
_
)))
)),
"private multipath descriptor should fail with a Miniscript Unexpected error"
);
}

#[test]
Expand Down