Skip to content

E2E Transaction Patterns Guide

This document explains transaction combination patterns for Bitcoin/Bitcoin Cash. Various E2E workflow patterns exist depending on key types and whether multisig is used.

Table of Contents

  1. Overview
  2. Supported Key Types
  3. Signature Patterns
  4. E2E Workflow Matrix
  5. Details of Each Pattern
  6. Account Types and Signing Requirements
  7. Implementation Status
  8. E2E Script Reference

Overview

Bitcoin transactions can be classified along two main axes:

  1. Key Type (Address Type) - Which BIP standard is used to generate addresses
  2. Signature Pattern - Single-sig or multisig

The combination of these creates various E2E workflows.


Supported Key Types

Bitcoin (BTC)

Address TypeBIPPrefix (Mainnet)Prefix (Testnet)Description
P2PKH (Legacy)BIP441...m.../n...Traditional Pay-to-Public-Key-Hash
P2SH-P2WPKHBIP493...2...SegWit wrapped in P2SH
P2WPKH (Native SegWit)BIP84bc1q...tb1q...Native SegWit
P2TR (Taproot)BIP86bc1p...tb1p...Taproot (recommended)

Bitcoin Cash (BCH)

Address TypePrefixDescription
CashAddrbitcoincash:q...Bitcoin Cash dedicated format
Legacy1...Legacy format (for compatibility)

Key Derivation Paths

StandardPathUsage
BIP44m/44'/0'/account'/change/indexP2PKH (Legacy)
BIP49m/49'/0'/account'/change/indexP2SH-P2WPKH
BIP84m/84'/0'/account'/change/indexP2WPKH (Native SegWit)
BIP86m/86'/0'/account'/change/indexP2TR (Taproot)

Signature Patterns

Single-Sig

Pattern where a single private key is used for signing.

┌─────────────────────────────────────────────────────────┐
│                  SINGLE-SIG FLOW                        │
├─────────────────────────────────────────────────────────┤
│                                                         │
│  1. Watch Wallet: Create unsigned transaction           │
│          ↓                                              │
│  2. Keygen Wallet: Sign with single key                │
│          ↓                                              │
│  3. Watch Wallet: Broadcast transaction                 │
│                                                         │
└─────────────────────────────────────────────────────────┘

Characteristics:

  • Simple and fast
  • Completed with a single signature
  • Risk concentrated since there's only one private key

Multi-Sig

Pattern where multiple private keys are used for signing. M-of-N (M signatures required out of N keys).

3-of-3 Multisig

┌─────────────────────────────────────────────────────────┐
│                  3-of-3 MULTISIG FLOW                   │
├─────────────────────────────────────────────────────────┤
│                                                         │
│  1. Watch Wallet: Create unsigned transaction           │
│          ↓                                              │
│  2. Keygen Wallet: Sign (1st signature)                │
│          ↓                                              │
│  3. Sign1 Wallet: Sign (2nd signature)                 │
│          ↓                                              │
│  4. Sign2 Wallet: Sign (3rd signature)                 │
│          ↓                                              │
│  5. Watch Wallet: Broadcast transaction                 │
│                                                         │
└─────────────────────────────────────────────────────────┘

2-of-3 Multisig

┌─────────────────────────────────────────────────────────┐
│                  2-of-3 MULTISIG FLOW                   │
├─────────────────────────────────────────────────────────┤
│                                                         │
│  1. Watch Wallet: Create unsigned transaction           │
│          ↓                                              │
│  2. Keygen Wallet: Sign (1st signature)                │
│          ↓                                              │
│  3. Sign1 Wallet: Sign (2nd signature)                 │
│          ↓                                              │
│  4. Watch Wallet: Broadcast transaction                 │
│                                                         │
│  (Sign2 Wallet not required - completed with 2 sigs)   │
│                                                         │
└─────────────────────────────────────────────────────────┘

MuSig2 (Signature Aggregation)

Aggregate signature protocol based on Schnorr signatures. N-of-N multisig becomes the same size as single-sig.

┌─────────────────────────────────────────────────────────┐
│                    MUSIG2 FLOW                          │
├─────────────────────────────────────────────────────────┤
│                                                         │
│  Round 1: Nonce Generation (can be parallelized)       │
│  ├─ Keygen Wallet: Generate nonce                       │
│  ├─ Sign1 Wallet: Generate nonce                        │
│  └─ Sign2 Wallet: Generate nonce                        │
│          ↓                                              │
│  Round 2: Signing (sequential)                         │
│  ├─ Keygen Wallet: Create partial signature             │
│  ├─ Sign1 Wallet: Create partial signature              │
│  └─ Sign2 Wallet: Create partial signature              │
│          ↓                                              │
│  Aggregation:                                           │
│  └─ Watch Wallet: Aggregate & broadcast                 │
│                                                         │
└─────────────────────────────────────────────────────────┘

MuSig2 Benefits:

  • Transaction size reduced by 30-50%
  • Improved privacy (indistinguishable from single-sig)
  • Reduced fees

E2E Workflow Matrix

BTC Pattern Matrix

PatternKey TypeSignature PatternAddress FormatE2E Script Support
1P2PKH (BIP44)Single-sig1...✅ e2e/e2e-p1-p2pkh-singlesig.sh
2P2PKH (BIP44)2-of-3 Multisig3... (P2SH wrapped)✅ e2e/e2e-p2-p2pkh-2of3.sh
3P2SH-P2WPKH (BIP49)Single-sig3...✅ e2e/e2e-p3-p2sh-p2wpkh-singlesig.sh
4P2SH-P2WSH (BIP49)2-of-3 Multisig3.../2...✅ e2e/e2e-p4-p2sh-p2wsh-2of3.sh
5P2WPKH (BIP84)Single-sigbc1q...✅ e2e/e2e-p5-p2wpkh-singlesig.sh
6P2WSH (BIP84)2-of-3 Multisigbc1q...✅ e2e/e2e-p6-p2wsh-2of3.sh
7P2WSH (BIP84)3-of-3 Multisigbc1q...✅ e2e/e2e-p7-p2wsh-3of3.sh
8P2SH-P2WSH3-of-3 Multisig3...✅ e2e/e2e-p8-p2sh-p2wsh-3of3.sh
9P2TR (BIP86)Single-sigbc1p...✅ e2e/e2e-p9-p2tr-singlesig.sh
10P2TR (BIP86)MuSig2 (N-of-N)bc1p...✅ e2e/e2e-p10-p2tr-musig2.sh
11P2TR (BIP86)Tapscript (M-of-N)bc1p...✅ e2e/e2e-p11-p2tr-tapscript.sh

BCH Pattern Matrix

BCH supports fewer patterns than BTC due to lack of SegWit, Taproot, and Schnorr signatures.

PatternKey TypeSignature PatternAddress FormatE2E Script Support
1CashAddr P2PKHSingle-sigbitcoincash:q...✅ e2e/e2e-p1-p2pkh-singlesig.sh
2CashAddr P2SH2-of-3 Multisigbitcoincash:p...✅ e2e/e2e-p2-p2sh-2of3.sh
3CashAddr P2SH3-of-3 Multisigbitcoincash:p...✅ e2e/e2e-p3-p2sh-3of3.sh

BCH Limitations:

  • ❌ No SegWit (no P2WPKH, P2WSH, P2SH-P2WPKH patterns)
  • ❌ No Taproot (no P2TR patterns)
  • ❌ No Schnorr signatures (ECDSA only)
  • ❌ No MuSig2 (no signature aggregation)
  • ❌ No Descriptor support (use address export/import instead)
  • ❌ No PSBT format (use raw transaction hex)
  • ❌ No Bech32/Bech32m encoding (use CashAddr)
  • ❌ No BIP49/84/86 derivation paths (BIP44 only)
  • ⚠️ Fee unit: sat/Byte (not sat/vByte - no witness discount)

For detailed BCH patterns, see BCH Technical Reference.


Details of Each Pattern for BTC

Pattern 1: BTC P2PKH Single-sig

Currently implemented in scripts/operation/btc/e2e/e2e-p1-p2pkh-singlesig.sh

