Commit Graph

17 Commits

Author SHA1 Message Date
hailin 1b48c05aa7 fix(mpc-system): GetSessionStatus 返回实际的 threshold_n 和 threshold_t
问题:
- Message Router 的 GetSessionStatus 把 TotalParties 当作 ThresholdN 返回
- 导致 server-party 收到错误的 threshold_n=2 而不是 3
- TSS 协议无法正确启动(参与者数量验证失败)

修复:
- 在 session_coordinator.proto 添加 threshold_n 和 threshold_t 字段
- Session Coordinator 返回实际的 threshold 值
- Message Router 透传 threshold 值而不是参与者数量

Generated with Claude Code

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-29 11:59:53 -08:00
hailin 9bc48d19a9 fix(mpc-system): 修复 co_managed_keygen 参与者 party_index 映射问题
- 在 proto 中添加 ParticipantStatus 消息和 participants 字段
- session-coordinator 返回参与者详细信息(含 party_index)
- account 服务透传 participants 到 HTTP 响应
- service-party-app 使用服务器返回的 party_index 而非数组索引
- 同时返回 join_tokens map 和 join_token 字符串以兼容两种格式

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-29 09:06:13 -08:00
hailin 1b5bcf3fda fix(co-managed-wallet): 修复向后兼容性问题并完善protobuf定义
## 变更概述
根据用户反馈,将 Session Coordinator 的函数签名改为可选参数模式,
确保新功能 100% 不影响现有的 keygen/sign 功能。

## 主要变更

### 1. Session Coordinator 向后兼容修复
- 保留原有 `ReconstructSession` 函数签名不变
- 新增 `ReconstructSessionOptions` 结构体存放可选参数
- 新增 `ReconstructSessionWithOptions` 函数支持新字段
- 原函数内部调用新函数,传入 nil options

### 2. Protobuf 定义更新
- CreateSessionRequest 新增字段:
  - wallet_name (field 10): 钱包名称
  - invite_code (field 11): 邀请码
- SessionInfo 新增字段:
  - wallet_name (field 8): 钱包名称
  - invite_code (field 9): 邀请码
- session_type 支持 "co_managed_keygen"

### 3. TSS Party 子进程修复
- 修复 tss.NewPartyID 参数类型错误 (big.Int)
- 修复 go.mod 依赖问题 (ed25519 replace)
- 删除未使用的变量

### 4. 清理错误生成的文件
- 删除 api/proto/*.pb.go (错误位置)
- 保留 api/grpc/coordinator/v1/*.pb.go (正确位置)

## 修改的文件

| 文件 | 变更类型 | 说明 |
|------|---------|------|
| mpc_session.go | 修改 | 添加 ReconstructSessionWithOptions |
| session_postgres_repo.go | 修改 | 使用新函数传入 options |
| session_cache_adapter.go | 修改 | 使用新函数传入 options |
| session_coordinator.proto | 修改 | 添加 wallet_name, invite_code 字段 |
| session_coordinator.pb.go | 重新生成 | 包含新 protobuf 字段 |
| tss-party/main.go | 修复 | NewPartyID 参数和未使用变量 |
| tss-party/go.mod | 修复 | ed25519 依赖替换 |

## 向后兼容性保证

- 所有现有代码调用 ReconstructSession 无需任何修改
- 数据库使用 COALESCE 处理 NULL 值
- Protobuf 新字段使用高序号,不影响现有消息解析
- **影响现有功能的风险: 0%**

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 23:33:40 -08:00
hailin ac4d9283dc fix: preserve original PartyIndex from keygen for signing sessions
- Add PartyIndex field to protobuf ParticipantInfo message
- Pass original PartyIndex from account shares to session coordinator
- Use original PartyIndex instead of loop variable when creating participants
- This fixes TSS signing failures when non-consecutive parties are selected
2025-12-06 10:45:05 -08:00
hailin 3d176e1132 feat: complete keygen_session_id implementation for signing sessions
- Regenerate protobuf Go code with KeygenSessionId fields
- Session Coordinator correctly parses, stores, and returns keygen_session_id
- Message Router Client parses keygen_session_id in JoinSession response
- participate_signing.go uses keygen_session_id for precise share lookup
- Database schema already includes keygen_session_id column

This fixes the signing issue where wrong keyshares were loaded for multi-account scenarios.
2025-12-06 08:57:30 -08:00
hailin 382386733d feat: add keygen_session_id to signing session flow
- Add keygen_session_id field to CreateSessionRequest and SessionInfo protobuf
- Modify CreateSigningSessionAuto to accept and pass keygenSessionID
- Update Account Handler to pass account's keygen_session_id when creating signing session
- This enables parties to load the correct keyshare by session ID
2025-12-06 08:39:40 -08:00
hailin 8e683064ed chore: regenerate coordinator proto with party_index field
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-06 00:11:24 -08:00
hailin 78119bc6a4 fix(proto): add party_index to JoinSessionResponse for correct index assignment
The JoinSessionResponse from coordinator was missing party_index field,
causing message router to try finding self's index in OtherParties (which
only contains other parties). This resulted in incorrect party index
assignment leading to "duplicate indexes" error in TSS keygen.

Changes:
- Add party_index field to coordinator's JoinSessionResponse proto
- Coordinator now includes PartyIndex in gRPC response
- Message router uses party_index from coordinator instead of searching

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-06 00:08:47 -08:00
hailin aa74e2b2e2 feat(mpc-system): add signing parties configuration and delegate signing support
- Add signing-config API endpoints (POST/PUT/DELETE/GET) for configuring
  which parties should participate in signing operations
- Add SigningParties field to Account entity with database migration
- Modify CreateSigningSession to use configured parties if set,
  otherwise use all active parties (backward compatible)
- Add delegate party signing support: user provides encrypted share
  at sign time for delegate party to use
- Update protobuf definitions for DelegateUserShare in session events
- Add ShareTypeDelegate to support hybrid custody model

API endpoints:
- POST /accounts/:id/signing-config - Set signing parties (first time)
- PUT /accounts/:id/signing-config - Update signing parties
- DELETE /accounts/:id/signing-config - Clear config (use all parties)
- GET /accounts/:id/signing-config - Get current configuration

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-05 22:47:55 -08:00
hailin 55f5ec49f2 chore(mpc-system): remove duplicate protobuf generated files
Remove redundant .pb.go files from api/proto/ directory.
The actual generated files are in api/grpc/coordinator/v1/ and api/grpc/router/v1/.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-05 20:47:55 -08:00
hailin 135e821386 feat(mpc-system): integrate reliability mechanisms and enable party-driven architecture
- Enable SubscribeSessionEvents for automatic session participation
- Integrate heartbeat mechanism with pending message count
- Add ACK sending after message receipt for reliable delivery
- Add party activity tracking in session coordinator
- Add CountPendingByParty for heartbeat response
- Add retry package with exponential backoff for gRPC clients
- Add memory-based message broker and event publisher adapters
- Add account service integration for keygen completion
- Add party timeout checking background job
- Add notification service stub for future implementation

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-05 20:30:03 -08:00
hailin c52b6aa980 refactor(mpc-system): replace K8s party discovery with Message Router-based discovery
- Add GetRegisteredParties gRPC method to Message Router for party discovery
- Create MessageRouterPartyDiscovery adapter in Session Coordinator
- Remove K8s dependency from Session Coordinator (works in any environment)
- Add party registration to server-party-api on startup
- Fix docker-compose.yml: add MESSAGE_ROUTER_ADDR to session-coordinator

This change implements a fully decentralized party discovery mechanism:
- Parties register themselves to Message Router on startup
- Session Coordinator queries Message Router for available parties
- Works in Docker Compose, K8s, or any deployment environment

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-05 16:37:16 -08:00
hailin c976fd3eb1 feat(mpc-system): implement party-driven architecture with SessionEvent broadcasting
Fully implemented party-driven architecture according to international standards (Fireblocks, ING Bank, ZenGo patterns):

**Architecture Changes:**
- Parties actively connect to Message Router (not passively called by coordinator)
- Session Coordinator publishes SessionEvents when creating sessions
- Parties automatically subscribe and respond to SessionEvents
- PartyID-based routing instead of network addresses

**New Features:**
1. Session Coordinator → Message Router gRPC Client
   - PublishSessionEvent RPC for broadcasting session lifecycle events
   - Automatic event publishing after session creation

2. Message Router SessionEvent Broadcasting
   - SubscribeSessionEvents RPC for party subscriptions
   - PublishSessionEvent RPC for coordinator publishing
   - Targeted broadcasting to selected parties

3. Server-Party Auto-Registration & Subscription
   - RegisterParty on startup with role (persistent/delegate/temporary)
   - SubscribeSessionEvents for automatic session notifications
   - Event handler for automatic MPC participation

**Files Modified:**
- api/proto/message_router.proto: Added SessionEvent messages and RPCs
- services/message-router/adapters/input/grpc/message_grpc_handler.go: PublishSessionEvent handler
- services/session-coordinator/adapters/output/grpc/message_router_client.go: NEW - gRPC client
- services/session-coordinator/application/use_cases/create_session.go: SessionEvent publishing
- services/session-coordinator/cmd/server/main.go: Message Router client initialization
- services/server-party/adapters/output/grpc/message_router_client.go: RegisterParty + SubscribeSessionEvents
- services/server-party/cmd/server/main.go: Party registration and event subscription (commented pending full integration)
- go.mod/go.sum: Updated grpc to v1.77.0

**Technical Details:**
- gRPC streaming for SessionEvent subscriptions
- Non-blocking channel broadcasts prevent slow subscribers from blocking
- PartyRole support (persistent/delegate/temporary)
- Join tokens distributed via SessionEvent

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-05 08:44:05 -08:00
hailin 747e4ae8ef refactor(mpc-system): migrate to party-driven architecture with PartyID-based routing
- Remove Address field from PartyEndpoint (parties connect to router themselves)
- Update K8s Discovery to only manage PartyID and Role labels
- Add Party registration and SessionEvent protobuf definitions
- Implement PartyRegistry and SessionEventBroadcaster domain logic
- Add RegisterParty and SubscribeSessionEvents gRPC handlers
- Prepare infrastructure for party-driven MPC coordination

This is the first phase of migrating from coordinator-driven to party-driven
architecture following international MPC system design patterns.
2025-12-05 08:11:28 -08:00
hailin ac76fd80bc feat(mpc-system): integrate gRPC calls into account-service MPC endpoints
- Update account_handler to use real gRPC calls instead of placeholders
- Add sessionCoordinatorClient field to AccountHTTPHandler
- Modify CreateKeygenSession to call session coordinator via gRPC
- Modify CreateSigningSession to call session coordinator via gRPC
- Modify GetSessionStatus to query real session data via gRPC
- Update main.go to initialize and pass sessionCoordinatorClient
- Remove separate mpc_handler.go (consolidated into account_handler)
- Regenerate protobuf files with gRPC service definitions
- Add proper imports for context, time, and grpc adapter

All MPC endpoints now create real sessions with JWT tokens and
can query actual session status from the session coordinator service.

Tested end-to-end: keygen session creation and status query working.
2025-12-05 02:11:27 -08:00
Developer 79ccdd7116 feat: Complete MPC TSS implementation with t-of-n threshold signing
Major changes:
- Add TSS core library (pkg/tss) with keygen and signing protocols
- Implement gRPC clients for Server Party service
- Add MPC session endpoints to Account service
- Deploy 3 Server Party instances in docker-compose
- Add MarkPartyReady and StartSession to proto definitions
- Complete integration tests for 2-of-3, 3-of-5, 4-of-7 thresholds
- Add comprehensive documentation (architecture, API, testing, deployment)

Test results:
- 2-of-3: PASSED (keygen 93s, signing 80s)
- 3-of-5: PASSED (keygen 198s, signing 120s)
- 4-of-7: PASSED (keygen 221s, signing 150s)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-29 06:57:53 -08:00
Developer 393c0ef04d > 2025-11-29 01:35:10 -08:00