fix(co-sign): update participants list from session_started event
- Add logic in handleCoSignStart to update participants from event.selectedParties - Fix initiator immediate trigger to use other_parties + self instead of incomplete participants list - Add debug logging for participant list updates - Ensures all parties have correct participant list before TSS signing starts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
742419c0bf
commit
8193549aba
|
|
@ -821,6 +821,32 @@ async function handleCoSignStart(event: {
|
|||
// 标记签名开始
|
||||
signInProgressSessionId = event.sessionId;
|
||||
|
||||
// 从 event.selectedParties 更新参与者列表(类似 keygen 的 handleSessionStart)
|
||||
// 这确保我们使用的是实际加入会话的参与者,而不是预设的列表
|
||||
if (event.selectedParties && event.selectedParties.length > 0) {
|
||||
const myPartyId = grpcClient?.getPartyId();
|
||||
const updatedParticipants: Array<{ partyId: string; partyIndex: number; name: string }> = [];
|
||||
|
||||
event.selectedParties.forEach((partyId, index) => {
|
||||
// 查找已有的参与者信息
|
||||
const existingParticipant = activeCoSignSession?.participants.find(p => p.partyId === partyId);
|
||||
updatedParticipants.push({
|
||||
partyId: partyId,
|
||||
partyIndex: existingParticipant?.partyIndex ?? (index + 1),
|
||||
name: partyId === myPartyId ? '我' : (existingParticipant?.name || `参与方 ${index + 1}`),
|
||||
});
|
||||
});
|
||||
|
||||
// 按 partyIndex 排序
|
||||
updatedParticipants.sort((a, b) => a.partyIndex - b.partyIndex);
|
||||
|
||||
activeCoSignSession.participants = updatedParticipants;
|
||||
console.log('[CO-SIGN] Updated participants from session_started event:', updatedParticipants.map(p => ({
|
||||
partyId: p.partyId.substring(0, 8),
|
||||
partyIndex: p.partyIndex,
|
||||
})));
|
||||
}
|
||||
|
||||
// 获取 share 数据
|
||||
const share = database?.getShare(activeCoSignSession.shareId, activeCoSignSession.sharePassword);
|
||||
if (!share) {
|
||||
|
|
@ -1625,6 +1651,7 @@ function setupIpcHandlers() {
|
|||
|
||||
if (joinResult?.success) {
|
||||
// 设置活跃的 Co-Sign 会话信息
|
||||
// 注意:这里只初始化发起者自己,其他参与者会在 session_started 事件中从 selectedParties 更新
|
||||
const signParticipants: Array<{ partyId: string; partyIndex: number; name: string }> = [];
|
||||
|
||||
// 添加发起方
|
||||
|
|
@ -1666,8 +1693,13 @@ function setupIpcHandlers() {
|
|||
|
||||
if (sessionStatus === 'in_progress') {
|
||||
debugLog.info('main', 'Session already in_progress, triggering sign immediately');
|
||||
// 从 joinResult.other_parties 获取其他参与者,加上发起者自己
|
||||
// 因为此时 activeCoSignSession.participants 只有发起者自己
|
||||
const otherParties = joinResult.other_parties || [];
|
||||
const selectedParties = [partyId, ...otherParties.map((p: { party_id: string }) => p.party_id)];
|
||||
console.log('[CO-SIGN] Initiator using other_parties + self:', selectedParties.map((id: string) => id.substring(0, 8)));
|
||||
|
||||
setImmediate(async () => {
|
||||
const selectedParties = activeCoSignSession?.participants.map(p => p.partyId) || [];
|
||||
await handleCoSignStart({
|
||||
eventType: 'session_started',
|
||||
sessionId: result.session_id,
|
||||
|
|
@ -1807,8 +1839,11 @@ function setupIpcHandlers() {
|
|||
|
||||
if (sessionStatus === 'in_progress') {
|
||||
debugLog.info('main', 'Session already in_progress, triggering sign immediately');
|
||||
// 使用 activeCoSignSession.participants(已从 other_parties + 自己构建)
|
||||
const selectedParties = activeCoSignSession?.participants.map(p => p.partyId) || [];
|
||||
console.log('[CO-SIGN] Participant using activeCoSignSession.participants:', selectedParties.map((id: string) => id.substring(0, 8)));
|
||||
|
||||
setImmediate(async () => {
|
||||
const selectedParties = activeCoSignSession?.participants.map(p => p.partyId) || [];
|
||||
await handleCoSignStart({
|
||||
eventType: 'session_started',
|
||||
sessionId: params.sessionId,
|
||||
|
|
|
|||
Loading…
Reference in New Issue