Commit Graph

247 Commits

Author SHA1 Message Date
hailin 0eea1815ae feat(android): 实现 2-of-3 钱包服务器备份参与签名功能
目的:允许 2-of-3 MPC 用户在丢失一个设备时,使用服务器备份参与签名转出资产
实现方式:纯新增代码,不修改现有逻辑,保持完全向后兼容

详细修改:

1. TssRepository.kt (新增 256 行)
   - 新增 buildSigningParticipantList() 辅助方法 (lines 3715-3743)
     * 根据 includeServerParties 参数决定是否包含服务器方
     * 默认 false,保持现有行为
   - 新增 createSignSessionWithOptions() 方法 (lines 3746-3959)
     * 完整复制 createSignSession 逻辑
     * 使用辅助方法构建参与方列表
     * 支持 includeServerBackup 参数
   - 详细日志标记: [CO-SIGN-OPTIONS]

2. MainViewModel.kt (新增 72 行)
   - 新增 initiateSignSessionWithOptions() 方法 (lines 1387-1467)
     * 调用 repository.createSignSessionWithOptions()
     * 处理签名会话创建和自动加入逻辑
     * 保留原有 initiateSignSession() 方法不变
   - 详细日志标记: [SIGN-OPTIONS]

3. TransferScreen.kt (新增 47 行)
   - 修改 onConfirmTransaction 回调: () -> Unit 改为 (Boolean) -> Unit
   - 在 TransferConfirmScreen 中新增复选框 UI (lines 736-776)
     * 仅在 2-of-3 时显示 (wallet.thresholdT == 2 && wallet.thresholdN == 3)
     * 主文本: "包含服务器备份参与签名"
     * 说明文本: "如果您丢失了一个设备,勾选此项以使用服务器备份完成签名"
   - 传递 checkbox 状态到回调

4. MainActivity.kt (新增 10 行)
   - 更新 onConfirmTransaction 回调接受 Boolean 参数
   - 条件调用:
     * includeServerBackup = true: 调用 initiateSignSessionWithOptions()
     * includeServerBackup = false: 调用 initiateSignSession() (原逻辑)

5. IMPLEMENTATION_PLAN.md (新增文件)
   - 详细记录实施方案、安全限制、测试场景
   - 包含完整的回滚方法

核心设计:

安全限制:
- 仅 2-of-3 配置显示选项
- 其他配置 (3-of-5, 4-of-7 等) 不显示
- 需要用户主动勾选,明确操作意图
- 服务器只有 1 个 key < t=2,无法单独控制钱包

向后兼容:
- 默认行为完全不变 (includeServerBackup = false)
- 不勾选或非 2-of-3 时使用原有方法
- 所有现有方法保持不变,无任何修改

代码特点:
- 所有新增代码都有详细中文注释
- 标注 "【新增】" 或 "新增参数" 便于识别
- 说明目的、安全性、回滚方法
- 详细的调试日志 ([CO-SIGN-OPTIONS], [SIGN-OPTIONS])

测试场景:

1. 2-of-3 正常使用 (不勾选)
   - 设备A + 设备B 签名 
   - 服务器被过滤 (现有行为)

2. 2-of-3 设备丢失 (勾选)
   - 设备A + 服务器 签名 
   - 用户明确勾选 "包含服务器备份"

3. 3-of-5 配置
   - 不显示复选框 
   - 保持现有行为

回滚方法:

按以下顺序删除新增代码即可完全回滚:
1. MainActivity.kt: lines 365-377 恢复为简单调用
2. TransferScreen.kt: 删除 checkbox UI (lines 736-776) 和参数修改
3. MainViewModel.kt: lines 1387-1467 删除新方法
4. TssRepository.kt: lines 3715-3960 删除新方法和辅助方法
5. 删除 IMPLEMENTATION_PLAN.md

编译状态:
 Kotlin 编译通过 (BUILD SUCCESSFUL in 1m 8s)
 无编译错误
 待运行时测试验证服务器 party ID 格式和在线状态

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-26 17:32:36 -08:00
hailin 0b22928d9a fix(android): 添加交易记录保存的错误处理
修复问题:
- saveTransactionRecord() 调用没有错误处理,保存失败会静默
- 如果保存失败,交易已广播但没有本地记录

改进:
- 添加 try-catch 捕获保存异常
- 保存失败时提示用户"交易已广播但保存记录失败"
- 添加成功日志便于调试

