服务层完整索引
Source: src/services/
概览
服务层包含 35 个服务目录,160+ 个源文件,是整个应用的核心业务逻辑层。
服务分类
🔐 钱包核心 (Wallet Core)
| 服务 | 目录 | 文件数 | 职责 |
|---|---|---|---|
| wallet-storage | wallet-storage/ | 4 | 钱包加密存储 (IndexedDB + AES) |
⛓️ 链适配器 (Chain Adapter)
| 服务 | 目录 | 文件数 | 职责 |
|---|---|---|---|
| chain-config | chain-config/ | 6 | 链配置管理 |
| chain-adapter | chain-adapter/ | 20+ | 多链统一接口 |
| chain-adapter/evm | chain-adapter/evm/ | 7 | EVM 链实现 (ETH/BSC/Polygon) |
| chain-adapter/bitcoin | chain-adapter/bitcoin/ | 7 | BTC UTXO 实现 |
| chain-adapter/tron | chain-adapter/tron/ | 7 | TVM 实现 (TRX/TRC20) |
| chain-adapter/bioforest | chain-adapter/bioforest/ | 9 | 生物链林实现 |
| chain-adapter/providers | chain-adapter/providers/ | 12 | API Provider 实现 |
🖥️ 小程序运行时 (MiniApp Runtime)
| 服务 | 目录 | 文件数 | 职责 |
|---|---|---|---|
| miniapp-runtime | miniapp-runtime/ | 8 | 小程序生命周期/动画 |
| ecosystem | ecosystem/ | 10 | 应用市场/PostMessage Bridge |
| authorize | authorize/ | 4 | DApp 授权管理 |
📱 平台服务 (Platform Services)
| 服务 | 目录 | 文件数 | 职责 |
|---|---|---|---|
| 平台服务索引 | - | - | 平台服务总览 |
| biometric | biometric/ | 4 | 生物识别 (Face ID/指纹) |
| camera | camera/ | 4 | 相机/二维码扫描 |
| haptics | haptics/ | 4 | 触觉反馈 |
| clipboard | clipboard/ | 1 | 剪贴板 |
| toast | toast/ | 4 | Toast 通知 |
| secure-storage | storage/ | 4 | 安全存储 |
💱 金融服务 (Financial Services)
| 服务 | 目录 | 文件数 | 职责 |
|---|---|---|---|
| currency-exchange | currency-exchange/ | 3 | 法币汇率 |
| staking | staking/ | 4 | 质押服务 |
| transaction | transaction/ | 4 | 交易服务抽象 |
🔧 基础设施 (Infrastructure)
| 服务 | 目录 | 文件数 | 职责 |
|---|---|---|---|
| bioforest-sdk | bioforest-sdk/ | 2 | BioForest SDK 类型 |
| bioforest-api | bioforest-api/ | 2 | BioForest API 客户端 |
| migration | migration/ | 1 | 数据迁移 |
服务依赖图
┌─────────────────────────────────────────────────────────────────────────┐
│ Application Layer │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐│
│ │ Stackflow │ │ Stores │ │ Queries │ │ Components ││
│ │ (Pages) │ │ (State) │ │ (Data) │ │ (UI) ││
│ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ └──────────┬──────────┘│
└─────────┼───────────────┼───────────────┼───────────────────┼───────────┘
│ │ │ │
▼ ▼ ▼ ▼
┌─────────────────────────────────────────────────────────────────────────┐
│ Service Layer │
│ │
│ ┌───────────────────────────────────────────────────────────────────┐ │
│ │ Core Services │ │
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────────────┐│ │
│ │ │wallet-storage│ │chain-config │ │ miniapp-runtime ││ │
│ │ │(加密存储) │ │(链配置) │ │ (小程序运行时) ││ │
│ │ └──────┬──────┘ └──────┬──────┘ └─────────────┬───────────────┘│ │
│ └─────────┼───────────────┼───────────────────────┼─────────────────┘ │
│ │ │ │ │
│ ┌─────────▼───────────────▼───────────────────────▼─────────────────┐ │
│ │ Chain Adapter Layer │ │
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────────┐ │ │
│ │ │ EVM │ │ Bitcoin │ │ Tron │ │BioForest│ │ Providers │ │ │
│ │ │Adapter │ │ Adapter │ │ Adapter │ │ Adapter │ │ (API层) │ │ │
│ │ └────┬────┘ └────┬────┘ └────┬────┘ └────┬────┘ └──────┬──────┘ │ │
│ └───────┼──────────┼──────────┼──────────┼───────────────┼────────┘ │
│ │ │ │ │ │ │
│ ┌───────▼──────────▼──────────▼──────────▼───────────────▼────────┐ │
│ │ Platform Services │ │
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────────┐│ │
│ │ │biometric│ │ camera │ │ haptics │ │ storage │ │ toast ││ │
│ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────────┘│ │
│ └──────────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────────────┐
│ External APIs │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐│
│ │ Etherscan │ │ BlockCypher │ │ TronGrid │ │ BioForest API ││
│ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────────────┘│
└─────────────────────────────────────────────────────────────────────────┘平台适配模式
每个平台服务都遵循统一的多平台适配模式:
service/
├── types.ts # 接口定义
├── mock.ts # Mock 实现 (开发/测试)
├── web.ts # Web 实现
├── dweb.ts # DWeb/原生实现
└── index.ts # 平台检测 + 导出typescript
// index.ts 典型实现
import { isDweb } from '@aspect/detect';
import { mockImpl } from './mock';
import { webImpl } from './web';
import { dwebImpl } from './dweb';
export const service = isDweb() ? dwebImpl : (import.meta.env.DEV ? mockImpl : webImpl);文件总览
src/services/
├── authorize/ # DApp 授权
│ ├── deep-link.ts
│ ├── mock.ts
│ ├── plaoc-adapter.ts
│ └── __tests__/
├── biometric/ # 生物识别
│ ├── types.ts
│ ├── mock.ts
│ ├── web.ts
│ └── dweb.ts
├── bioforest-api/ # BioForest API
│ ├── types.ts
│ └── client.ts
├── bioforest-sdk/ # BioForest SDK
│ ├── types.d.ts
│ └── bioforest-chain-bundle.d.ts
├── camera/ # 相机服务
│ ├── types.ts
│ ├── mock.ts
│ ├── web.ts
│ └── dweb.ts
├── chain-adapter/ # 链适配器
│ ├── types.ts
│ ├── registry.ts
│ ├── derive-wallet-chain-addresses.ts
│ ├── index.ts
│ ├── bioforest/ # BioForest 实现
│ ├── bitcoin/ # Bitcoin 实现
│ ├── evm/ # EVM 实现
│ ├── tron/ # Tron 实现
│ ├── providers/ # API Providers
│ └── __tests__/
├── chain-config/ # 链配置
│ ├── types.ts
│ ├── schema.ts
│ ├── storage.ts
│ ├── subscription.ts
│ ├── service.ts
│ └── __tests__/
├── clipboard/ # 剪贴板
│ └── index.ts
├── currency-exchange/ # 汇率服务
│ ├── types.ts
│ ├── service.ts
│ └── __tests__/
├── ecosystem/ # 生态系统
│ ├── types.ts
│ ├── schema.ts
│ ├── storage.ts
│ ├── permissions.ts
│ ├── bridge.ts
│ ├── scoring.ts
│ ├── registry.ts
│ ├── my-apps.ts
│ ├── provider.ts
│ ├── handlers/
│ └── __tests__/
├── haptics/ # 触觉反馈
│ ├── types.ts
│ ├── mock.ts
│ ├── web.ts
│ └── dweb.ts
├── migration/ # 数据迁移
│ └── mpay-migration.ts
├── miniapp-runtime/ # 小程序运行时
│ ├── types.ts
│ ├── index.ts
│ ├── hooks.ts
│ ├── iframe-manager.ts
│ ├── runtime-refs.ts
│ ├── visual-config.ts
│ └── MiniappVisualProvider.tsx
├── mock-devtools/ # Mock 开发工具
│ ├── types.ts
│ ├── define-mock.ts
│ └── components/
├── staking/ # 质押服务
│ ├── types.ts
│ ├── mock.ts
│ ├── web.ts
│ └── dweb.ts
├── storage/ # 存储抽象
│ ├── types.ts
│ ├── mock.ts
│ ├── web.ts
│ └── dweb.ts
├── toast/ # Toast 服务
│ ├── types.ts
│ ├── mock.ts
│ ├── web.ts
│ └── dweb.ts
├── transaction/ # 交易服务
│ ├── types.ts
│ ├── mock.ts
│ ├── web.ts
│ └── dweb.ts
├── wallet/ # 钱包类型
│ └── types.ts
├── wallet-storage/ # 钱包存储
│ ├── types.ts
│ ├── schema.ts
│ ├── service.ts
│ ├── index.ts
│ └── __tests__/
└── types.ts # 共享类型