Skip to content

Conversation

apoelstra
Copy link
Member

Since #851 we return a NotSupported error when attempting to request an xpriv from an x-only key. I'm not sure if this is the correct semantics, but it was deliberately written, so we'll keep it. However the behavior was different for multipath xprivs. There we returned None, i.e. "key not found/mismatch" rather than an error.

This PR returns an error in both cases.

@apoelstra
Copy link
Member Author

cc @oleonardolima can you review whether this PR looks correct, and if so, ACK it (then I will merge it) and also backport it into #860?

@apoelstra apoelstra force-pushed the 2025-09/fix-keymap branch 2 times, most recently from fe3342d to df8d860 Compare September 30, 2025 15:23
Copy link
Member Author

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On df8d860 successfully ran local tests

tcharding
tcharding previously approved these changes Sep 30, 2025
Copy link
Member

@tcharding tcharding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK df8d860

Copy link
Contributor

@oleonardolima oleonardolima left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Sorry for the oversight on the multipath descriptors.

Overall it looks good to me, just a minor comment on the test. I'll apply the tests to the backport PR.

assert!(matches!(result, Err(GetKeyError::NotSupported)));

// Also test with KeyMap; as in the previous test, the error turns to None.
let descriptor_s = "wpkh([d34db33f/84h/1h/0h]tprv8ZgxMBicQKsPd3EupYiPRhaMooHKUHJxNsTfYuScep13go8QFfHdtkG9nRkFGb7busX4isf6X9dURGCoKgitaApQ6MupRhZMcELAxTBRJgS/*)";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: any reason not to test with the multipath here too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, no, just an oversight. This test has been pretty frustrating to write because both the keys and the descriptors have paths in them, and you can't directly construct a multi-path DerivationPath so you need to do everything by parsing descriptor strings..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the test.

Copy link
Contributor

@oleonardolima oleonardolima Oct 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I suggested the changes, I noticed that I wont' be able to backport this to the release/12.x as it didn't converted Xpriv to Xpub properly for multipath: #757, and get the old error.

Claude 4 wrote the original tests; I then replaced its fix (which incorrectly
also propagated errors in GetKey for KeyMap), updated the tests, and removed
some extra tests which seemed uninformative and just noisy.

To backport this to 12.x, just do s/KeyMap/KeyMapWrapper/ on the new tests.
Oh, and add some `let keymap = KeyMapWrapper::from(keymap)` lines.

Co-authored-by: aider (anthropic/claude-sonnet-4-20250514) <aider@aider.chat>
Copy link
Member Author

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On 89b5048 successfully ran local tests

Copy link
Contributor

@oleonardolima oleonardolima left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 89b5048

@apoelstra apoelstra merged commit 47d421a into rust-bitcoin:master Oct 2, 2025
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants