How cake-tech/cake_wallet works
Purpose and Entry Points
Cake Wallet is a non-custodial, privacy-oriented, multi-currency Flutter wallet targeting Android, iOS, macOS, Linux, and Windows. The Dart application starts at lib/main.dart, composes dependencies in lib/di.dart, and routes UI through lib/router.dart and lib/routes.dart. Native launchers host Flutter on each platform, including android/app/src/main/java/com/cakewallet/cake_wallet/MainActivity.java, ios/Runner/AppDelegate.swift, and linux/main.cc.
Application Composition and State
The app is organized as Flutter presentation code over MobX-style stores and view models. Shared app/session state, settings, wallet selection, nodes, trades, and authentication live under lib/store/app_store.dart, lib/store/settings_store.dart, and lib/store/wallet_list_store.dart. Screen-facing orchestration is concentrated in lib/view_model/, such as lib/view_model/send/send_view_model.dart and lib/view_model/wallet_creation_vm.dart. Reactive lifecycle hooks connect wallet, node, fiat, and authentication changes in lib/reactions/bootstrap.dart and lib/reactions/on_current_wallet_change.dart.
Wallet Domain Boundary
cw_core defines chain-agnostic wallet contracts and persistent/domain types: wallet lifecycle, credentials, balances, addresses, transactions, nodes, proxying, and hardware-wallet abstractions. Key boundary paths are cw_core/lib/wallet_base.dart, cw_core/lib/wallet_service.dart, and cw_core/lib/wallet_info.dart. The main app depends on these abstractions rather than directly coupling most UI flows to chain implementations; wallet creation, restoration, loading, and backup are coordinated through lib/core/wallet_creation_service.dart, lib/core/wallet_loading_service.dart, and lib/core/backup_service_v3.dart.
Chain Implementations and Network Access
Per-chain Dart packages implement the core interfaces and expose chain-specific signing, syncing, address, token, and transaction behavior. Major implementations include Monero (cw_monero/lib/monero_wallet_service.dart, cw_monero/lib/api/wallet_manager.dart), UTXO Bitcoin/Litecoin (cw_bitcoin/lib/bitcoin_wallet_service.dart, cw_bitcoin/lib/electrum_wallet.dart), EVM (cw_evm/lib/evm_chain_wallet_service.dart, cw_evm/lib/clients/evm_chain_client.dart), and Solana/Tron (cw_solana/lib/solana_client.dart, cw_tron/lib/tron_http_provider.dart). Default RPC, Electrum, and node endpoints are bundled as assets, e.g. assets/bitcoin_electrum_server_list.yml, assets/ethereum_server_list.yml, and assets/solana_node_list.yml; users can manage endpoint selection via lib/core/node_switching_service.dart.
User Flows and UI Surfaces
The established UI is screen-oriented under lib/src/screens/, with root/authentication, dashboard, send/receive, wallet onboarding, exchange, and settings flows. Representative controllers are lib/src/screens/root/root.dart, lib/src/screens/send/send_page.dart, and lib/src/screens/new_wallet/new_wallet_page.dart. A parallel newer interface resides in lib/new-ui/, including lib/new-ui/new_dashboard.dart, lib/new-ui/pages/send_page.dart, and lib/new-ui/pages/swap_page.dart. Both surfaces consume the same stores, view models, wallet services, and route infrastructure.
Payments, Swaps, and External Services
Transaction creation flows from UI/view models into the selected wallet implementation and its network client; pending transaction models provide the confirmation/broadcast boundary. Address input is normalized or resolved across DNS/domain and social-address schemes by lib/core/address_resolver/address_resolver_service.dart, lib/core/universal_address_detector.dart, and lib/core/lightning_invoice_service.dart. Third-party integrations are adapter-driven: exchange providers in lib/exchange/provider/exchange_provider.dart, fiat on-ramp providers in lib/buy/buy_provider.dart, Cake Pay APIs in lib/cake_pay/src/services/cake_pay_api.dart, and WalletConnect signing/session support in lib/src/screens/wallet_connect/services/walletkit_service.dart.
Privacy, Native Dependencies, and Delivery
Network privacy is a first-class cross-cutting boundary: core supports SOCKS/proxy and Tor implementations in cw_core/lib/utils/proxy_wrapper.dart and cw_core/lib/utils/tor/torch.dart; app startup/settings expose these controls through lib/view_model/start_tor_view_model.dart. Secure key/PIN operations bridge to platform facilities via cw_core/lib/set_app_secure_native.dart, ios/CakeWallet/decrypt.swift, and macos/CakeWallet/decrypt.swift. Several chains require native libraries/plugins—Monero, MWEB, Zcash, Decred, and Wownero—built through platform scripts such as scripts/android/build_monero_all.sh, scripts/ios/build_zcash.sh, and scripts/linux/build_all.sh. Docker-based Android builds and CI workflows support reproducible packaging (scripts/android/docker/build.sh, .github/workflows/reusable-build.yml).
Main entry points: send_view_model.dart View models · root.dart Established screens · wallet_service.dart Wallet service contract · di.dart Dependency composition
Components 25
Flutter application
- App entry
lib/main.dart - Dependency composition
lib/di.dart - Routes and router
lib/router.dart - Established screens · Root, onboarding, dashboard, send, receive, exchange, and settings.
lib/src/screens/root/root.dart - New UI surface
lib/new-ui/new_dashboard.dart - App stores · Session, settings, wallets, nodes, trades, and authentication state.
lib/store/app_store.dart - View models
lib/view_model/send/send_view_model.dart - Reactive lifecycle
lib/reactions/bootstrap.dart
Wallet domain
- Wallet contracts · Wallet lifecycle, credentials, balances, addresses, transactions, nodes, proxies, and hardware wallets.
cw_core/lib/wallet_base.dart - Wallet service contract
cw_core/lib/wallet_service.dart - Wallet lifecycle services · Creation, restoration, loading, and backup coordination.
lib/core/wallet_creation_service.dart - Address resolution · Normalizes domains, social addresses, and Lightning invoices.
lib/core/address_resolver/address_resolver_service.dart - Node selection
lib/core/node_switching_service.dart
Chain implementations
- Monero wallet
cw_monero/lib/monero_wallet_service.dart - Bitcoin and Litecoin wallets
cw_bitcoin/lib/bitcoin_wallet_service.dart - EVM wallets
cw_evm/lib/evm_chain_wallet_service.dart - Solana and Tron clients
cw_solana/lib/solana_client.dart
External and platform
- Bundled endpoints
assets/bitcoin_electrum_server_list.yml - Provider adapters
lib/exchange/provider/exchange_provider.dart - Cake Pay API
lib/cake_pay/src/services/cake_pay_api.dart - WalletConnect
lib/src/screens/wallet_connect/services/walletkit_service.dart - Tor and proxy
cw_core/lib/utils/proxy_wrapper.dart - Secure native storage · Bridges key and PIN operations to platform facilities.
cw_core/lib/set_app_secure_native.dart - Native chain builds · Builds native dependencies for supported chains.
scripts/android/build_monero_all.sh - Reproducible delivery
scripts/android/docker/build.sh
Connections 29
- App entry → Dependency composition: initializes
- Dependency composition → Routes and router: configures
- Routes and router → Established screens: navigates
- Routes and router → New UI surface: navigates
- Established screens → View models: uses
- New UI surface → View models: uses
- View models → App stores: reads and updates
- Reactive lifecycle → App stores: observes
- Dependency composition → Reactive lifecycle: starts
- App stores → Wallet lifecycle services: coordinates wallets
- View models → Wallet lifecycle services: onboards and loads
- Wallet lifecycle services → Wallet service contract: uses
- Wallet service contract → Wallet contracts: implements domain contract
- Monero wallet → Wallet service contract: implements
- Bitcoin and Litecoin wallets → Wallet service contract: implements
- EVM wallets → Wallet service contract: implements
- Solana and Tron clients → Wallet contracts: uses contracts
- View models → Address resolution: resolves payment input
- View models → Node selection: selects endpoint
- Node selection → Bundled endpoints: loads defaults
- Monero wallet → Tor and proxy: routes through
- Bitcoin and Litecoin wallets → Tor and proxy: routes through
- EVM wallets → Tor and proxy: routes through
- Established screens → Provider adapters: initiates swaps and buys
- Established screens → Cake Pay API: uses
- Established screens → WalletConnect: manages sessions
- Wallet contracts → Secure native storage: secures keys and PINs
- Native chain builds → Monero wallet: builds native dependency
- Reproducible delivery → Native chain builds: packages