Address Type: P2PKH (BIP44 Legacy)
Signing Requirements: Single-sig (Keygen only)
Descriptor: pkh([fingerprint/44'/0'/0']xpub.../0/*)

Workflow:

  1. Generate Seed in Keygen
  2. Generate HD Key in Keygen (10 accounts each)
  3. Export Descriptor from Keygen
  4. Import Descriptor to Watch
  5. Generate Test UTXO (regtest)
  6. Create unsigned transaction → Sign once → Broadcast

Characteristics:

  • Simple and fast (completed with single signature)
  • Sign1/Sign2 wallets not required
  • Uses BIP44 key derivation path
  • Legacy address format (m.../n... in regtest)

Pattern 2: BTC P2PKH 2-of-3 Multisig

✅ Fully implemented in scripts/operation/btc/e2e/e2e-p2-p2pkh-2of3.sh

Address Type: P2PKH (BIP44 Legacy) with 2-of-3 Multisig
Signing Requirements: 2-of-3 (Keygen + Sign1, Sign2 is optional)
Descriptor: sh(multi(2, [fingerprint/44'/1'/1]xpub1/0/*, [fingerprint/44'/1'/1]xpub2/0/*, [fingerprint/44'/1'/1]xpub3/0/*))
Address Format: 2... (P2SH in regtest), 3... (P2SH in mainnet)

Workflow:

  1. Generate Seed in Keygen/Sign1/Sign2
  2. Generate HD Key in Keygen (10 accounts each)
  3. Generate HD Key in Sign1/Sign2 (with non-hardened account derivation for multisig)
  4. Export fullpubkey from Sign1/Sign2
  5. Import fullpubkey to Keygen
  6. Export Descriptor from Keygen (generates sh(multi(2, ...)))
  7. Import Descriptor to Watch
  8. Generate Test UTXO (regtest)
  9. Create unsigned transaction → Sign 2 times → Broadcast

Characteristics:

  • 2-of-3 multisig (completed with Keygen + Sign1 signatures, Sign2 not required)
  • Uses BIP44 key derivation path with non-hardened account index for multisig
  • Generates proper P2SH addresses (2... prefix in regtest)
  • Fully compatible with Bitcoin Core descriptor import

Pattern 3: BTC P2SH-P2WPKH Single-sig

Fully implemented and verified in scripts/operation/btc/e2e/e2e-p3-p2sh-p2wpkh-singlesig.sh

Address Type: P2SH-P2WPKH (BIP49 Nested SegWit)
Signing Requirements: Single-sig (Keygen only)
Descriptor: sh(wpkh([fingerprint/49'/0'/0']xpub.../0/*))
Address Format: 2... (P2SH in regtest), 3... (P2SH in mainnet)

What is P2SH-P2WPKH (BIP49)?

P2SH-P2WPKH is SegWit (P2WPKH) wrapped in P2SH for backward compatibility. It was introduced in BIP49 as a transitional format during SegWit adoption.

BIPRole
BIP16Defines P2SH (Pay-to-Script-Hash)
BIP49Defines P2SH-P2WPKH derivation path (m/49'/...)
BIP141Defines SegWit (P2WPKH witness program)
BIP143Defines SegWit transaction signing

Address Structure

P2SH-P2WPKH Address:
┌─────────────────────────────────────────────────────┐
│  P2SH wrapper (for legacy wallet compatibility)     │
│  ┌─────────────────────────────────────────────────┐│
│  │  P2WPKH (Native SegWit)                         ││
│  │  ┌─────────────────────────────────────────────┐││
│  │  │  Public Key Hash (20 bytes)                 │││
│  │  └─────────────────────────────────────────────┘││
│  └─────────────────────────────────────────────────┘│
└─────────────────────────────────────────────────────┘

Comparison with Other Single-sig Patterns

ItemPattern 1 (P2PKH)Pattern 3 (P2SH-P2WPKH)Pattern 5 (P2WPKH)Pattern 9 (P2TR)
BIPBIP44BIP49BIP84BIP86
Address Prefix1.../m...3.../2...bc1q...bc1p...
Descriptorpkh(...)sh(wpkh(...))wpkh(...)tr(...)
SegWitNoYes (wrapped)Yes (native)Yes (Taproot)
Transaction SizeLargestMediumSmallerSmallest
Legacy CompatibleYesYesNoNo

Why Use P2SH-P2WPKH?

AspectDescription
✅ SegWit benefitsReduced transaction size compared to P2PKH, lower fees
✅ Legacy compatibility3... addresses can receive from any wallet (including old wallets)
✅ Widely supportedSupported by most exchanges and services
❌ Not optimalNative SegWit (P2WPKH) is more efficient
❌ TransitionalPrimarily for backward compatibility during SegWit migration

Workflow:

  1. Generate Seed in Keygen
  2. Generate BIP49 HD Key in Keygen (10 accounts each)
  3. Export Descriptor from Keygen (generates sh(wpkh(...)))
  4. Import Descriptor to Watch
  5. Generate Test UTXO (regtest)
  6. Create unsigned transaction → Sign once → Broadcast

Characteristics:

  • Simple and fast (completed with single signature)
  • Sign1/Sign2 wallets not required
  • Uses BIP49 key derivation path (m/49'/0'/account'/change/index)
  • P2SH address format (2... prefix in regtest)
  • SegWit transaction efficiency with legacy address compatibility

Pattern 4: BTC P2SH-P2WSH 2-of-3 Multisig

Fully implemented and verified in scripts/operation/btc/e2e/e2e-p4-p2sh-p2wsh-2of3.sh

Address Type: P2SH-P2WSH (BIP49 Nested SegWit Multisig)
Signing Requirements: 2-of-3 Multisig (any 2 signatures out of 3)
Descriptor: sh(wsh(sortedmulti(2,[fp1/49'/1'/1']xpub1/0/*,[fp2/49'/1'/1']xpub2/0/*,[fp3/49'/1'/1']xpub3/0/*)))
Address Format: 2... (P2SH in regtest), 3... (P2SH in mainnet)

What is P2SH-P2WSH 2-of-3?

P2SH-P2WSH is SegWit multisig (P2WSH) wrapped in P2SH for backward compatibility. The 2-of-3 configuration requires any 2 signatures out of 3 possible keys to authorize a transaction.

BIPRole
BIP16Defines P2SH (Pay-to-Script-Hash)
BIP49Defines P2SH-SegWit derivation path (m/49'/...)
BIP141Defines SegWit witness program
BIP143Defines SegWit transaction signing
BIP67Defines sorted multisig keys (lexicographic ordering)

Address Structure

P2SH-P2WSH 2-of-3 Address:
┌─────────────────────────────────────────────────────────────┐
│  P2SH wrapper (for legacy wallet compatibility)              │
│  ┌─────────────────────────────────────────────────────────┐ │
│  │  P2WSH (SegWit Script Hash)                              │ │
│  │  ┌─────────────────────────────────────────────────────┐ │ │
│  │  │  sortedmulti(2, pubkey1, pubkey2, pubkey3)           │ │ │
│  │  │  → 2-of-3 multisig script                            │ │ │
│  │  └─────────────────────────────────────────────────────┘ │ │
│  └─────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
ItemPattern 2 (P2PKH 2-of-3)Pattern 4 (P2SH-P2WSH 2-of-3)Pattern 8 (P2SH-P2WSH 3-of-3)
BIPBIP44BIP49BIP49
Address Prefix2... (P2SH)2... (P2SH)2... (P2SH)
Descriptorsh(multi(2,...))sh(wsh(sortedmulti(2,...)))sh(wsh(sortedmulti(3,...)))
SegWitNoYes (wrapped)Yes (wrapped)
Signature Requirement2-of-32-of-33-of-3 (all required)
Transaction SizeLargerSmallerSimilar to P4
Threshold FlexibilityMediumMediumLow (all must sign)

Why Use P2SH-P2WSH 2-of-3?

AspectDescription
✅ Threshold securityRequires only 2 out of 3 keys - provides redundancy and operational flexibility
✅ SegWit efficiencyReduced transaction size and fees compared to legacy multisig
✅ Legacy compatibility2... addresses can receive from any wallet
✅ Sorted keysUses BIP67 sorted multisig for deterministic key ordering
❌ Complex setupRequires 3 separate wallets (keygen + sign1 + sign2)
❌ Multiple signaturesRequires coordination between 2 signers

Workflow:

  1. Generate Seeds in Keygen, Sign1, Sign2 wallets
  2. Generate BIP49 HD Keys in all wallets (deposit, payment, stored accounts)
  3. Export fullpubkeys from Sign1 and Sign2 wallets
  4. Import fullpubkeys into Keygen wallet
  5. Export 2-of-3 multisig descriptors from Keygen (generates sh(wsh(sortedmulti(2,...))))
  6. Import descriptors into Watch wallet
  7. Generate Test UTXOs (regtest)
  8. Create unsigned transaction → Sign with Keygen (1st) → Sign with Sign1 (2nd) → Broadcast

Characteristics:

  • 2-of-3 threshold: Any 2 signatures out of 3 are sufficient (Sign2 not needed if Keygen + Sign1 sign)
  • Uses BIP49 key derivation path (m/49'/1'/1'/change/index for multisig)
  • P2SH address format (2... prefix in regtest, 3... in mainnet)
  • SegWit transaction efficiency with legacy address compatibility
  • Configuration: Uses account_2of3.yaml for multisig account settings
  • Security model: Provides redundancy - losing one key doesn't prevent access to funds

Signing Flow:

Watch Wallet (create unsigned tx)

Keygen Wallet (1st signature)

Sign1 Wallet (2nd signature) ← Complete here! (2-of-3 satisfied)

Watch Wallet (broadcast)

Note: Sign2 is optional - 2 signatures already satisfy the 2-of-3 requirement

Pattern 6: BTC P2WSH Native SegWit 2-of-3 Multisig

✅ Fully implemented in scripts/operation/btc/e2e/e2e-p6-p2wsh-2of3.sh

Address Type: P2WSH (BIP84 Native SegWit Multisig)
Signing Requirements: 2-of-3 Multisig (any 2 signatures out of 3)
Descriptor: wsh(sortedmulti(2,[fp1/84'/1'/1']xpub1/0/*,[fp2/84'/1'/1']xpub2/0/*,[fp3/84'/1'/1']xpub3/0/*))
Address Format: bcrt1q... (62 chars for P2WSH in regtest), bc1q... (mainnet)

What is P2WSH 2-of-3?

P2WSH (Pay-to-Witness-Script-Hash) is native SegWit multisig without P2SH wrapper. The 2-of-3 configuration requires any 2 signatures out of 3 possible keys to authorize a transaction. This is the most efficient multisig format for Bitcoin.

BIPRole
BIP84Defines native SegWit derivation path (m/84'/...)
BIP141Defines SegWit witness program (P2WSH)
BIP143Defines SegWit transaction signing
BIP67Defines sorted multisig keys (lexicographic ordering)

Address Structure

P2WSH 2-of-3 Address (Native SegWit):
┌─────────────────────────────────────────────────────────────┐
│  P2WSH (Native SegWit - no P2SH wrapper)                     │
│  ┌─────────────────────────────────────────────────────────┐ │
│  │  sortedmulti(2, pubkey1, pubkey2, pubkey3)               │ │
│  │  → 2-of-3 multisig witness script                        │ │
│  │  → SHA256 hash becomes witness program (32 bytes)        │ │
│  │  → Bech32-encoded as bc1q... address                     │ │
│  └─────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
ItemPattern 4 (P2SH-P2WSH 2-of-3)Pattern 6 (P2WSH 2-of-3)Pattern 7 (P2WSH 3-of-3)
BIPBIP49BIP84BIP84
Address Prefix2... (P2SH)bc1q... (62 chars)bc1q... (62 chars)
Descriptorsh(wsh(sortedmulti(2,...)))wsh(sortedmulti(2,...))wsh(sortedmulti(3,...))
SegWitYes (wrapped)Yes (native)Yes (native)
Signature Requirement2-of-32-of-33-of-3 (all required)
Transaction SizeMediumSmallestSlightly larger than P6
Legacy CompatibleYesNoNo

Why Use P2WSH 2-of-3?

AspectDescription
✅ Threshold securityRequires only 2 out of 3 keys - provides redundancy and operational flexibility
✅ Maximum efficiencyNo P2SH wrapper - smallest transaction size for multisig
✅ Lowest feesNative SegWit provides the best fee rates
✅ Sorted keysUses BIP67 sorted multisig for deterministic key ordering
✅ Descriptor-basedFull Bitcoin Core descriptor wallet support
❌ No legacy compatibilityCannot receive from very old wallets (requires Bech32 support)
❌ Complex setupRequires 3 separate wallets (keygen + sign1 + sign2)

Workflow:

  1. Generate Seeds in Keygen, Sign1, Sign2 wallets
  2. Generate BIP84 HD Keys in all wallets (deposit, payment, stored accounts)
  3. Export fullpubkeys from Sign1 and Sign2 wallets
  4. Import fullpubkeys into Keygen wallet
  5. Export 2-of-3 multisig descriptors from Keygen (generates wsh(sortedmulti(2,...)))
  6. Import descriptors into Watch wallet
  7. Generate Test UTXOs (regtest)
  8. Create unsigned transaction → Sign with Keygen (1st) → Sign with Sign1 (2nd) → Broadcast

Characteristics:

  • 2-of-3 threshold: Any 2 signatures out of 3 are sufficient (Sign2 not needed if Keygen + Sign1 sign)
  • Uses BIP84 key derivation path (m/84'/1'/1'/change/index for multisig)
  • Native SegWit Bech32 address format (bcrt1q... 62 chars in regtest, bc1q... in mainnet)
  • Most efficient multisig format (no P2SH overhead)
  • Configuration: Uses account_2of3.yaml for multisig account settings
  • Security model: Provides redundancy - losing one key doesn't prevent access to funds

Signing Flow:

Watch Wallet (create unsigned tx)

Keygen Wallet (1st signature)

Sign1 Wallet (2nd signature) ← Complete here! (2-of-3 satisfied)

Watch Wallet (broadcast)

Note: Sign2 is optional - 2 signatures already satisfy the 2-of-3 requirement

Implementation Notes:

  • Requires native SegWit descriptor support in PSBT creation
  • Address derivation uses NewAddressWitnessScriptHash() with SHA256 hash
  • Witness script format: OP_2 <pubkey1> <pubkey2> <pubkey3> OP_3 OP_CHECKMULTISIG
  • Public keys are sorted lexicographically per BIP67

Pattern 8: BTC P2SH-P2WSH 3-of-3 Multisig

✅ Fully implemented in scripts/operation/btc/e2e/e2e-p8-p2sh-p2wsh-3of3.sh

Address Type: P2SH-P2WSH (SegWit multisig wrapped in P2SH)
Signing Requirements: 3-of-3 (Keygen + Sign1 + Sign2)
Descriptor: sh(wsh(sortedmulti(3, xpub1, xpub2, xpub3)))

What is P2SH-P2WSH?

P2SH-P2WSH is a nested structure where P2WSH (Pay-to-Witness-Script-Hash) is wrapped inside P2SH (Pay-to-Script-Hash). This is achieved through a combination of multiple BIPs:

BIPRole
BIP16Defines P2SH (Pay-to-Script-Hash)
BIP141Defines SegWit (including P2WSH)
BIP143Defines SegWit transaction signing

Note: P2SH-P2WSH is different from BIP49 (P2SH-P2WPKH):

  • BIP49 (P2SH-P2WPKH): Wraps P2WPKH (single public key) in P2SH → For Single-sig
  • P2SH-P2WSH: Wraps P2WSH (witness script) in P2SH → For Multisig

Why No Single-sig or 2-of-3 Variants?

VariantReason for Absence
Single-sigP2SH-P2WPKH (BIP49, Pattern 3) is sufficient. P2SH-P2WSH is designed for complex scripts
2-of-3Technically possible but not implemented in this project (prioritization)

P2SH-P2WSH is primarily used for complex multisig scripts while maintaining SegWit efficiency and backward compatibility with legacy wallets.

Comparison with Other Patterns

PatternDescriptorUse Case
Pattern 2sh(multi(2, ...))Legacy P2SH multisig
Pattern 6-7wsh(sortedmulti(...))Native SegWit multisig
Pattern 8sh(wsh(sortedmulti(...)))SegWit multisig + Legacy compatibility

Pros and Cons

AspectDescription
✅ Legacy compatibility3... addresses can receive from legacy wallets
✅ SegWit efficiencyWitness data stored separately, reducing transaction size
❌ ComplexityNested structure makes implementation and debugging more complex
❌ SizeSlightly larger than Native SegWit (P2WSH)

Workflow:

  1. Generate Seed in Keygen/Sign1/Sign2
  2. Generate HD Key in Keygen (10 accounts each)
  3. Generate HD Key in Sign1/Sign2
  4. Export fullpubkey from Sign1/Sign2
  5. Import fullpubkey to Keygen
  6. Export Descriptor from Keygen
  7. Import Descriptor to Watch
  8. Generate Test UTXO (regtest)
  9. Create unsigned transaction → Sign 3 times → Broadcast

Pattern 9: BTC P2TR Single-sig (Taproot)

✅ Fully implemented in scripts/operation/btc/e2e/e2e-p9-p2tr-singlesig.sh

Address Type: P2TR (BIP86 Taproot)
Signing Requirements: Single-sig (Keygen only)
Descriptor: tr([fingerprint/86'/0'/0']xpub.../0/*)
Address Format: bc1p... (Mainnet), tb1p... (Testnet), bcrt1p... (regtest)
Bitcoin Core: v22.0+ required

What is P2TR (Taproot)?

P2TR (Pay-to-Taproot) is Bitcoin's latest major upgrade (activated November 2021) that introduces a new address format and signature scheme. It combines Schnorr signatures and Merkelized Alternative Script Trees (MAST) into a single output type.

BIPRole
BIP86Defines key derivation path (m/86'/...) for Taproot key path spend
BIP340Defines Schnorr signature scheme (64 bytes vs 71-72 for ECDSA)
BIP341Defines Taproot output structure and spending rules
BIP342Defines Tapscript (script semantics for Taproot)

Address Structure

P2TR Address (SegWit v1 - Taproot):
┌─────────────────────────────────────────────────────────────┐
│  Bech32m Encoding (NOT Bech32!)                              │
│  ┌─────────────────────────────────────────────────────────┐ │
│  │  Witness Version: 1 (different from v0 in P2WPKH)       │ │
│  │  ┌─────────────────────────────────────────────────────┐ │ │
│  │  │  Tweaked Public Key (32 bytes, x-only format)        │ │ │
│  │  │  output_key = internal_key + H_TapTweak(P) * G       │ │ │
│  │  └─────────────────────────────────────────────────────┘ │ │
│  └─────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘

Format: bc1p + 58 characters (mainnet, 62 chars total)
        tb1p + 58 characters (testnet/signet)
        bcrt1p + 58 characters (regtest)

Comparison with Other Single-sig Patterns

ItemPattern 1 (P2PKH)Pattern 3 (P2SH-P2WPKH)Pattern 5 (P2WPKH)Pattern 9 (P2TR)
BIPBIP44BIP49BIP84BIP86
Address Prefix1.../m...3.../2...bc1q...bc1p...
Descriptorpkh(...)sh(wpkh(...))wpkh(...)tr(...)
SegWit VersionN/Av0 (wrapped)v0 (native)v1 (Taproot)
SignatureECDSAECDSAECDSASchnorr (BIP340)
Signature Size71-72 bytes71-72 bytes71-72 bytes64 bytes
Transaction SizeLargestMediumSmallerSmallest
EncodingBase58CheckBase58CheckBech32Bech32m
address_typelegacyp2sh-segwitbech32taproot

Key Path vs Script Path Spending

Taproot supports two spending paths:

Spend TypeDescriptionUse CasePattern
Key PathDirect signature with tweaked keySingle-sig, efficient multisigPattern 9
Script PathReveal Merkle proof + satisfy scriptComplex conditions, timelocksPattern 11

Pattern 9 uses Key Path Spend - the most efficient method when only a single key controls the funds.

Why Use P2TR (Taproot)?

AspectDescription
✅ Smallest transactions~30-40% smaller than P2PKH, ~15% smaller than P2WPKH
✅ Lowest feesMost efficient single-sig format
✅ Enhanced privacyAll Taproot spends (single-sig and multisig) look identical
✅ Schnorr signatures64 bytes vs 71-72 for ECDSA, batch verification possible
✅ Future-proofLatest Bitcoin address standard
✅ Faster validationSchnorr signatures verify faster than ECDSA
❌ Requires Bitcoin Core v22.0+Older nodes cannot create/validate Taproot
❌ Newer standardSome services may not support bc1p... addresses yet

Key Derivation Path (BIP86)

m / 86' / coin_type' / account' / change / address_index
         └─ 0' for mainnet, 1' for testnet/regtest

Schnorr Signature (BIP340)

Schnorr Signature: 64 bytes total
  ┌──────────────────────────────────────────────────────────┐
  │  r (32 bytes) │ s (32 bytes)                              │
  │  x-coord of R │ scalar value                              │
  └──────────────────────────────────────────────────────────┘

ECDSA Signature (DER encoded): 71-72 bytes
  ┌──────────────────────────────────────────────────────────┐
  │ 30 │ len │ 02 │ r_len │ r │ 02 │ s_len │ s              │
  └──────────────────────────────────────────────────────────┘

Workflow:

  1. Generate Seed in Keygen
  2. Generate BIP86 HD Key in Keygen (10 accounts each)
  3. Export Taproot Descriptor from Keygen (generates tr(...))
  4. Import Descriptor to Watch
  5. Generate Test UTXO (regtest)
  6. Create unsigned transaction → Sign once (Schnorr) → Broadcast

Signing Flow (Single-sig):

Watch Wallet (create unsigned tx)

Keygen Wallet (sign with Schnorr signature - 64 bytes)

Watch Wallet (broadcast)

Characteristics:

  • Simple and fast (completed with single Schnorr signature)
  • Sign1/Sign2 wallets not required
  • Uses BIP86 key derivation path (m/86'/0'/account'/change/index)
  • Taproot address format (bcrt1p... prefix in regtest)
  • Most efficient single-sig transaction format
  • Requires Bitcoin Core v22.0+ (Taproot/Schnorr support)

Implementation Notes:

  • Environment variable: WALLET_ADDRESS_TYPE="taproot"
  • Descriptor format: tr([fingerprint/86'/coin'/account']xpub.../0/*)
  • Uses Bech32m encoding (NOT Bech32 - different checksum constant)
  • Witness version 1 (vs version 0 for P2WPKH)
  • Address derivation uses x-only public keys (32 bytes, parity byte removed)

Pattern 10: BTC P2TR MuSig2

Implementation Status: Framework implemented - CLI commands have TODOs for full MuSig2 protocol E2E Test Status: ✅ Verified (2026-01-16) - Infrastructure, wallets, Taproot addresses, and workflow framework working correctly

Address Type: P2TR (BIP86)
Signing Requirements: N-of-N MuSig2 (all signatures required)
Descriptor: tr(musig([fingerprint1/86'/1'/1']xpub1,[fingerprint2]xpub2,[fingerprint3]xpub3)/0/*)

2-Round Protocol:

  1. Round 1: Generate nonces in each wallet (parallelizable)
  2. Round 2: Create partial signatures in each wallet (sequential)
  3. Aggregate signatures in Watch and broadcast

Implementation Notes:

  • Environment variable: WALLET_ADDRESS_TYPE="taproot"
  • Uses BIP86 key derivation (m/86'/coin'/account'/change/index)
  • Address format: bcrt1p... (regtest), bc1p... (mainnet) - bech32m encoding
  • Requires Bitcoin Core v22.0+ for descriptor-based wallets
  • 2-round signing protocol (BIP327)
  • Framework script available at scripts/operation/btc/e2e/e2e-p10-p2tr-musig2.sh

E2E Test Verified Components:

  • ✅ Infrastructure setup (Docker, Bitcoin Core regtest, MySQL)
  • ✅ Wallet creation and configuration (watch, keygen, sign1, sign2)
  • ✅ HD key generation for all accounts (deposit, payment, stored)
  • ✅ Taproot address generation with correct bech32m encoding
  • ✅ Descriptor export and import (2000 addresses generated)
  • ✅ UTXO generation and balance verification
  • ✅ Payment workflow and transaction creation
  • ⚠️ MuSig2 protocol (Round 1/2, aggregation) - Placeholder implementation pending full CLI support

Details of Each Pattern for BCH

BCH Pattern 3: BCH CashAddr P2SH 3-of-3 Multisig

✅ Fully implemented and verified in scripts/operation/bch/e2e/e2e-p3-p2sh-3of3.sh

Address Type: CashAddr P2SH (BIP44 + BIP11)
Signing Requirements: 3-of-3 (Keygen + Sign1 + Sign2)
Address Format: bchreg:p... (P2SH multisig in regtest)
Key Derivation: m/44'/1'/account'/change/index (testnet/regtest)

Implementation Status:

  • ✅ Infrastructure and wallet setup
  • ✅ HD key generation and fullpubkey export/import
  • ✅ 3-of-3 multisig address creation
  • ✅ Payment request creation and database storage
  • UTXO retrieval (Fixed in PR #426 - CashAddr format normalization)
  • ✅ Transaction creation and signing workflow
  • ⚠️ PSBT generation (Known issue with BCH label format)

Workflow:

  1. Generate Seed in Keygen/Sign1/Sign2
  2. Generate HD Key in Keygen (10 keys per account)
  3. Generate HD Key in Sign1/Sign2
  4. Export fullpubkey from Sign1/Sign2
  5. Import fullpubkey to Keygen
  6. Create 3-of-3 Multisig addresses in Keygen
  7. Export addresses from Keygen (CashAddr format)
  8. Import addresses to Watch wallet
  9. Generate Test UTXO (regtest)
  10. Create unsigned transaction → Sign 3 times (ECDSA) → Broadcast

Signing Flow:

Watch Wallet (create unsigned tx)

Keygen Wallet (1st ECDSA signature)

Sign1 Wallet (2nd ECDSA signature)

Sign2 Wallet (3rd ECDSA signature)

Watch Wallet (broadcast)

Note: Unlike BTC's SegWit patterns, BCH transactions don't benefit from witness data separation, resulting in larger transaction sizes. BCH compensates with very low fees (~1 sat/byte).

For more BCH patterns, see BCH Technical Reference


Account Types and Signing Requirements

AccountPurposeRecommended Signature PatternReason
clientCustomer deposit addressesSingle-sigRequired for customer-side operations
depositDeposit aggregationMultisig (2-of-3 or 3-of-3)Enhanced security
paymentPaymentsMultisig (2-of-3 or 3-of-3)Approval workflow
storedLong-term storageMultisig (3-of-3)Highest level of security

Implementation Status

Key Type Implementation Status

Key TypeBTCBCH
P2PKH (Legacy)✅ ImplementedN/A
P2SH-P2WPKH (BIP49)✅ ImplementedN/A
P2WPKH (BIP84)✅ ImplementedN/A
P2TR (BIP86)✅ ImplementedN/A
CashAddrN/A✅ Implemented

Signature Pattern Implementation Status

Signature PatternBTCBCH
Single-sig✅ Implemented✅ Implemented
2-of-3 Multisig✅ Implemented (Fixed in #357)⚠️ Partial
3-of-3 Multisig✅ Implemented✅ Implemented
MuSig2🔜 In developmentN/A

Descriptor Support

FeatureBTCBCH
Descriptor Export✅ Implemented❌ Not supported
Descriptor Import✅ Implemented❌ Not supported
Bitcoin Core Integration✅ ImplementedN/A

E2E Script Reference

Currently Available E2E Scripts

ScriptCoinPatternSigning Requirements
scripts/operation/btc/e2e/e2e-p1-p2pkh-singlesig.shBTCP2PKH Single-sig (Pattern 1)Single-sig
scripts/operation/btc/e2e/e2e-p2-p2pkh-2of3.shBTCP2PKH 2-of-3 Multisig (Pattern 2)2-of-3
scripts/operation/btc/e2e/e2e-p3-p2sh-p2wpkh-singlesig.shBTCP2SH-P2WPKH Single-sig (Pattern 3)Single-sig
scripts/operation/btc/e2e/e2e-p4-p2sh-p2wsh-2of3.shBTCP2SH-P2WSH 2-of-3 Multisig (Pattern 4)2-of-3
scripts/operation/btc/e2e/e2e-p5-p2wpkh-singlesig.shBTCP2WPKH Native SegWit Single-sig (Pattern 5)Single-sig
scripts/operation/btc/e2e/e2e-p6-p2wsh-2of3.shBTCP2WSH Native SegWit 2-of-3 Multisig (Pattern 6)2-of-3
scripts/operation/btc/e2e/e2e-p7-p2wsh-3of3.shBTCP2WSH Native SegWit 3-of-3 Multisig (Pattern 7)3-of-3
scripts/operation/btc/e2e/e2e-p8-p2sh-p2wsh-3of3.shBTCP2SH-P2WSH 3-of-3 Multisig (Pattern 8)3-of-3
scripts/operation/btc/e2e/e2e-p9-p2tr-singlesig.shBTCP2TR Taproot Single-sig (Pattern 9)Single-sig
scripts/operation/btc/e2e/e2e-p10-p2tr-musig2.shBTCP2TR MuSig2 (Pattern 10)N-of-N (framework)
scripts/operation/btc/e2e/e2e-p11-p2tr-tapscript.shBTCP2TR Tapscript (Pattern 11)2-of-3 (framework)
scripts/operation/bch/e2e/e2e-p1-p2pkh-singlesig.shBCHCashAddr P2PKH Single-sig (Pattern 1)Single-sig
scripts/operation/bch/e2e/e2e-p2-p2sh-2of3.shBCHCashAddr P2SH 2-of-3 Multisig (Pattern 2)2-of-3
scripts/operation/bch/e2e/e2e-p3-p2sh-3of3.shBCHCashAddr P2SH 3-of-3 Multisig (Pattern 3)3-of-3

Planned E2E Scripts

No additional E2E scripts planned at this time. All 11 Bitcoin patterns are implemented.


Quick Reference

Identifying BTC Address Types

PrefixTypeBIPSegWit
1...P2PKHBIP44
3...P2SH or P2SH-P2WPKHBIP16/BIP49
bc1q...P2WPKH or P2WSHBIP84
bc1p...P2TR (Taproot)BIP86

Identifying BCH Address Types

PrefixTypeMultisig
bitcoincash:q...P2PKH
bitcoincash:p...P2SH

Transaction Size Comparison

PatternWeightvBytesNotes
P2PKH Single-sig (1-in, 2-out)~680~170Legacy
P2WPKH Single-sig (1-in, 2-out)~440~110Native SegWit
P2TR Single-sig (1-in, 2-out)~396~99Taproot
2-of-3 P2WSH Multisig~1,100~275Traditional Multisig
2-of-3 MuSig2 (P2TR)~560~140Signature Aggregation


Document Version: 1.10 Last Updated: 2026-01-17 Maintainer: go-crypto-wallet team


Changelog

Version 1.10 (2026-01-17)

  • ✅ Fixed BCH Pattern 3 (3-of-3 Multisig) UTXO retrieval issue (Closes #423, PR #426)
  • Resolved CashAddr format mismatch in ListUnspentByAccount address comparison
  • Updated BCH Pattern Matrix to show all 3 patterns with correct E2E script paths
  • Updated E2E Script Reference with proper BCH script locations
  • Added implementation status details for BCH Pattern 3
  • All BCH patterns now have dedicated E2E scripts in scripts/operation/bch/e2e/

Version 1.9 (2026-01-17)

  • Updated BCH Pattern Matrix with accurate pattern numbering (1, 2, 3)
  • Added BCH limitations section (no SegWit, Taproot, Schnorr, MuSig2)
  • Updated BCH Pattern 3 (3-of-3 Multisig) with detailed workflow and signing flow
  • Added cross-reference link to BCH Technical Reference
  • Renamed "BCH Pattern 2" to "BCH Pattern 3" to reflect correct pattern numbering

Version 1.8 (2026-01-16)

  • ✅ Pattern 11 (P2TR Tapscript M-of-N) framework implemented
  • E2E script e2e-p11-p2tr-tapscript.sh created (Closes #381)
  • Implements Tapscript Script Path spending framework with 2-of-3 threshold
  • Uses BIP86 key derivation + BIP342 Tapscript semantics
  • Script tree with Merkle proof and control block structure
  • M × Schnorr signatures for Script Path spend
  • Address format: bcrt1p... (62 chars, Bech32m encoding)
  • ~50% smaller than P2WSH 2-of-3 multisig
  • Enhanced privacy: unused script paths hidden in Merkle tree
  • Note: Full Tapscript implementation pending (currently uses placeholder)

Version 1.7 (2026-01-16)

  • ✅ Pattern 9 (P2TR Taproot Single-sig) is now fully working
  • E2E script e2e-p9-p2tr-singlesig.sh completed and verified (Closes #377)
  • Fixed Taproot address derivation to use x-only public keys (32 bytes)
  • Implements BIP86 key derivation for Taproot key path spending
  • Uses Schnorr signatures (BIP340, 64 bytes)
  • Most efficient single-sig transaction format
  • Address format: bcrt1p... (62 chars, Bech32m encoding)

Version 1.6 (2026-01-16)

  • ✅ Pattern 8 (P2SH-P2WSH 3-of-3 Multisig) is now fully working
  • E2E script e2e-p8-p2sh-p2wsh-3of3.sh completed and verified
  • Fixed receiver address generation to use P2SH-SegWit format (Closes #374)
  • P2SH-wrapped SegWit multisig with legacy compatibility (2... addresses in regtest)
  • Implements BIP49 key derivation for 3-of-3 multisig
  • All 3 signatures required (Keygen + Sign1 + Sign2)

Version 1.5 (2026-01-16)

  • ✅ Pattern 6 (P2WSH Native SegWit 2-of-3 Multisig) is now fully working
  • E2E script e2e-p6-p2wsh-2of3.sh completed and verified
  • Native SegWit multisig with Bech32 encoding (bcrt1q... 62-char addresses)
  • Added native SegWit descriptor support (wsh, wpkh) in PSBT infrastructure
  • Most efficient multisig format - no P2SH wrapper overhead
  • Implements BIP84 key derivation and BIP67 sorted multisig keys

Version 1.4 (2026-01-15)

  • ✅ Pattern 5 (P2WPKH Native SegWit Single-sig) is now fully working
  • E2E script e2e-p5-p2wpkh-singlesig.sh completed and verified
  • Native SegWit with Bech32 encoding (bcrt1q... addresses)

Version 1.3 (2026-01-15)

  • ✅ Pattern 3 (P2SH-P2WPKH Single-sig) is now fully working
  • E2E script e2e-p3-p2sh-p2wpkh-singlesig.sh completed and verified

Version 1.2 (2026-01-15)

  • ✅ Pattern 2 (P2PKH 2-of-3 Multisig) is now fully working
  • Fixed key derivation path mismatch for multisig accounts (PR #357)
  • Added detailed explanation of the fix and root cause
  • Updated implementation status for 2-of-3 multisig

Version 1.1 (2026-01-14)

  • Initial comprehensive documentation of all patterns