影响:
- 确保本地发起的交易 100% 被记录或提示失败原因

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-26 09:19:43 -08:00
hailin 656f75a4d1 fix(android): 使用 Kavascan Etherscan API 同步交易记录
替换之前的 BlockScout v2 API(返回404)为 Kavascan 的 Etherscan 兼容 API:
- action=tokentx: 获取 ERC-20 代币交易
- action=txlist: 获取原生 KAVA 交易

优势:
- 一次请求获取所有历史交易,无需分批扫描区块
- 速度快(<5秒 vs 之前的30-45秒)
- API 稳定可靠

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-26 08:51:40 -08:00
hailin d974fddda5 feat(android): 使用 Kavascan BlockScout API 同步交易记录
替换慢速的 eth_getLogs 区块扫描方案为官方推荐的 BlockScout REST API:
- 使用 /api/v2/addresses/{address}/transactions 端点
- 一次性获取所有交易历史(自动分页)
- 支持 ERC-20 代币转账和原生 KAVA 转账
- 从 30-45 秒优化到 < 5 秒
- 解析 token_transfers 字段识别代币类型
- 根据合约地址映射到 GREEN_POINTS/ENERGY_POINTS/FUTURE_POINTS

参考: https://kavascan.com/api-docs
       https://docs.blockscout.com/devs/apis/rest

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-26 08:36:33 -08:00
hailin 144d28238e perf(android): 优化交易记录同步速度
- 减少扫描区块数从 100000 到 20000(只扫描最近约 2 天)
- 并行查询 SENT 和 RECEIVED 交易(提速 2倍)
- 从约 100 秒减少到约 10-15 秒每个代币
- 总同步时间从 5 分钟减少到 30-45 秒

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-26 08:24:36 -08:00
hailin 78e105d46d fix(android): 分批查询交易记录以绕过 RPC 10000 区块限制
RPC 节点限制每次查询最多 10000 个区块,修改为分批查询:
- 每批查询 10000 个区块
- 总共扫描最近 100000 个区块(约 10 批)
- 添加批次日志输出

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-26 08:04:58 -08:00
hailin 6e03c1c798 fix(android): 进一步修复交易记录同步问题
- 将扫描区块数从 50000 增加到 200000(确保覆盖足够长时间)
- 统一地址格式为 lowercase,避免大小写不匹配导致记录无法同步
- 添加详细的交易哈希日志用于调试
- 修复 saveTransactionRecord 和 syncNativeTransactionHistory 中的地址格式问题

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-26 07:55:18 -08:00
hailin a516006117 fix(android): 修复交易记录同步功能
- 修复 fromBlock 使用 "earliest" 导致 RPC 请求超时的问题
- 改为只扫描最近 50000 个区块(约 1-2 个月历史)
- 添加自动获取当前区块号功能
- 进入交易记录页面时自动触发同步
- 添加同步结果提示消息(Snackbar)
- 增加详细的调试日志用于排查问题
- 暂时禁用原生 KAVA 交易同步(KavaScan API 需验证)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-26 07:41:24 -08:00
hailin 3727b0e817 feat(android): 实现交易记录功能
- TssRepository 添加交易记录管理方法 (saveTransactionRecord, updateTransactionStatus, confirmTransaction, getTransactionRecords)
- 添加历史交易同步功能 (syncERC20TransactionHistory, syncNativeTransactionHistory, syncAllTransactionHistory)
- MainViewModel 添加交易记录状态和后台确认轮询
- 新建 TransactionHistoryScreen 交易记录列表界面
- WalletsScreen 添加"记录"按钮入口
- 转账成功后自动保存记录并后台确认状态
- 首次导入钱包时自动同步链上历史交易

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-26 06:55:25 -08:00
hailin 7b3d28c957 feat(android): 添加导出/导入备份功能的详细调试日志
添加日志位置:
- TssRepository: exportShareBackup 和 importShareBackup 函数
- MainViewModel: exportShareBackup 和 importShareBackup 函数
- MainActivity: 文件选择器回调、LaunchedEffect、导出/导入触发点

日志标签:
- [EXPORT] / [IMPORT]: Repository 和 ViewModel 层
- [EXPORT-FILE] / [IMPORT-FILE]: 文件选择器回调
- [EXPORT-EFFECT] / [IMPORT-EFFECT]: LaunchedEffect
- [EXPORT-TRIGGER] / [IMPORT-TRIGGER]: 用户操作触发点

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-26 05:39:56 -08:00
hailin c002640911 fix(android): 修复导出备份后返回启动屏幕的问题
问题原因:
- 当文件选择器 (ActivityResultContracts.CreateDocument) 启动时,
  Android 可能会销毁并重新创建 Activity(配置更改)
- startupComplete、pendingExportJson、pendingExportAddress 使用 remember
  存储状态,在 Activity 重建时会丢失
- startupComplete 重置为 false 导致显示启动检查屏幕

修复方案:
- 将 startupComplete 从 remember 改为 rememberSaveable
- 将 pendingExportJson 和 pendingExportAddress 从 remember 改为 rememberSaveable
- rememberSaveable 会通过 Android 的 savedInstanceState 机制持久化状态

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-26 05:32:43 -08:00
hailin 2799eb5a3a fix(tss-android): 修复备份恢复后钱包无法签名的问题
## 问题根因

备份恢复后的钱包在签名时失败,根本原因是 gRPC 通信使用了**设备的 partyId**,
而不是 **share 的原始 partyId**(keygen 时生成的 partyId)。

这导致:
1. 消息订阅使用错误的 partyId,无法接收其他参与方发送的消息
2. 消息发送使用错误的 fromParty,其他参与方无法正确路由消息
3. Session 事件订阅使用错误的 partyId,无法接收 session_started 等事件
4. API 调用使用错误的 partyId,服务端无法正确识别参与方

## 修改内容

### 1. 添加新的成员变量用于跟踪正确的 partyId
- `currentMessageRoutingPartyId`: 消息路由使用的 partyId
- `currentSessionEventPartyId`: Session 事件订阅使用的 partyId

### 2. 修改 startMessageRouting 方法
- 添加 `routingPartyId` 可选参数
- 签名流程中使用 signingPartyId(share 原始 partyId)
- 消息发送 (routeMessage fromParty) 使用正确的 partyId
- 消息订阅 (subscribeMessages) 使用正确的 partyId

### 3. 修改 startSessionEventSubscription 方法
- 添加 `subscriptionPartyId` 可选参数
- 签名流程中使用 signingPartyId

### 4. 修改 ensureSessionEventSubscriptionActive 方法
- 添加 `signingPartyId` 可选参数
- 支持动态切换订阅的 partyId

### 5. 修复所有签名流程中的调用

#### joinSignSessionViaGrpc 流程:
- grpcClient.joinSession 使用 signingPartyId
- startMessageRouting 使用 signingPartyId
- ensureSessionEventSubscriptionActive 使用 signingPartyId

#### joinSignSessionViaApiAndExecute 流程:
- joinSignSessionViaApi HTTP 请求使用 signingPartyId
- grpcClient.joinSession 使用 signingPartyId
- startMessageRouting 使用 signingPartyId

#### createSignSession 流程:
- ensureSessionEventSubscriptionActive 使用 signingPartyId
- join_tokens 查找使用 originalPartyId
- grpcClient.joinSession 使用 signingPartyId
- startMessageRouting 使用 signingPartyId

#### startSigning 流程:
- startMessageRouting 使用 signingPartyId

### 6. 修复 joinSignSessionViaApi 函数
- 添加 signingPartyId 参数
- HTTP 请求体中的 party_id 和 device_id 使用 signingPartyId

### 7. 修复重连恢复逻辑 (restoreStreamsAfterReconnect)
- startMessageRouting 使用保存的 currentMessageRoutingPartyId
- startSessionEventSubscription 使用保存的 currentSessionEventPartyId

## 测试场景

修复后应支持以下场景:
1. 原设备 keygen → 原设备签名 ✓
2. 原设备 keygen → 备份 → 新设备恢复 → 新设备发起签名 ✓
3. 原设备 keygen → 备份 → 新设备恢复 → 新设备参与签名 ✓

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-26 04:15:52 -08:00
hailin 94d283696f fix(tss): 修复备份恢复后签名失败的问题
问题原因:
- 备份恢复的钱包在签名时使用了当前设备的 partyId,而不是原始 keygen 时的 partyId
- TSS 协议要求签名时使用的 partyId 必须与 keygen 时完全一致

修复内容:
- Android: joinSignSessionViaGrpc() 使用 shareEntity.partyId 而非当前设备 partyId
- Electron: cosign:joinSession 和 cosign:createSession 使用 share.party_id
- Electron: handleCoSignStart() 使用 share.party_id 进行签名
- 所有 gRPC 通信和消息订阅都使用原始 partyId

关键修改点:
- TssRepository.kt: joinSignSessionViaGrpc() 第 1136 行使用 signingPartyId
- main.ts: cosign:joinSession 第 1826 行使用 signingPartyId
- main.ts: cosign:createSession 第 1624-1633 行使用 share.party_id
- main.ts: handleCoSignStart() 第 836 行使用 share.party_id

其他:
- 移除 Android APK 中的 x86_64 ABI (仅用于模拟器)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-20 00:39:05 -08:00
hailin c5db77d23a feat(tss): 添加积分股(eUSDT)和积分值(fUSDT)代币支持
新增功能:
- 添加 ENERGY_POINTS (积分股/eUSDT) 和 FUTURE_POINTS (积分值/fUSDT) 代币类型
- 实现所有 ERC-20 代币的通用余额查询功能
- 支持四种代币的转账功能 (KAVA, dUSDT, eUSDT, fUSDT)
- 更新 UI 显示所有代币余额和代币选择器

代币合约地址 (Kava EVM):
- dUSDT (绿积分): 0xA9F3A35dBa8699c8E681D8db03F0c1A8CEB9D7c3
- eUSDT (积分股): 0x7C3275D808eFbAE90C06C7E3A9AfDdcAa8563931
- fUSDT (积分值): 0x14dc4f7d3E4197438d058C3D156dd9826A161134

技术改进:
- 添加 TokenConfig 工具类统一管理代币配置
- 添加 ERC20Selectors 常量类定义合约方法选择器
- 添加 transaction_records 表用于存储转账历史 (数据库版本升级到 v4)
- 重构余额查询和转账逻辑支持多代币类型
- 所有 ERC-20 代币使用 6 位小数精度

受影响文件:
- Android: Models.kt, TssRepository.kt, TransactionUtils.kt, Database.kt,
          AppModule.kt, TransferScreen.kt, WalletsScreen.kt
- Electron: transaction.ts, Home.tsx

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-19 23:36:58 -08:00
hailin a47b935bce fix(tss-android): 修复备份恢复后无法签名的问题
问题原因:
备份数据中缺少 partyId 字段。恢复到新手机后,签名时使用的是新设备
生成的 partyId,而不是 keygen 时编码到 LocalPartySaveData 中的
原始 partyId,导致 TSS 签名协议无法正确匹配密钥数据而失败。

修复内容:
1. Models.kt:
   - ShareRecord 添加 partyId 字段
   - ShareBackup 添加 partyId 字段,备份格式版本升级到 v2
   - 更新 fromShareRecord() 和 toShareRecord() 方法

2. Database.kt:
   - ShareRecordEntity 添加 party_id 列
   - 数据库版本升级到 3

3. AppModule.kt:
   - 添加 MIGRATION_2_3 数据库迁移脚本

4. TssRepository.kt:
   - 添加 currentSigningPartyId 成员变量跟踪当前签名使用的 partyId
   - keygen 保存时包含 partyId (3处)
   - 备份导入时保存原始 partyId
   - 签名流程使用 shareEntity.partyId 替代设备 partyId (3处)
   - gRPC 调用 (markPartyReady, reportCompletion) 使用原始 partyId

关键点: 签名时必须使用 keygen 时的原始 partyId,因为该 ID 被编码
到了 TSS 密钥数据结构中。现在备份会保存此关键字段,恢复后签名
将使用正确的 partyId。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-19 18:56:27 -08:00
hailin c392142562 feat(blockchain): 切换到dUSDT(绿积分)合约 - KAVA主网
合约信息:
- 地址: 0xA9F3A35dBa8699c8C681D8db03F0c1A8CEB9D7c3
- 名称: Durian USDT (dUSDT)
- 精度: 6位
- 网络: KAVA EVM Mainnet (Chain ID: 2222)
- 链接: https://kavascan.com/address/0xA9F3A35dBa8699c8C681D8db03F0c1A8CEB9D7c3

