From c26a24b544f4f2c8acc5a4ea53c0e8d8b72a2701 Mon Sep 17 00:00:00 2001 From: Developer Date: Thu, 4 Dec 2025 06:04:47 -0800 Subject: [PATCH] =?UTF-8?q?fix(mpc-service):=20=E7=A1=AE=E4=BF=9D=20keygen?= =?UTF-8?q?=20=E4=BC=9A=E8=AF=9D=E5=8C=85=E5=90=AB=E5=AE=8C=E6=95=B4?= =?UTF-8?q?=E7=9A=84=E5=8F=82=E4=B8=8E=E8=80=85=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题:account-service 要求 participants 数量必须等于 threshold_n 原因:createKeygenSession 传入的 participants 可能不足 3 个 修复: - 在 createKeygenSession 中自动补全参与者列表 - 对于 2-of-3 配置,确保有 3 个参与者: - user-party (用户端) - server-party-1 (服务端) - server-party-2 (备份) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../external/tss-lib/tss-wrapper.ts | 39 +++++++++++++++++-- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/backend/services/mpc-service/src/infrastructure/external/tss-lib/tss-wrapper.ts b/backend/services/mpc-service/src/infrastructure/external/tss-lib/tss-wrapper.ts index c4d2021c..b08ec25a 100644 --- a/backend/services/mpc-service/src/infrastructure/external/tss-lib/tss-wrapper.ts +++ b/backend/services/mpc-service/src/infrastructure/external/tss-lib/tss-wrapper.ts @@ -255,20 +255,51 @@ export class TSSWrapper implements TSSProtocolDomainService { /** * Create a keygen session via account-service. * This will also notify server-party-1/2/3 to participate. + * + * Note: account-service requires exactly threshold_n participants. + * For a 2-of-3 setup, we need 3 participants: + * - user-party (the user's share, returned to client) + * - server-party-1 (stored on server) + * - server-party-2 (backup, stored on server) */ private async createKeygenSession( participants: TSSParticipant[], threshold: Threshold, ): Promise { + // Build the full participant list for threshold_n parties + // If we have fewer participants, add the default server parties + const allParticipants: Array<{ party_id: string; device_type: string }> = []; + + // Add provided participants + for (const p of participants) { + allParticipants.push({ + party_id: p.partyId, + device_type: 'server', + }); + } + + // Ensure we have exactly threshold_n participants + // Default server party IDs for 2-of-3 setup + const defaultPartyIds = ['user-party', 'server-party-1', 'server-party-2']; + const existingPartyIds = new Set(allParticipants.map(p => p.party_id)); + + for (const partyId of defaultPartyIds) { + if (!existingPartyIds.has(partyId) && allParticipants.length < threshold.n) { + allParticipants.push({ + party_id: partyId, + device_type: partyId === 'user-party' ? 'client' : 'server', + }); + } + } + + this.logger.log(`Creating keygen session with ${allParticipants.length} participants: ${allParticipants.map(p => p.party_id).join(', ')}`); + const response = await this.axiosClient.post( `${this.accountServiceUrl}/api/v1/mpc/keygen`, { threshold_n: threshold.n, threshold_t: threshold.t, - participants: participants.map(p => ({ - party_id: p.partyId, - device_type: 'server', - })), + participants: allParticipants, }, ); return response.data;