Skip to content

xchain-bitcoin: support legacy (P2PKH / BIP44) derivation paths and addresses #1722

Description

@betelthyme

Summary

@xchainjs/xchain-bitcoin currently supports only P2WPKH (native SegWit, default, m/84'/0'/0'/0/) and P2TR (Taproot, m/86') via the AddressFormat enum. It has no support for two older, still-widely-held address types:

  • P2PKH — legacy 1… addresses, BIP44 m/44'/0'/0'/0/
  • P2SH-P2WPKH — wrapped-SegWit 3… addresses, BIP49 m/49'/0'/0'/0/

Consumers with funds on 1… or 3… addresses — common for older wallets, exchange withdrawals, and long-held cold storage — cannot derive, view balances for, or spend from those addresses using this client.

Scope decision: cover both P2PKH and P2SH-P2WPKH (the earlier open question about whether to include 3… is resolved: yes, include it).

Current state

  • packages/xchain-bitcoin/src/client.ts — default rootDerivationPaths are BIP84 (m/84').
  • AddressFormat supports P2WPKH and P2TR only (src/types/client-types.ts).
  • Address building in clientKeystore.ts / client.ts branches on P2WPKH vs P2TR (Bitcoin.payments.p2wpkh / p2tr) — no p2pkh or p2sh branch.
  • Ledger (clientLedger.ts) format handling only covers bech32 / bech32m.

Proposed work

Enum + paths

  • Add P2PKH and P2SH_P2WPKH to the AddressFormat enum.
  • Add default paths: P2PKH m/44'/0'/0'/0/ (mainnet) / m/44'/1'/0'/0/ (testnet); P2SH-P2WPKH m/49'/0'/0'/0/ (mainnet) / m/49'/1'/0'/0/ (testnet).

Address generation + tx build/sign (keystore + Ledger)

  • P2PKH: Bitcoin.payments.p2pkh; Ledger legacy uses p2pkh/base58 (not bech32).
  • P2SH-P2WPKH: Bitcoin.payments.p2sh({ redeem: Bitcoin.payments.p2wpkh(...) }); PSBT inputs need the redeemScript; Ledger uses the p2sh format.

Tests + release

  • Derivation vectors for both new formats, plus build/sign coverage.
  • Changeset (minor — additive feature).

Notes / open questions

  • Confirm the underlying UTXO providers return 1… and 3… address UTXOs correctly.
  • 3… is not exclusively wrapped-SegWit (P2SH also covers multisig/other scripts); this work specifically targets single-sig P2SH-P2WPKH (BIP49).

Context: scoped during a working session; scope confirmed to include both P2PKH and P2SH-P2WPKH. Parked to pick up later.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions