feat: support BIP-322 P2WSH multisig signatures in auth#3637
Open
TaprootFreak wants to merge 2 commits intodevelopfrom
Open
feat: support BIP-322 P2WSH multisig signatures in auth#3637TaprootFreak wants to merge 2 commits intodevelopfrom
TaprootFreak wants to merge 2 commits intodevelopfrom
Conversation
12 tasks
TaprootFreak
added a commit
to DFXswiss/btc-wallet
that referenced
this pull request
Apr 28, 2026
Adds a pure verifier mirroring the backend implementation in DFXswiss/api#3637, exposed both as a standalone function (verifyBip322Signature) and as MultisigHDWallet.verifyMessage so the existing Sign/Verify Message screen works symmetrically: a signature produced by signMessage on one device can be verified on any device holding the same wallet (or just the address). Verifier algorithm: - strict P2WSH address detection (bc1q…, 62 chars, 32-byte program) - base64 → witness stack (varint-prefixed items) - last item must be the witness script; sha256 must match the bech32 program - script must be standard OP_M … OP_N OP_CHECKMULTISIG with 33-byte pubkeys - exactly M signatures + empty CHECKMULTISIG dummy - BIP-143 sighash over the synthetic to_spend / to_sign pair - ECDSA verify each sig against pubkeys in script order, sighash flag 0x01 Adds 7 tests covering: round-trip with signMessage, multiple message lengths (incl. unicode and 200-char), wrong-message rejection, wrong-address rejection, PSBT cross-device round-trip verification, malformed-input handling, and isP2wshAddress detection.
8 tasks
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
bc1q…62 chars) in the auth flow, so users can sign in withwsh(sortedmulti(t, …))/wsh(multi(t, …))wallets.crypto.service.ts:verifyBitcoinBased, only when no message-prefix is set (Bitcoin mainnet) and the address passes strict P2WSH detection — existing P2WPKH/P2SH-P2WPKH/P2TR/legacy paths are untouched.OP_M … OP_N OP_CHECKMULTISIGwitness scripts with SIGHASH_ALL signatures. Miniscript / Taproot scripts / non-standard policies are rejected.Implementation notes
@noble/curves,@noble/hashes,bech32— all already in deps), no new packages.to_spend/to_signpair from BIP-322.typeof address !== 'string'guards on the public entry points, matching the precedent inbech32m.service.ts.Client-side caveat
Sparrow Wallet's Sign/Verify Message dialog does not accept multisig wallets (hard-coded
IllegalArgumentException, issue #193). Producing a BIP-322 simple signature for a multisig today requires either Bitcoin Knotssignmessage, or building the BIP-322to_signPSBT externally and signing it through Sparrow's regular multisig PSBT flow. The backend code here is signing-tool-agnostic.Test plan
bip322-p2wsh.util.spec.ts— 15 tests:it.todoplaceholder for a real wallet-produced fixturecrypto.service.spec.ts— 67 existing tests still green/auth