feat(bip32): add BIP-328 MuSig2 synthetic xpub support - #145
Open
prestwich wants to merge 1 commit into
Open
Conversation
Adds ChainCode::musig2_synthetic_root() (the fixed BIP-328 chain code), XPub::synthetic_musig2_root() to construct a synthetic root from a MuSig2 aggregate pubkey, and XPub::is_musig2_synthetic_root() to identify one. Verified against the BIP-328 spec's own test vector. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RxoDav1hztgxJGcSGuCqKv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ChainCode::musig2_synthetic_root(), the fixed chain code BIP-328 defines for MuSig2 synthetic xpubs (sha256("MuSig2MuSig2MuSig2"))XPub::synthetic_musig2_root(key)to construct a synthetic root xpub from a MuSig2 plain aggregate pubkey (depth/parent/index fixed to 0, per the spec)XPub::is_musig2_synthetic_root()to identify whether an existingXPubmatches that synthetic-root shapeHintor the ser/deser code inenc.rs: BIP-328 reuses standard BIP32 xpub version bytes, so nothing new is needed there. Unhardened-only derivation from a synthetic root is already enforced by the existingXPub::derive_child.See https://github.com/bitcoin/bips/blob/master/bip-0328.mediawiki
Test plan
is_musig2_synthetic_rootcorrectly distinguishes a synthetic root from an ordinary xpub and from a derived childcargo test -p coins-bip32— 25 tests + 5 doctests passingcargo build --workspace,cargo clippy -p coins-bip32 --all-targets,cargo fmt -p coins-bip32 -- --checkall clean🤖 Generated with Claude Code
https://claude.ai/code/session_01RxoDav1hztgxJGcSGuCqKv