Overview
The@subwallet/extension-base package is the foundational package of the SubWallet Extension, providing core functionality, utilities, and services used throughout the extension. It serves as the backbone for blockchain interactions, state management, and business logic.
Purpose and Responsibilities
- Background Services: Implements all major background services for wallet operations
- Chain Interactions: Provides APIs for interacting with Substrate, EVM, Cardano, Bitcoin, and TON networks
- State Management: Manages application state and subscriptions using Redux Toolkit
- Transaction Handling: Handles signing, validation, and submission of transactions
- Account Management: Manages keyring operations and account derivation
- Balance & Asset Tracking: Tracks balances, NFTs, and token prices across chains
- Staking & Earning: Implements staking, nomination pools, and earning mechanisms
- WalletConnect Integration: Manages WalletConnect sessions and requests
Key Exports
The package primarily exports throughsrc/bundle.ts:
Directory Structure
Major Services
Balance Service
Tracks account balances across all supported chains and handles multi-asset balance queries.Chain Service
Manages chain connections, API instances, and network status. Handles Substrate, EVM, and other chain types.Earning Service
Implements staking, nomination pools, liquid staking, and other earning mechanisms across different chains.History Service
Tracks transaction history and provides historical data for user operations.Keyring Service
Manages account creation, derivation, import/export, and keyring operations.Transaction Service
Handles transaction creation, signing, validation, and submission across different chain types.WalletConnect Service
Manages WalletConnect v2 sessions, request handling, and dApp connections.Price Service
Fetches and caches token prices from various sources like CoinGecko.NFT Service
Tracks NFT ownership and metadata across supported chains.Dependencies
Key dependencies include:- Polkadot.js Stack:
@polkadot/api,@polkadot/util,@polkadot/util-crypto - Ethereum:
ethers,web3,@ethereumjs/tx - State Management:
@reduxjs/toolkit,redux - Storage:
dexie(IndexedDB wrapper) - Blockchain SDKs:
@ton/ton,@emurgo/cardano-serialization-lib-nodejs,bitcoinjs-lib - WalletConnect:
@walletconnect/sign-client - Other Extensions:
@subwallet/extension-chains,@subwallet/extension-inject,@subwallet/extension-dapp
Integration in Architecture
extension-base is consumed by:
- extension-koni-ui: Uses services and types for UI state management
- Background scripts: Instantiates services and handles message passing
- Content scripts: Uses types and utilities for dApp communication
Usage Example
Related Packages
- extension-chains - Chain metadata and definitions
- extension-inject - Injection types and interfaces
- extension-koni-ui - UI components and views
- extension-dapp - dApp integration utilities