Skip to content

feat: Bitcoin native support — Phase 0 architecture & interface definitions#599

Open
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
devin/1777412122-bitcoin-architecture
Open

feat: Bitcoin native support — Phase 0 architecture & interface definitions#599
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
devin/1777412122-bitcoin-architecture

Conversation

@devin-ai-integration
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot commented Apr 28, 2026

Summary

Phase 0 (Team A — Architecture) deliverables for Bitcoin native support in MetaMask Mobile.

This PR adds no production code changes — it defines the interfaces, contracts, and architecture documentation needed to guide the implementation of native Bitcoin support.

Architecture Document (docs/bitcoin-architecture.md)

Comprehensive document covering:

  • Current architecture analysis — How the Engine singleton, controller pattern, RestrictedMessenger, and existing multichain infrastructure (Solana, Bitcoin Snap) work today
  • Bitcoin domain model — UTXO vs account model comparison, address types (P2PKH → P2TR), BIP44/49/84/86 key derivation paths
  • Component architecture — How Bitcoin modules fit into the existing controller layer, with rendered PNG diagrams
  • Data flow diagrams — Balance check, send transaction, receive address, and account creation flows
  • Integration points — Contracts with KeyringController, NetworkController, MultichainBalancesController, MultichainTransactionsController, AccountsController, and the UI layer
  • Migration strategy — 6-phase adoption plan from current Snap-based support to fully native implementation

TypeScript Interface Definitions (app/core/Bitcoin/types/)

File Contents
account.ts BitcoinUtxo, BitcoinBalance, BitcoinAccountData, CreateBitcoinAccountParams
address.ts BitcoinAddressType enum (P2PKH, P2SH, P2WPKH, P2WSH, P2TR), BitcoinAddress, metadata registry
network.ts BitcoinNetworkId enum (mainnet, testnet, signet, regtest), BitcoinNetworkConfig with block explorer URLs
transaction.ts BitcoinTransaction, BitcoinTransactionParams, BitcoinFeeRates, CoinSelectionResult, CoinSelectionStrategy
keyring.ts BitcoinDerivationPath, BitcoinDerivationPurpose, derivation path formatting helpers
controller.ts BitcoinAccountService, BitcoinTransactionService, BitcoinNetworkService contracts
index.ts Barrel export

Architecture Diagrams (rendered PNG images)

  • docs/assets/bitcoin-architecture-components.png — Full component architecture
  • docs/assets/bitcoin-architecture-layers.png — Data flow layer diagram
  • docs/assets/bitcoin-flow-balance.png — Balance check data flow
  • docs/assets/bitcoin-flow-send.png — Send transaction data flow

Review & Testing Checklist for Human

  • Review architecture document for accuracy against the current codebase (especially the existing multichain controller patterns and Snap integration)
  • Verify TypeScript interface definitions are complete and align with Bitcoin domain concepts (UTXO model, address types, derivation paths)
  • Confirm the migration strategy phases are realistic and properly sequenced
  • Check that architecture diagrams accurately reflect the component relationships
  • Verify no production code was modified — this PR is documentation and type definitions only

Notes

  • All TypeScript interfaces use types from existing MetaMask packages (@metamask/utils, @metamask/keyring-api) where applicable
  • The interfaces are designed to be backward-compatible with the current Snap-based Bitcoin support
  • Default address type is P2WPKH (Native SegWit, BIP84) matching existing BtcAccountType.P2wpkh
  • All new code would be feature-gated behind ///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps) consistent with existing multichain controllers

Link to Devin session: https://app.devin.ai/sessions/321806b665844eb2b69a7487852de1b5
Requested by: @dr-phil


Open in Devin Review

Phase 0 deliverables for Bitcoin native support:

- Architecture document (docs/bitcoin-architecture.md) covering:
  - Component diagram showing Bitcoin modules in existing architecture
  - Interface definitions with TypeScript code
  - Data flow diagrams for balance check, send tx, receive, account creation
  - Integration points with existing MetaMask controllers
  - Migration/adoption strategy for gradually enabling Bitcoin support

- TypeScript interface definitions (app/core/Bitcoin/types/):
  - account.ts: UTXO-based account model (BitcoinUtxo, BitcoinBalance, BitcoinAccountData)
  - address.ts: Address types (P2PKH, P2SH, P2WPKH, P2WSH, P2TR)
  - network.ts: Network configuration (mainnet, testnet, signet, regtest)
  - transaction.ts: Transaction model, coin selection, fee rates
  - keyring.ts: BIP44/49/84/86 derivation paths
  - controller.ts: Service contracts (AccountService, TransactionService, NetworkService)

- Architecture diagrams as PNG images:
  - Component architecture diagram
  - Data flow layers diagram
  - Balance check flow diagram
  - Send transaction flow diagram

Co-Authored-By: Phil Bedford <phil.bedford@cognition.ai>
@staging-devin-ai-integration
Copy link
Copy Markdown

Devin Review

Status Commit
⚪ Not started

Open in Devin Review (Staging)

💡 Connect your GitHub account to enable automatic code reviews.

@devin-ai-integration
Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

devin-ai-integration[bot]

This comment was marked as resolved.

- Remove P2WSH from single-key derivation mappings (BIP84 is P2WPKH-only;
  P2WSH uses BIP48 for multisig, which is out of scope for single-key wallets)
- Add 'n' to P2PKH testnet prefix (version byte 0x6f produces both 'm' and 'n')
- Introduce SingleKeyAddressType to enforce P2WSH exclusion at the type level

Co-Authored-By: Phil Bedford <phil.bedford@cognition.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant