Skip to content

服务层完整索引

Source: src/services/

概览

服务层包含 35 个服务目录160+ 个源文件,是整个应用的核心业务逻辑层。


服务分类

🔐 钱包核心 (Wallet Core)

服务目录文件数职责
wallet-storagewallet-storage/4钱包加密存储 (IndexedDB + AES)

⛓️ 链适配器 (Chain Adapter)

服务目录文件数职责
chain-configchain-config/6链配置管理
chain-adapterchain-adapter/20+多链统一接口
chain-adapter/evmchain-adapter/evm/7EVM 链实现 (ETH/BSC/Polygon)
chain-adapter/bitcoinchain-adapter/bitcoin/7BTC UTXO 实现
chain-adapter/tronchain-adapter/tron/7TVM 实现 (TRX/TRC20)
chain-adapter/bioforestchain-adapter/bioforest/9生物链林实现
chain-adapter/providerschain-adapter/providers/12API Provider 实现

🖥️ 小程序运行时 (MiniApp Runtime)

服务目录文件数职责
miniapp-runtimeminiapp-runtime/8小程序生命周期/动画
ecosystemecosystem/10应用市场/PostMessage Bridge
authorizeauthorize/4DApp 授权管理

📱 平台服务 (Platform Services)

服务目录文件数职责
平台服务索引--平台服务总览
biometricbiometric/4生物识别 (Face ID/指纹)
cameracamera/4相机/二维码扫描
hapticshaptics/4触觉反馈
clipboardclipboard/1剪贴板
toasttoast/4Toast 通知
secure-storagestorage/4安全存储

💱 金融服务 (Financial Services)

服务目录文件数职责
currency-exchangecurrency-exchange/3法币汇率
stakingstaking/4质押服务
transactiontransaction/4交易服务抽象

🔧 基础设施 (Infrastructure)

服务目录文件数职责
bioforest-sdkbioforest-sdk/2BioForest SDK 类型
bioforest-apibioforest-api/2BioForest API 客户端
migrationmigration/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             # 共享类型

Released under the MIT License.