Skip to content

Add P2MR (BIP360) payment support#25

Merged
BlobMaster41 merged 1 commit intomainfrom
feat/implement-p2mr
Feb 16, 2026
Merged

Add P2MR (BIP360) payment support#25
BlobMaster41 merged 1 commit intomainfrom
feat/implement-p2mr

Conversation

@BlobMaster41
Copy link
Contributor

@BlobMaster41 BlobMaster41 commented Feb 16, 2026

Description

Implement Pay-to-Merkle-Root (P2MR, BIP360) support: add P2MR payment class and legacy factory (src/payments/p2mr.ts), types (P2MRPayment), and tests/fixtures. Wire P2MR into address and PSBT utilities (address.fromOutputScript/toOutputScript, psbt utils, payments index) and add Merkle utilities (rootHashFromPathP2MR and tapBranchHash) reused from Taproot logic. Include documentation (documentation/p2mr.md) and update package metadata (package-lock.json) for a new release candidate.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Performance improvement
  • Refactoring (no functional changes)
  • Documentation update
  • CI/CD changes
  • Dependencies update

Checklist

Build & Tests

  • npm install completes without errors
  • npm test passes all tests
  • npm run browserBuild completes without errors (if applicable)

Code Quality

  • Code follows the project's coding standards
  • No new compiler/linter warnings introduced
  • Error handling is appropriate
  • TypeScript types are properly defined

Documentation

  • Code comments added for complex logic
  • Public APIs are documented
  • README updated (if applicable)

Security

  • No sensitive data (keys, credentials) committed
  • No new security vulnerabilities introduced
  • Cryptographic operations reviewed (if applicable)

Bitcoin Specific

  • Transaction serialization/deserialization is correct
  • Script operations are properly validated
  • Network parameters are handled correctly
  • PSBT operations maintain compatibility

Testing

Related Issues


By submitting this PR, I confirm that my contribution is made under the terms of the project's license.

Implement Pay-to-Merkle-Root (P2MR, BIP360) support: add P2MR payment class and legacy factory (src/payments/p2mr.ts), types (P2MRPayment), and tests/fixtures. Wire P2MR into address and PSBT utilities (address.fromOutputScript/toOutputScript, psbt utils, payments index) and add Merkle utilities (rootHashFromPathP2MR and tapBranchHash) reused from Taproot logic. Include documentation (documentation/p2mr.md) and update package metadata (package-lock.json) for a new release candidate.
@BlobMaster41 BlobMaster41 added documentation Improvements or additions to documentation enhancement New feature or request 7.x labels Feb 16, 2026
@BlobMaster41 BlobMaster41 requested a review from Copilot February 16, 2026 06:40
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements Pay-to-Merkle-Root (P2MR, referenced as BIP 360) payment support - a SegWit version 2 output type that commits directly to the Merkle root of a script tree without an internal public key. This eliminates the quantum-vulnerable key-path spend found in P2TR (Taproot) while maintaining the efficient script tree structure.

Changes:

  • Added P2MR payment class and legacy factory function with full validation and lazy-computed getters following established patterns
  • Implemented P2MR-specific Merkle utilities (rootHashFromPathP2MR) and exported tapBranchHash for reuse
  • Integrated P2MR into address encoding/decoding, PSBT utilities, type system, and exports with comprehensive test fixtures and documentation

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/payments/p2mr.ts New P2MR payment class implementation with validation, getters, factory methods, and legacy function
src/payments/types.ts Added P2MRPayment interface and P2MR to PaymentType enum and Payment union
src/payments/index.ts Exported P2MR types, classes, functions, and utilities (rootHashFromPathP2MR, tapBranchHash)
src/payments/bip341.ts Added rootHashFromPathP2MR function and made tapBranchHash public for P2MR support
src/address.ts Added P2MR detection in fromOutputScript and encoding in toOutputScript for bc1z addresses
src/psbt/psbtutils.ts Added isP2MR payment factory function for PSBT integration
src/index.ts Exported P2MRPayment type in main index
test/payments.spec.ts Added p2mr module to test execution array
test/fixtures/p2mr.json Comprehensive test fixtures covering address/output/hash conversions, script trees, and witness construction
documentation/p2mr.md Complete documentation with examples, API reference, and comparison with P2TR
package-lock.json Version bump from 7.0.0-rc.1 to 7.0.0-rc.2

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@BlobMaster41 BlobMaster41 merged commit 7a085b9 into main Feb 16, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

7.x documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments