rwadurian/backend/mpc-system/services/service-party-android
hailin 71eea98ea5 fix(android): 修复连续创建MPC账户失败的bug
问题描述:
- 用户第一次创建MPC账户成功后返回钱包界面
- 再次创建新的MPC账户时,keygen无法自动开始
- 原因是第一次keygen完成后错误地取消了全局会话事件订阅

根本原因分析:
1. startKeygenAsInitiator() 完成时调用了 sessionEventJob?.cancel()
2. sessionEventJob 是在 registerParty() 时启动的全局事件订阅
3. 取消后,新创建的keygen会话无法接收 session_started 事件
4. 导致keygen无法自动触发

对比发现:
- Sign流程在开始前会调用 ensureSessionEventSubscriptionActive() 检查订阅状态
- Keygen流程没有这个检查,存在不一致性

修复方案:
1. 删除 startKeygenAsInitiator() 中的 sessionEventJob?.cancel()
   - 全局订阅不应该在单次操作完成后取消
   - 只在 cancelSession() 和断开连接时才取消

2. 在 createKeygenSession() 开头添加 ensureSessionEventSubscriptionActive()
   - 与sign流程保持一致
   - 即使有其他代码意外取消订阅,也能自我恢复

影响范围:
- TssRepository.kt: startKeygenAsInitiator(), createKeygenSession()

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 08:03:28 -08:00
..
app fix(android): 修复连续创建MPC账户失败的bug 2026-01-27 08:03:28 -08:00
contracts feat(blockchain): 切换到dUSDT(绿积分)合约 - KAVA主网 2026-01-02 04:31:11 -08:00
gradle/wrapper feat(android): add Android TSS Party app with full API implementation 2025-12-31 23:27:29 -08:00
tsslib feat(tss): add real-time round progress from msg.Type() parsing 2026-01-01 22:41:51 -08:00
.gitignore feat(android): strengthen gRPC connection reliability 2026-01-01 06:44:42 -08:00
IMPLEMENTATION_PLAN.md feat(android): 实现 2-of-3 钱包服务器备份参与签名功能 2026-01-26 17:32:36 -08:00
README.md feat(android): add Android TSS Party app with full API implementation 2025-12-31 23:27:29 -08:00
build-apk.bat fix(android): simplify build-apk.bat with official gomobile setup 2026-01-01 00:53:04 -08:00
build-install-debug.bat fix(android): 修复批处理文件中文乱码问题 2026-01-26 23:53:25 -08:00
build.gradle.kts feat(android): add Android TSS Party app with full API implementation 2025-12-31 23:27:29 -08:00
gradle.properties feat(android): add Android TSS Party app with full API implementation 2025-12-31 23:27:29 -08:00
gradlew feat(android): add Android TSS Party app with full API implementation 2025-12-31 23:27:29 -08:00
gradlew.bat feat(android): add Android TSS Party app with full API implementation 2025-12-31 23:27:29 -08:00
settings.gradle.kts feat(android): add Android TSS Party app with full API implementation 2025-12-31 23:27:29 -08:00

README.md

TSS Party Android

Android 版本的 TSS (Threshold Signature Scheme) Party 应用,用于多方共管钱包的密钥生成和签名。

项目结构

service-party-android/
├── app/                          # Android 应用模块
│   ├── src/main/
│   │   ├── java/com/durian/tssparty/
│   │   │   ├── data/             # 数据层
│   │   │   │   ├── local/        # 本地存储 (Room, TSS Bridge)
│   │   │   │   ├── remote/       # 远程通信 (gRPC)
│   │   │   │   └── repository/   # 数据仓库
│   │   │   ├── domain/model/     # 领域模型
│   │   │   ├── presentation/     # UI 层
│   │   │   │   ├── screens/      # Compose 屏幕
│   │   │   │   └── viewmodel/    # ViewModels
│   │   │   ├── di/               # Hilt 依赖注入
│   │   │   ├── ui/theme/         # Material Theme
│   │   │   └── util/             # 工具类
│   │   ├── proto/                # gRPC Proto 文件
│   │   └── res/                  # Android 资源
│   └── libs/                     # TSS 原生库 (.aar)
├── tsslib/                       # Go TSS 库源码
│   ├── tsslib.go                 # gomobile 绑定
│   ├── go.mod
│   ├── build.sh                  # Linux/macOS 构建脚本
│   └── build.bat                 # Windows 构建脚本
└── gradle/                       # Gradle Wrapper

技术栈

  • UI: Jetpack Compose + Material 3
  • 架构: MVVM + Repository Pattern
  • 依赖注入: Hilt
  • 数据库: Room
  • 网络: gRPC (protobuf-lite)
  • TSS 核心: Go + gomobile (BnB Chain tss-lib v2)

构建步骤

1. 构建 TSS 原生库 (可选,需要 Go 环境)

# 安装 gomobile
go install golang.org/x/mobile/cmd/gomobile@latest
gomobile init

# 构建 Android AAR
cd tsslib
./build.sh  # Linux/macOS
# 或
build.bat   # Windows

这将在 app/libs/ 生成 tsslib.aar

注意: 当前版本使用 Kotlin stub 实现,无需编译 Go 库即可构建 APK。 实际运行需要真正的 tsslib.aar

2. 构建 APK

# Debug 版本
./gradlew assembleDebug

# Release 版本 (需要签名配置)
./gradlew assembleRelease

APK 输出路径: app/build/outputs/apk/debug/app-debug.apk

功能

  1. 加入 Keygen 会话 - 扫描/输入邀请码,参与多方密钥生成
  2. 查看钱包 - 显示已创建的共管钱包列表
  3. 签名交易 - 使用密钥份额参与多方签名
  4. 设置 - 配置 Message Router 服务器地址

配置

默认服务器配置:

  • Message Router: localhost:50051
  • Kava RPC: https://evm.kava.io

与 Electron 版本的对应关系

Electron 版本 Android 版本
electron/main.ts TssNativeBridge.kt + GrpcClient.kt
electron/preload.ts TssRepository.kt
src/pages/*.tsx presentation/screens/*.kt
tss-party/ (Go 子进程) tsslib/ (gomobile .aar)
sql.js Room Database

许可证

MIT