修改:
- blockchain.config.ts: 更新默认合约地址
- chain-config.service.ts: 更新默认合约地址
- docker-compose.yml: NETWORK_MODE改为mainnet,配置KAVA主网
- .env.example: 更新合约地址和注释
- KAVA_NETWORK.md: 标注dUSDT为当前使用合约

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-02 04:31:11 -08:00
hailin 47e4ef2b33 feat(android): add share export and import functionality
Add ability to backup wallet shares to files and restore from backups:

- Add ShareBackup data class in Models.kt for backup format
- Add exportShareBackup() and importShareBackup() in TssRepository
- Add export/import state and methods in MainViewModel
- Add file picker integration in MainActivity using ActivityResultContracts
- Add import FAB button in WalletsScreen
- Export saves as .tss-backup file with address and timestamp in filename
- Import validates backup format and checks for duplicate wallets

The backup file contains all necessary data to restore a wallet share:
sessionId, publicKey, encryptedShare, threshold, partyIndex, address.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-02 03:35:37 -08:00
hailin 9f33e375d0 fix(android): add @OptIn annotation for experimental FilterChip API
Add @OptIn(ExperimentalMaterial3Api::class) to TransferInputScreen
composable to fix compilation error for FilterChip and FilterChipDefaults.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-02 03:06:32 -08:00
hailin 9b9612bd5f feat(token): add Green Points (绿积分) ERC-20 token support
Add support for the dUSDT token "绿积分" (Green Points) on both Android
and Electron applications:

Android changes:
- Add TokenType enum and GreenPointsToken config in Models.kt
- Implement ERC-20 balance fetching and transfer encoding in TssRepository
- Update TransactionUtils with ERC-20 transfer support
- Add dual balance display (KAVA + 绿积分) in WalletsScreen
- Add token type selector in TransferScreen

Electron changes:
- Add TokenType and GREEN_POINTS_TOKEN config in transaction.ts
- Implement fetchGreenPointsBalance and ERC-20 transfer encoding
- Update Home.tsx with dual balance display and token selector
- Add token selector styles in Home.module.css

Token contract: 0xA9F3A35dBa8699c8C681D8db03F0c1A8CEB9D7c3 (Kava mainnet)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-02 03:01:05 -08:00
hailin b3822e48eb fix(android): decode Base64 signature before broadcasting transaction
The TSS native bridge returns signatures in Base64 format, but the
broadcast function expected hex format. Added Base64 decoding in
broadcastTransaction() to properly parse r, s, v components.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 22:44:44 -08:00
hailin 2365a50b1b feat(tss): add real-time round progress from msg.Type() parsing
Extract current round number from tss-lib message type string using
regex pattern `Round(\d+)`. This enables real-time progress updates
(1/4, 2/4... for keygen, 1/9, 2/9... for signing) instead of only
showing completion status.

Changes across all three platforms:
- tss-wasm/main.go: Add extractRoundFromMessageType() and call
  OnProgress with parsed round on each outgoing message
- service-party-android/tsslib/tsslib.go: Same implementation for
  Android gomobile binding
- service-party-app/tss-party/main.go: Same implementation for
  Electron subprocess, with isKeygen parameter to distinguish
  keygen (4 rounds) vs signing (9 rounds)

Safe fallback: Returns 0 if parsing fails, which doesn't affect
protocol execution - only UI display.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 22:41:51 -08:00
hailin f8de55e671 fix(android): reset isLoading after signing completes to enable broadcast button
The broadcast button was disabled because isLoading remained true after
signing completed. Added isLoading = false reset in startSigningProcess
after waitForSignature succeeds or fails.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 22:21:30 -08:00
hailin 001f0ac480 fix(android): remove 0x prefix from messageHash before TSS sign
TSS native library expects pure hex string without 0x prefix.
Fix both startSigning (initiator) and executeSignAsJoiner (joiner) functions.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 22:04:18 -08:00
hailin 0bd764e1d1 fix(android): ensure session event subscription active before creating sign session
Add ensureSessionEventSubscriptionActive() call at the start of createSignSession()
to prevent race condition where session_started event arrives before subscription
is ready. Also add debug logging for _signSessionId and pendingSignInitiatorInfo
in event callback to help diagnose sign initiator event matching issues.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 21:45:18 -08:00
hailin ecd7a2a2dc fix(android): clear pendingSessionId in resetSessionStatus to fix stale session matching
The resetSessionStatus() function was not clearing pendingSessionId,
causing events from new sessions to be ignored because pendingSessionId
still held the old session ID.

Added:
- Clear pendingSessionId = null in resetSessionStatus()
- Clear _currentSession.value = null in resetSessionStatus()
- Added debug logging for session state clearing

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 21:11:24 -08:00
hailin e865153e8e fix(android): refresh session event subscription when joining sign session
The session event gRPC stream may silently disconnect without triggering
onError or onCompleted callbacks. This causes session_started events to
be lost, preventing the sign process from starting.

Changes:
- Add ensureSessionEventSubscriptionActive() to refresh event subscription
- Call it in joinSignSessionViaGrpc for sign joiner
- Call it in createSignSession for sign initiator after auto-join

This ensures a fresh event stream connection before waiting for events.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 20:47:13 -08:00
hailin da76037d04 fix(tss-wasm): correct signing rounds from 6 to 9
GG20 signing protocol has 9 rounds, not 6. This aligns WASM with
Electron (tss-party/main.go:717) and Android (tsslib/tsslib.go:477).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 20:24:47 -08:00
hailin 16e1e9159c fix(android): sign initiator event handling to match Electron flow
Changes:
- Add sign initiator handling for participant_joined events in MainViewModel
- Add sign initiator handling for session_started events in MainViewModel
- Add sign initiator handling for all_joined events in MainViewModel
- Set pendingSessionId in TssRepository.createSignSession for event matching
- Refactor initiateSignSession to wait for session_started instead of starting immediately
- Add PendingSignInitiatorInfo data class to store pending sign info
- Add sessionAlreadyInProgress flag to SignSessionResult for immediate trigger case

This fixes the issue where sign initiator couldn't detect when other parties
joined the signing session, making Android flow 100% consistent with Electron.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 20:14:32 -08:00
hailin fd56de5c00 fix(android): enable real-time progress updates for keygen/sign rounds
Connect TssNativeBridge.progress Flow to UI through:
- Add progressCallback in TssRepository with startProgressCollection/stopProgressCollection
- Subscribe to native bridge progress in keygen and sign methods
- Add setProgressCallback in MainViewModel to update appropriate round state
- Progress now flows: Go Native → TssNativeBridge → TssRepository → MainViewModel → UI

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 19:45:31 -08:00
hailin 3576af0f25 feat(android): add 5-minute countdown timer UI for keygen/sign sessions
Displays remaining time during the 5-minute polling timeout:
- Shows countdown in CreateWalletScreen (SessionScreen)
- Shows countdown in JoinKeygenScreen (JoiningScreen, KeygenProgressScreen)
- Shows countdown in CoSignJoinScreen (JoiningScreen, SigningProgressScreen)
- Format: mm:ss with Timer icon in tertiary container card
- Countdown starts on all_joined event and stops on session start/cancel

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 19:33:20 -08:00
hailin b30017f3a7 fix(android): prevent memory leaks from detached coroutine scopes
Critical fixes to prevent app crashes when screens are kept open for extended periods:

- Add repositoryScope with SupervisorJob for structured concurrency in TssRepository
- Replace detached CoroutineScope(Dispatchers.IO).launch with repositoryScope.launch:
  - Session event subscription (line 206)
  - Session status polling (line 291)
  - Message routing (line 1508)
- Add cleanup() method to properly cancel all jobs and repositoryScope
- Update disconnect() to also cancel sessionStatusPollingJob
- Update MainViewModel.onCleared() to call repository.cleanup()

This ensures all background coroutines are properly cancelled when the ViewModel
is cleared, preventing memory accumulation over time.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 19:05:13 -08:00
hailin fc86af918f feat(android): add 5-minute polling timeout mechanism for keygen/sign
Implements Electron's checkAndTriggerKeygen() polling fallback:
- Adds polling every 2 seconds with 5-minute timeout
- Triggers keygen/sign via synthetic session_started event on in_progress status
- Handles gRPC stream disconnection when app goes to background
- Shows timeout error in UI via existing error mechanism

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 18:51:02 -08:00
hailin ad79679ee2 feat(ui): add QR code display for invite code in signing session
Android TransferScreen:
- Add QR code display above invite code text
- Import QRCodeWriter and related components
- Add generateInviteQRCode helper function
- Update hint text to mention scanning

