Add P2MR (BIP360) support to PSBT handling#27
Merged
BlobMaster41 merged 1 commit intomainfrom Feb 16, 2026
Merged
Conversation
Detect and handle P2MR (Pay-to-Merkle-Root) outputs throughout PSBT logic. Highlights: - Add isP2MRInput helper and treat P2MR as taproot-style input in isTaprootInput. - Avoid key-path finalization for P2MR inputs in Psbt.finalizeInput (always use script-path). - Import rootHashFromPathP2MR and isP2MR, and extend tap leaf verification to support P2MR control-block format. isTapLeafInTree now checks P2TR and P2MR control-block shapes and validates against the merkle root. - Update checks for mixed taproot/non-taproot outputs to account for P2MR. - Extensive tests added for P2MR: detection, single- and two-leaf signing/finalization, signature validation, and rejecting key-path finalization. These changes enable BIP-360 P2MR script-path spends to be signed, validated, finalized, and extracted via PSBT.
There was a problem hiding this comment.
Pull request overview
This PR adds comprehensive support for P2MR (Pay-to-Merkle-Root, BIP360) to the PSBT handling logic. P2MR is a SegWit v2 output type that commits directly to a Merkle root without an internal public key, enabling script-path spending only (no key-path). The implementation extends the existing taproot infrastructure to handle P2MR alongside P2TR throughout the PSBT signing, validation, and finalization workflows.
Changes:
- Adds P2MR detection and handling throughout PSBT input/output validation using
isP2MRInputhelper - Prevents key-path finalization for P2MR inputs (always uses script-path)
- Extends tap leaf verification with P2MR control-block format support via
rootHashFromPathP2MR - Adds comprehensive test coverage for P2MR detection, signing, finalization, and validation
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/psbt/bip371.ts | Adds isP2MRInput helper; extends isTaprootInput and isTaprootOutput to detect P2MR; updates isTapLeafInTree to verify P2MR control blocks using rootHashFromPathP2MR with fallback logic for ambiguous cases |
| src/psbt.ts | Modifies #finalizeTaprootInput to prevent key-path finalization for P2MR inputs by checking !isP2MRInput(input) before using tapKeySig |
| test/psbt.spec.ts | Adds comprehensive P2MR test suite covering detection via isTaprootInput, single/multi-leaf script-path signing and finalization, signature validation, and rejection of key-path finalization |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced Feb 17, 2026
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.
Description
Detect and handle P2MR (Pay-to-Merkle-Root) outputs throughout PSBT logic. Highlights:
These changes enable BIP-360 P2MR script-path spends to be signed, validated, finalized, and extracted via PSBT.
Type of Change
Checklist
Build & Tests
npm installcompletes without errorsnpm testpasses all testsnpm run browserBuildcompletes without errors (if applicable)Code Quality
Documentation
Security
Bitcoin Specific
Testing
Related Issues
By submitting this PR, I confirm that my contribution is made under the terms of the project's license.