Skip to content

feat: Add Bitcoin development infrastructure (Phase 0 - Team C)#600

Open
devin-ai-integration[bot] wants to merge 3 commits intomainfrom
devin/1777412125-bitcoin-dev-infrastructure
Open

feat: Add Bitcoin development infrastructure (Phase 0 - Team C)#600
devin-ai-integration[bot] wants to merge 3 commits intomainfrom
devin/1777412125-bitcoin-dev-infrastructure

Conversation

@devin-ai-integration
Copy link
Copy Markdown

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

Summary

Sets up development environments and testnet infrastructure for Bitcoin native support development (Phase 0, Team C - Infrastructure).

No existing app functionality is modified — this PR only adds new Bitcoin-specific infrastructure files.

What's included:

Configuration (app/core/Bitcoin/config/)

  • networks.ts — Bitcoin network types, API endpoint definitions (Blockstream + Mempool.space), CAIP-2 chain ID alignment with existing BtcScope, address prefixes (with both m and n P2PKH prefixes for testnet), confirmation thresholds, satoshi constants
  • environment.ts — Environment variable definitions (MM_BITCOIN_API_URL, MM_BITCOIN_NETWORK, etc.) with defaults
  • index.ts — Barrel exports

Development Scripts (scripts/bitcoin/)

  • check-bitcoin-deps.sh — Verify Bitcoin dev dependencies (npm packages, API connectivity, tools)
  • test-bitcoin-api.sh — Test connectivity to Blockstream/Mempool.space testnet+signet APIs
  • generate-test-addresses.sh — Generate well-known BIP-84/86 test vector addresses
  • request-testnet-btc.sh — Helper to request testnet/signet BTC from faucets (with network-aware monitor URLs)

Testing Infrastructure (app/core/Bitcoin/__tests__/)

  • Mock API responses for both Blockstream Esplora and Mempool.space formats
  • Mock UTXOs (single, multiple, empty, dust scenarios)
  • Mock transactions (confirmed + unconfirmed, full Esplora format)
  • Test address fixtures (testnet, signet, regtest - bech32, nested segwit, legacy)
  • Helper utilities: UTXO factories, BTC/satoshi conversion, mock response builders
  • Unit tests for all configuration and test utilities

Documentation (docs/)

  • bitcoin-dev-setup.md — Prerequisites, quick start, env config, API endpoints, testnet wallet setup, architecture overview, troubleshooting
  • bitcoin-testing-guide.md — Unit testing patterns, fixture docs, mock data factories, conventions

Design decisions:

  • Uses public APIs (Blockstream + Mempool.space) — no full Bitcoin node required
  • Aligns with existing @metamask/keyring-api BtcScope and multichain patterns in app/core/Multichain/
  • Follows existing test patterns (__tests__/fixtures/, __tests__/helpers/)
  • Cross-platform shell scripts (macOS + Linux)
  • Signet recommended over testnet for new development (more reliable)

Review & Testing Checklist for Human

  • Verify the Bitcoin config constants align with your team's intended network support (testnet vs signet as default)
  • Review docs/bitcoin-dev-setup.md for accuracy against your local dev environment
  • Run ./scripts/bitcoin/check-bitcoin-deps.sh to confirm dependency checks work on your machine
  • Run ./scripts/bitcoin/test-bitcoin-api.sh testnet to verify API connectivity
  • Once node_modules are available, run yarn test app/core/Bitcoin/__tests__/ to verify all unit tests pass

Notes

  • All CI failures are caused by a pre-existing repo issue: yarn install fails because react-native-tcp GitHub tarball returns HTTP 404 (https://codeload.github.com/aprock/react-native-tcp/tar.gz/98fbc801f0586297f16730b2f4c75eef15dfabcd). This is not introduced by this PR — no yarn.lock or package.json modifications were made. This affects all CI jobs requiring node_modules (lint, unit tests, depcheck, etc.)
  • All new TypeScript files have been validated with tsc --noResolve --skipLibCheck (full type checking requires node_modules)
  • Addressed both Devin Review findings: fixed signet monitor URL (Blockstream doesn't support signet) and incomplete testnet P2PKH prefix (m/n both valid)

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


Open in Devin Review

Add development environments and testnet infrastructure for Bitcoin
native support development. This includes:

Configuration:
- Bitcoin network configuration (testnet, signet, regtest)
- API endpoint definitions for Blockstream and Mempool.space
- Environment variable definitions and defaults
- CAIP-2 chain ID alignment with existing multichain framework

Development Scripts:
- check-bitcoin-deps.sh: Verify Bitcoin dev dependencies
- test-bitcoin-api.sh: Test Bitcoin API connectivity
- generate-test-addresses.sh: Generate test address fixtures
- request-testnet-btc.sh: Helper for testnet faucets

Testing Infrastructure:
- Mock Bitcoin RPC/API responses (Blockstream + Mempool.space)
- Mock UTXOs (single, multiple, empty, dust scenarios)
- Mock transactions (confirmed + unconfirmed)
- Test address fixtures (testnet, signet, regtest)
- Helper utilities (UTXO factories, conversion functions)
- Unit tests for config and test utilities

Documentation:
- bitcoin-dev-setup.md: Setup guide, env config, architecture
- bitcoin-testing-guide.md: Testing patterns and conventions

No existing app functionality is modified.

Co-Authored-By: Phil Bedford <phil.bedford@cognition.ai>
@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

@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[bot]

This comment was marked as resolved.

- Fix signet monitor URL: use mempool.space instead of non-existent
  Blockstream signet endpoint in request-testnet-btc.sh
- Fix testnet P2PKH prefix: both 'm' and 'n' are valid encodings of
  version byte 0x6F; changed p2pkh to array for testnet/signet/regtest
- Update isValidAddressFormat to handle array prefixes

Co-Authored-By: Phil Bedford <phil.bedford@cognition.ai>
devin-ai-integration[bot]

This comment was marked as resolved.

Change 'testnet3' to 'testnet' for consistency with BITCOIN_ENV_DEFAULTS
and user-facing convention. All other network type values (signet, regtest)
already matched between the enum and environment defaults.

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