Electron CoSignSession:
- Import QRCodeSVG from qrcode.react
- Add QR code above invite code text with proper styling
- Center QR code and update hint text

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 18:37:18 -08:00
hailin ed55be2b86 fix(android): transfer flow improvements and message_hash format fix
Transfer Screen improvements:
- Add QR code scanning for recipient address (using zxing library)
- Support EIP-681 URI format (ethereum:0x...) and plain address
- Remove password requirement - TSS wallets don't need passwords
- Remove unused onScanQrCode callback parameter

WalletsScreen changes:
- Simplify onTransfer callback to only pass shareId
- Remove TransferDialog - now navigates directly to TransferScreen
- Remove unused state variables (showTransferDialog, transferWallet)

Bug fix:
- Remove 0x prefix from message_hash before sending to API
- Backend expects pure hex, not 0x-prefixed hex string

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 18:18:29 -08:00
hailin 480251b85f fix(android): remove incorrect Participant import
Participant class is already imported via domain.model.* wildcard import,
no need for separate import from data.repository (where it doesn't exist).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 11:03:31 -08:00
hailin ee1cfe082d fix(android): resolve compilation errors for walletName and Participant
- TssRepository: Use address-based wallet name since ShareRecordEntity
  doesn't have wallet_name field (unlike Electron's ShareRecord)
- MainViewModel: Add missing Participant import and simplify type reference

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 11:00:36 -08:00
hailin 04eeadf7a7 fix(android): co-sign flow consistency with Electron + state reset
Changes:
- Fix Android state not resetting after successful keygen/join
  - Add resetSessionStatus() method in TssRepository
  - Call reset on success navigation in MainActivity

- Make Android co-sign flow 100% consistent with Electron:
  - Get keygen session status for participants list
  - Filter out co-managed-party-* (server backup parties)
  - Auto-join via gRPC after creating sign session
  - Start message routing BEFORE signing (prepareForSign)
  - Use gRPC response partyIndex instead of local share
  - Use original keygen thresholdN instead of signingParties.size
  - Pass parties list in join sign flow

- Update SignSessionInfoResponse to include parties array
- Update validateSignInviteCode to parse parties from API response

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 10:52:13 -08:00
hailin 7346b3518a fix(electron): auto-navigate to home after keygen completion
Previously, after keygen completed, the Session page would just update the
status to 'completed' but not navigate away. Users had to manually click
the "Return Home" button. This could result in a white screen if the button
wasn't visible or clickable.

Now the page auto-navigates to home after 2 seconds, giving users time to
see the completion status and public key before redirecting.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 10:22:42 -08:00
hailin 549b21f298 fix(message-router): prevent subscription race condition on gRPC reconnect
When a party re-subscribes (e.g., Android reconnects), the old gRPC stream's
defer Unsubscribe() was accidentally removing the NEW subscription from the
subscribers map, causing the party to miss session_started events.

Fix:
- Subscribe() now returns the channel to the caller
- Unsubscribe() now takes the channel and only removes if it matches
- This prevents older streams from removing newer subscriptions

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 10:04:11 -08:00
hailin b7fc488dcf feat(android): add persistent partyId storage matching Electron behavior
- Add AppSettingEntity and AppSettingDao to Database.kt for key-value storage
- Add database migration (version 1 → 2) to create app_settings table
- Modify TssRepository.registerParty() to load/create partyId from database
- PartyId is now persisted across app restarts, matching Electron's getOrCreatePartyId()

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 09:50:30 -08:00
hailin e2451874ea fix(android): add logging for session event subscription debugging
- Add warning log when parties miss session event broadcast (message-router)
- Add logging for subscribeSessionEvents to detect null asyncStub
- Add sessionStatusPollingJob field for future fallback polling mechanism

This helps diagnose why Android parties are not receiving session_started events.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 09:23:38 -08:00
hailin eb3f71fa2e fix(android): fix session_started event race condition with pendingSessionId
Problem:
- Android initiator/joiner could miss session_started events due to race condition
- Events arriving between joinSession() and _currentSession.value assignment were ignored
- This caused keygen timeout because parties never started the TSS protocol

Solution:
- Add pendingSessionId field set BEFORE joinSession() call
- Modify startSessionEventSubscription() to match events against both activeSession and pendingSessionId
- Clear pendingSessionId on session completion, failure, or cancellation

This ensures session_started events are correctly processed even if they arrive
before _currentSession is fully initialized.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 09:09:52 -08:00
hailin cc56b8fadf fix(android): fetch session status after creation to show all participants
- Add getPartyId() method to TssRepository
- Call getSessionStatus after createKeygenSession to fetch all participants
  including server-party-co-managed that have already auto-joined
- This matches Electron's behavior of calling getSessionStatus on session page

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 08:51:49 -08:00
hailin f305a8cd97 feat(session): broadcast participant_joined event via gRPC for real-time UI updates
Backend changes (session-coordinator):
- Add PublishParticipantJoined method to JoinSessionMessageRouterClient interface
- Implement PublishParticipantJoined in MessageRouterClient to broadcast events
- Call PublishParticipantJoined in join_session.go after participant joins
- Add detailed logging for debugging event broadcast

Android changes (service-party-android):
- Add detailed logging in TssRepository for session event handling
- Add detailed logging in MainViewModel for participant_joined processing
- Log activeSession state, event matching, and participant updates

This enables the initiator's waiting screen to receive real-time updates
when participants join the session, matching the expected behavior.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 08:34:47 -08:00
hailin 13d1e58b84 fix(android): change QR scanner to portrait orientation
- Created PortraitCaptureActivity that extends CaptureActivity
- Registered it in AndroidManifest.xml with screenOrientation="portrait"
- Updated JoinKeygenScreen and CoSignJoinScreen to use the portrait activity
- Also simplified keygen join logic to match Electron exactly

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 08:16:41 -08:00
hailin d90c722c7d fix(android): simplify keygen join to match Electron behavior exactly
Removed polling fallback and simplified to match Electron's design:
- If joinSession returns sessionStatus="in_progress", trigger keygen immediately
- Otherwise wait for session_started gRPC event

Added debug log to show sessionStatus value for troubleshooting.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 08:14:26 -08:00
hailin 50cb10d6a8 fix(android): improve session_started polling with multiple attempts
Changed from single 2-second delay to 5 attempts at 500ms intervals.
This provides faster detection while covering a longer window (2.5 seconds total).

The polling loop:
- Checks every 500ms for up to 5 times
- Stops immediately if keygen is already triggered
- Stops if session context changes (user cancelled/navigated away)

This handles the case where the last joiner triggers session_started
but cannot receive the event themselves.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 08:10:15 -08:00
hailin c3d5da46f7 fix(android): add polling fallback for session_started race condition
When multiple Android devices join a keygen session nearly simultaneously,
the last joiner may miss the session_started gRPC event because it's sent
before the device has fully set up its event subscription.

This fix adds a 2-second delayed polling check after join to detect if
the session has already started. If the session is in_progress and we
haven't started keygen yet, trigger it via polling instead of relying
solely on the session_started event.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 08:08:18 -08:00
hailin 136a5ba851 fix(android): change address format from Cosmos to EVM and fix balance query
Changes:
- Change address derivation from deriveKavaAddress to deriveEvmAddress
  in TssRepository.kt (3 locations)
- Add AddressUtils.isEvmAddress() and getEvmAddress() helper methods
  to handle both old Cosmos and new EVM address formats
- Fix balance query for old wallets by deriving EVM address from
  public key when needed (MainViewModel.fetchBalanceForShare)
- Add retry logic for optimistic lock conflicts in join_session.go
  to prevent party_index collision during concurrent joins

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 07:48:52 -08:00
hailin 444b720f8d feat(android): strengthen gRPC connection reliability
Major improvements to Android gRPC client:
- Add automatic reconnection with exponential backoff (1s to 30s)
- Add heartbeat mechanism with failure detection (30s interval, 3 failures trigger reconnect)
- Add stream version tracking to filter stale callbacks
- Add channel state monitoring (every 5s)
- Add per-call deadline instead of one-time deadline for stubs
- Add SharedFlow for connection events (Connected, Disconnected, Reconnecting, Reconnected, PendingMessages)
- Add callback exception handling for robustness
- Add stream recovery after reconnection via callback mechanism

TssRepository changes:
- Save message routing params for recovery after reconnect
- Expose grpcConnectionEvents SharedFlow for UI notifications
- Auto-restore event subscriptions after reconnection

Other changes:
- Add QR code to Electron Create page for mobile scanning
- Auto version increment from version.properties
- SettingsScreen shows BuildConfig version info
- CreateWalletScreen tracks hasEnteredSession state

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 06:44:42 -08:00