Skip to content

Conversation

@Gaubee
Copy link
Contributor

@Gaubee Gaubee commented Dec 27, 2025

概述

搭建 Bio 小程序生态系统的完整架构,包含真实签名服务集成

  • pnpm workspace: Monorepo 结构支持 SDK 和小程序
  • @aspect-aspect/bio-sdk: 客户端 SDK,提供 window.bio 接口
  • Host Provider: PostMessage 通信桥和方法处理器
  • 权限系统: 敏感方法自动请求用户授权
  • 真实签名集成: 使用 SignatureAuthService 执行真实 Ed25519 签名
  • UI 集成: 生态 Tab、小程序容器、对话框组件
  • 可信源管理: 订阅源添加/删除/启用/禁用
  • 内置小程序: 一键传送、锻造
  • 完整测试: 子项目单元测试 + E2E 测试

用户故事流程

1. 用户打开生态 Tab → 查看小程序列表
2. 用户点击小程序 → 进入 MiniappActivity
3. 小程序调用 bio_requestAccounts → 账户选择器弹出
4. 用户选择账户 → 返回账户信息
5. 小程序调用 bio_signMessage → 签名确认对话框弹出
6. 用户点击签名 → 钱包锁输入界面
7. 用户输入图案密码 → SignatureAuthService 执行真实签名
8. 签名返回给小程序 ✅

完成的 Phases

Phase 内容 状态
1 基础设施 (Monorepo, SDK, 小程序骨架)
2 Host Provider (Bridge, Handlers, Registry)
3 UI 集成 (EcosystemTab, MiniappActivity)
4 UI 对话框 (AccountPicker, SigningConfirm, PermissionRequest)
5 权限与架构 (EcosystemStore, permissions, HandlerContext)
6 功能完善 (MiniappTransferConfirmJob, SettingsSourcesActivity)
7 测试基础设施 (子项目 vitest + 单元测试)
8 真实签名集成 (SignatureAuthService)
9 E2E 测试

签名流程

// SigningConfirmJob.tsx
1. 用户点击签名  setWalletLockConfirmCallback()
2. 打开 WalletLockConfirmJob
3. 用户输入密码  回调执行
4. const signature = await authService.handleMessageSign(payload, encryptedSecret, password)
5. BioForest 链: 真实 Ed25519 签名
   其他链: 确定性 mock 签名
6. CustomEvent('signing-confirm', { signature })  返回小程序

测试覆盖

类型 文件 测试数量
SDK bio-sdk/src/*.test.ts 18
Miniapps teleport/forge App.test.tsx 13
Host services/ecosystem/*.test.ts 11
E2E ecosystem-miniapp.mock.spec.ts 8

CI 状态

  • ✅ ci-fast 通过
  • ✅ checks-fast 通过
  • ✅ checks 通过

待后续 PR

  • 交易广播到链上(目前只返回签名)
  • 小程序后端 API 集成
  • Transport 抽象层 (DWEB 准备)

@Gaubee Gaubee mentioned this pull request Dec 27, 2025
21 tasks
- Add pnpm-workspace.yaml for monorepo structure
- Create @aspect-aspect/bio-sdk package with EIP-1193 style API
- Create miniapps/teleport (一键传送) demo app
- Create miniapps/forge (锻造) demo app
- Add ecosystem.json subscription manifest
- Add whitebook documentation (10-生态篇)
- Configure build scripts for SDK and miniapps
Phase 2: Host Provider
- Add PostMessage bridge for iframe communication
- Implement wallet handlers (requestAccounts, selectAccount, pickWallet)
- Implement signing handlers (signMessage, signTypedData)
- Implement transfer handlers (sendTransaction)
- Add miniapp registry for subscription management

Phase 3: UI Integration
- Add EcosystemTab with app grid
- Add MiniappActivity and MiniappPage for running miniapps
- Update TabBar with ecosystem tab (3 tabs: wallet, ecosystem, settings)
- Register MiniappActivity route

Testing
- Add unit tests for types, bridge, and registry
- All 1622 tests passing

Documentation
- Add implementation status document
- Update whitebook index with ecosystem chapter
- AccountPickerJob: wallet account selector for miniapps
- SigningConfirmJob: message signing confirmation dialog
- PermissionRequestJob: permission request dialog
- MiniappPage: register handler callbacks for UI integration

Phase 4: Complete UI integration for bio_selectAccount, bio_signMessage
Phase 5: Permission & Architecture

- Add EcosystemStore for permission and source storage
- Add permissions.ts for permission checking
- Integrate permission checking into bridge.ts
- Add HandlerContext for multi-instance callback management
- Refactor handlers to use context-based callbacks
- Update PermissionRequestJob to handle JSON permissions

All 1623 tests passing.
Phase 6: Feature Completion

- Add MiniappTransferConfirmJob for miniapp transfer requests
- Add SettingsSourcesActivity for managing trusted sources
- Add sources management entry in settings page
- Update miniapp.tsx to use new transfer confirm dialog

All 1623 tests passing.
- bio-sdk: vitest config + 18 unit tests (events, types, provider)
- teleport: vitest config + 6 component tests
- forge: vitest config + 7 component tests
- Add window.bio type declarations
- Add turbo.json test:storybook task config
- Update whitebook: Storybook v10 + Vitest integration rationale

All subprojects now have proper test infrastructure:
- vitest.config.ts for test runner
- test-setup.ts for jest-dom matchers
- Unit tests for core logic
- Component tests for React apps
- SigningConfirmJob: use SignatureAuthService.handleMessageSign
- MiniappTransferConfirmJob: use SignatureAuthService.handleTransferSign
- Both dialogs now trigger WalletLockConfirmJob for password verification
- miniapp.tsx: extract chainName from wallet address for signing

The signing flow now:
1. User confirms → WalletLockConfirmJob opens
2. User inputs pattern → Password verified
3. Real Ed25519/mock signature generated based on chain type
4. Signature returned to miniapp via CustomEvent
- Test ecosystem tab visibility
- Test account picker job
- Test signing confirm job
- Test transfer confirm job
- Test trusted sources management

Uses mock configuration for consistent test data.
Screenshots added:
- 01-home-with-ecosystem-tab: Home page with ecosystem tab
- 02-ecosystem-tab-content: Miniapp list (Teleport, Forge)
- 03-account-picker: Single wallet account picker
- 04-signing-confirm: Signing request dialog
- 05-signing-wallet-lock: Pattern lock for signing
- 06-transfer-confirm: Transfer confirmation dialog
- 07-trusted-sources: Trusted sources management
- 08-multi-wallet-picker: Multiple wallets account picker
- 09-ethereum-only-picker: Chain-filtered account picker
- 10-long-message-signing: Long message signing dialog
- 11-large-amount-transfer: Large amount transfer
- 12-small-amount-transfer: Small decimal amount transfer

Bug fix:
- AccountPickerJob: Hide wallets without matching chain address
  instead of showing them as disabled. This prevents confusion
  when filtering by chain.
Port rule: default port + 6000 to avoid vite default port conflicts
- e2e: 11173 (dev)
- e2e:mock: 11174 (mock)

This prevents port conflicts when vite dev server is already running
on default ports 5173/5174.
- AccountPickerJob: use AddressDisplay for wallet addresses
- SigningConfirmJob: use AddressDisplay for signing address
- MiniappTransferConfirmJob: use AddressDisplay for from/to addresses,
  AmountDisplay for transfer amount with proper formatting

Benefits:
- Consistent address truncation across components
- Proper number formatting with thousand separators
- Responsive address display based on container width
- Accessibility improvements (aria labels, copy functionality)
Changed From-To section from horizontal to vertical layout:
- Addresses now have full width for proper truncation
- Single ellipsis in middle (e.g., c7R6wVdP...7CpPn5Mk5Xz3)
- Added copy buttons for both addresses
- Down arrow between from/to for better visual flow
New screenshot tests:
- 13: Permission request dialog (bio_signMessage, bio_sendTransaction)
- 14: Empty wallet state in account picker
- 15: Hex data warning in signing dialog

New interaction tests:
- Cancel signing triggers event with { confirmed: false }
- Cancel transfer triggers event with { confirmed: false }
- Cancel account picker triggers cancel event
- Select account triggers event with address/chain/name
- Transfer confirm page has copyable addresses

Total: 20 tests (12 screenshots + 8 functional)
- Expand MiniappManifest with category, tags, screenshots, publishedAt,
  updatedAt, verified, beta, longDescription, website fields
- Add MiniappCategory type and KNOWN_PERMISSIONS definitions
- Create MiniappDetailActivity for full app metadata display
  - App header with icon, name, verified badge, author, category
  - Long description with Markdown support
  - Screenshots horizontal scroll gallery
  - Permission list with risk level indicators
  - Supported chains display
  - Tags display
  - Developer info section
- Update EcosystemTab with card-based layout
  - Rich app cards with icon, name, description, badges
  - Click card for details, direct open button
- Update ecosystem.json with enhanced sample data
- Add E2E tests for detail page (17 screenshots total)
- Add MiniappInfo interface with name and icon
- Update SigningParams to use app object instead of appName
- Update HandlerCallbacks interfaces to include app info
- Pass appIcon from MiniappPage to all Sheet components:
  - SigningConfirmJob
  - MiniappTransferConfirmJob
  - AccountPickerJob
  - PermissionRequestJob
- Update Sheet headers to display app icon with fallback
- Update E2E tests with appIcon parameter
- Redesign teleport icon: purple portal with arrow and sparkles
- Redesign forge icon: orange flame with anvil
- Add SVG screenshots showing app interfaces:
  - teleport: transfer form and success screens
  - forge: exchange interface
- Update ecosystem.json to use SVG screenshots
- Update E2E screenshots showing app icons in dialogs
- Split globals.css into theme.css (shareable) and globals.css
- Create @keyapp/sdk package with context API (theme, locale, env, a11y)
- Configure miniapps to use tsconfig paths for component sharing
- Add Tailwind CSS 4 support to miniapps with vite-tsconfig-paths
- Pass context params to iframe URL and sync via PostMessage
- Add React hooks for context consumption in miniapps
- Rewrite Teleport and Forge apps using shared @/components/ui
- Add Tailwind CSS styling with theme support
- Add E2E tests for miniapp UI with 16 screenshot tests
- Verify theme sync (light/dark mode, custom primary hue)
- Fix emptyOutDir to preserve icon and screenshots
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants