From 636a06c241df1d2182231dac734fbc7d08fc8653 Mon Sep 17 00:00:00 2001 From: hailin Date: Sat, 20 Dec 2025 23:11:16 -0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=89=8B=E6=9C=BA=E5=8F=B7=E6=B3=A8?= =?UTF-8?q?=E5=86=8C=E6=97=B6=E8=A7=A6=E5=8F=91=E9=92=B1=E5=8C=85=E7=94=9F?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复问题: - 之前手机号注册只创建账户,不生成钱包 - autoCreateAccount 方法会触发钱包生成,但 register 方法没有 解决方案: - 在 register() 方法中添加 MpcKeygenRequestedEvent 发布 - 与 autoCreateAccount() 保持一致的钱包生成流程 流程: 1. 验证短信验证码和推荐码 2. 创建用户账户并保存到数据库 3. 发布 UserAccountCreatedEvent(推荐关系等) 4. 发布 MpcKeygenRequestedEvent(触发异步钱包生成) 5. 返回 JWT Token 给用户 钱包生成异步流程: - MPC Service 监听 MpcKeygenRequestedEvent - 生成 MPC 密钥对,发布 KeygenCompleted - Blockchain Service 派生区块链地址 - Identity Service 保存钱包地址到数据库 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- .../services/user-application.service.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/backend/services/identity-service/src/application/services/user-application.service.ts b/backend/services/identity-service/src/application/services/user-application.service.ts index 0fc49254..22cb92ed 100644 --- a/backend/services/identity-service/src/application/services/user-application.service.ts +++ b/backend/services/identity-service/src/application/services/user-application.service.ts @@ -512,6 +512,24 @@ export class UserApplicationService { await this.eventPublisher.publishAll(account.domainEvents); account.clearDomainEvents(); + // 发布 MPC Keygen 请求事件 (触发后台生成钱包) + const sessionId = crypto.randomUUID(); + await this.eventPublisher.publish( + new MpcKeygenRequestedEvent({ + sessionId, + userId: account.userId.toString(), + accountSequence: account.accountSequence.value, + username: `user_${account.accountSequence.value}`, + threshold: 2, + totalParties: 3, + requireDelegate: true, + }), + ); + + this.logger.log( + `Account registered: sequence=${accountSequence.value}, phone=${phoneNumber.value}, MPC keygen requested`, + ); + const tokens = await this.tokenService.generateTokenPair({ userId: account.userId.toString(), accountSequence: account.accountSequence.value,