Skip to content

feat(bip32): add BIP-328 MuSig2 synthetic xpub support - #145

Open
prestwich wants to merge 1 commit into
mainfrom
prestwich/bip328-musig2-synthetic-xpub
Open

feat(bip32): add BIP-328 MuSig2 synthetic xpub support#145
prestwich wants to merge 1 commit into
mainfrom
prestwich/bip328-musig2-synthetic-xpub

Conversation

@prestwich

Copy link
Copy Markdown
Member

Summary

  • Adds ChainCode::musig2_synthetic_root(), the fixed chain code BIP-328 defines for MuSig2 synthetic xpubs (sha256("MuSig2MuSig2MuSig2"))
  • Adds 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)
  • Adds XPub::is_musig2_synthetic_root() to identify whether an existing XPub matches that synthetic-root shape
  • No changes to Hint or the ser/deser code in enc.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 existing XPub::derive_child.

See https://github.com/bitcoin/bips/blob/master/bip-0328.mediawiki

Test plan

  • New unit tests verify the constructor reproduces the spec's own test vector byte-for-byte, and that is_musig2_synthetic_root correctly distinguishes a synthetic root from an ordinary xpub and from a derived child
  • cargo test -p coins-bip32 — 25 tests + 5 doctests passing
  • cargo build --workspace, cargo clippy -p coins-bip32 --all-targets, cargo fmt -p coins-bip32 -- --check all clean

🤖 Generated with Claude Code

https://claude.ai/code/session_01RxoDav1hztgxJGcSGuCqKv

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
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.

1 participant