Commit Graph

6 Commits

Author SHA1 Message Date
hailin dfc984f536 fix(co-managed): 修复签名时使用错误 keyshare 的关键 bug
## 问题现象
2-of-3 服务器参与签名时 TSS 协议失败:
```
[TSS-SIGN] ERROR: failed to calculate Bob_mid or Bob_mid_wc
```

## 根本原因
服务器使用了错误的 keyshare:
- 签名会话的 keygen_session_id: c1e66501-bf6b-4d75-8c03-ba547ca82e1b
- 服务器实际加载的 keyshare: 01f2eb3b-e038-4806-b474-b131e6bf9d8e (most recent)
- 原因:main.go:449 传递了 KeygenSessionID: uuid.Nil,触发回退逻辑

## 修复内容

### 1. PendingSession 结构体添加 KeygenSessionID 字段 (33行)
```go
type PendingSession struct {
    SessionID       uuid.UUID
    JoinToken       string
    MessageHash     []byte
    KeygenSessionID uuid.UUID // 新增:从 JoinSession 获取的正确 keygen session ID
    ThresholdN      int
    ThresholdT      int
    SelectedParties []string
    CreatedAt       time.Time
}
```

### 2. session_created 阶段保存 keygen_session_id (395-419行)
**修改前**:
```go
_, err := messageRouter.JoinSession(joinCtx, sessionID, partyID, joinToken)
// ... 忽略返回值,后续使用 uuid.Nil
```

**修改后**:
```go
sessionInfo, err := messageRouter.JoinSession(joinCtx, sessionID, partyID, joinToken)
// ... 保存到 pendingSession
pendingSessionCache.Store(event.SessionId, &PendingSession{
    KeygenSessionID: sessionInfo.KeygenSessionID, // 保存正确的 keygen session ID
    // ...
})
```

### 3. session_started 阶段使用正确的 keygen_session_id (439-453行)
**修改前**:
```go
sessionInfo := &use_cases.SessionInfo{
    KeygenSessionID: uuid.Nil, // 错误:触发回退逻辑
}
```

**修改后**:
```go
sessionInfo := &use_cases.SessionInfo{
    KeygenSessionID: pendingSession.KeygenSessionID, // 正确:使用 JoinSession 返回的 ID
}
```

## 日志改进
- session_created: 记录 keygen_session_id (407行)
- session_started: 记录 keygen_session_id (442行)

## 测试计划
1. 重启 server-party-co-managed 服务
2. Android 客户端勾选"包含服务器备份"发起转账
3. 检查服务器日志:应该使用正确的 keygen_session_id,不再有 "Using most recent keyshare" 警告
4. 验证 TSS 签名协议成功完成

## 影响范围
- 仅影响 server-party-co-managed 的 2-of-3 签名功能
- 不影响 keygen 功能
- 不影响其他服务

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-26 19:40:14 -08:00
hailin ad4549e767 feat(co-managed): 支持 2-of-3 服务器参与签名功能
修改内容:
1. participate_signing.go: 添加 ExecuteWithSessionInfo 方法
   - 新增方法供 server-party-co-managed 调用
   - 跳过 JoinSession 步骤(已在 session_created 阶段完成)
   - 将核心逻辑提取到 executeWithSessionInfo 共享方法

2. server-party-co-managed/main.go: 完整实现 co-sign 支持
   - 初始化 participateSigningUC
   - session_created: 移除签名会话拒绝逻辑,添加 2-of-3 安全检查
   - session_started: 根据 messageHash 判断 keygen/sign 并调用对应 use case

功能特性:
-  仅支持 2-of-3 配置的签名会话
-  100% 寄生 server-party 的 use_cases(与 co-keygen 架构一致)
-  不影响现有 server-party 功能
-  完整的两阶段事件处理(session_created + session_started)

安全限制:
- 仅当 threshold_t=2 且 threshold_n=3 时参与签名
- 其他配置(3-of-5, 4-of-7等)会被拒绝

测试:
-  server-party-co-managed 编译成功

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-26 18:53:38 -08:00
hailin 290b5ea766 fix(server-party-co-managed): use session_started event for participants list
session_created event only contains initial co-managed parties,
but session_started event contains ALL participants including
external parties that joined dynamically via invite code.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-30 00:52:28 -08:00
hailin 2164664ca0 feat(server-party): add ExecuteWithSessionInfo for co-managed keygen
Add new ExecuteWithSessionInfo method to ParticipateKeygenUseCase
for server-party-co-managed to skip duplicate JoinSession call.

- server-party-co-managed already calls JoinSession in session_created phase
- ExecuteWithSessionInfo accepts pre-obtained SessionInfo and skips internal JoinSession
- Refactor common execution logic to private executeWithSessionInfo method
- Update server-party-co-managed to use ExecuteWithSessionInfo on session_started

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-30 00:43:09 -08:00
hailin fd6f84ce82 fix(server-party-co-managed): 修复死锁问题 - session_created 时立即 JoinSession
问题:
- 原来在 session_created 时只存储 token,等待 session_started
- 但 session_started 需要所有 N 方都 JoinSession 后才触发
- 这导致死锁:co-managed-party 永远收不到 session_started

修复:
- Phase 1 (session_created): 立即调用 JoinSession + 存储 session 信息
- Phase 2 (session_started): 执行 TSS 协议(超时从此时开始计算)

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-30 00:23:26 -08:00
hailin e114723ab0 feat(mpc-system): add server-party-co-managed for co_managed_keygen sessions
- Create new server-party-co-managed service with two-phase event handling
  - Phase 1 (session_created): Store join token and wait
  - Phase 2 (session_started): Execute TSS protocol (same timing as service-party-app)
- Add PartyRoleCoManagedPersistent role to isolate from normal keygen/sign
- Update docker-compose.yml with 3 co-managed party instances
- Update deploy.sh service lists
- Modify selectPartiesByCompositionForCoManaged to use new role

This ensures co_managed_keygen sessions use dedicated parties that behave
100% compatible with service-party-app, without affecting existing keygen/sign flows.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-29 23:54:45 -08:00