fix(co-sign): fix threshold_n display and add missing fields in GetSignSessionByInviteCode

- Add threshold_n to GetSignSessionByInviteCodeResponse interface
- Fix main.ts to use result.threshold_n instead of result.parties?.length
- Add message_hash, joined_count, join_token to GetSignSessionByInviteCode response
- Generate join token for sign session lookup

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2025-12-31 01:47:08 -08:00
parent 4d65b8dd83
commit c1e32a8c04
3 changed files with 28 additions and 6 deletions

View File

@ -685,13 +685,14 @@ func (h *CoManagedHTTPHandler) GetSignSessionByInviteCode(c *gin.Context) {
var thresholdN, thresholdT int var thresholdN, thresholdT int
var status string var status string
var expiresAt time.Time var expiresAt time.Time
var messageHash []byte
err := h.db.QueryRowContext(ctx, ` err := h.db.QueryRowContext(ctx, `
SELECT id, COALESCE(wallet_name, ''), COALESCE(keygen_session_id::text, ''), SELECT id, COALESCE(wallet_name, ''), COALESCE(keygen_session_id::text, ''),
threshold_n, threshold_t, status, expires_at threshold_n, threshold_t, status, expires_at, COALESCE(message_hash, '')
FROM mpc_sessions FROM mpc_sessions
WHERE invite_code = $1 AND session_type = 'sign' WHERE invite_code = $1 AND session_type = 'sign'
`, inviteCode).Scan(&sessionID, &walletName, &keygenSessionID, &thresholdN, &thresholdT, &status, &expiresAt) `, inviteCode).Scan(&sessionID, &walletName, &keygenSessionID, &thresholdN, &thresholdT, &status, &expiresAt, &messageHash)
if err != nil { if err != nil {
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
@ -727,28 +728,48 @@ func (h *CoManagedHTTPHandler) GetSignSessionByInviteCode(c *gin.Context) {
"session_id": sessionID, "session_id": sessionID,
"keygen_session_id": keygenSessionID, "keygen_session_id": keygenSessionID,
"wallet_name": walletName, "wallet_name": walletName,
"message_hash": hex.EncodeToString(messageHash),
"threshold_n": thresholdN, "threshold_n": thresholdN,
"threshold_t": thresholdT, "threshold_t": thresholdT,
"status": status, "status": status,
"joined_count": 0,
"expires_at": expiresAt.UnixMilli(), "expires_at": expiresAt.UnixMilli(),
}) })
return return
} }
// Generate join token for this session (wildcard token that allows any party to join)
var joinToken string
if h.jwtService != nil {
sessionUUID, parseErr := uuid.Parse(sessionID)
if parseErr == nil {
token, err := h.jwtService.GenerateJoinToken(sessionUUID, "*", time.Hour) // Wildcard party ID, 1 hour expiry
if err != nil {
logger.Warn("Failed to generate join token for sign session",
zap.String("session_id", sessionID),
zap.Error(err))
} else {
joinToken = token
}
}
}
logger.Info("Found sign session for invite_code", logger.Info("Found sign session for invite_code",
zap.String("invite_code", inviteCode), zap.String("invite_code", inviteCode),
zap.String("session_id", sessionID), zap.String("session_id", sessionID),
zap.String("wallet_name", walletName)) zap.String("wallet_name", walletName),
zap.Bool("has_join_token", joinToken != ""))
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"session_id": sessionID, "session_id": sessionID,
"keygen_session_id": keygenSessionID, "keygen_session_id": keygenSessionID,
"wallet_name": walletName, "wallet_name": walletName,
"message_hash": hex.EncodeToString(messageHash),
"threshold_n": thresholdN, "threshold_n": thresholdN,
"threshold_t": thresholdT, "threshold_t": thresholdT,
"status": statusResp.Status, "status": statusResp.Status,
"completed_parties": statusResp.CompletedParties, "joined_count": statusResp.CompletedParties,
"total_parties": statusResp.TotalParties,
"expires_at": expiresAt.UnixMilli(), "expires_at": expiresAt.UnixMilli(),
"join_token": joinToken,
}) })
} }

View File

@ -1712,7 +1712,7 @@ function setupIpcHandlers() {
messageHash: result.message_hash, messageHash: result.message_hash,
threshold: { threshold: {
t: result.threshold_t, t: result.threshold_t,
n: result.parties?.length || 0, n: result.threshold_n,
}, },
status: result.status, status: result.status,
currentParticipants: result.joined_count || 0, currentParticipants: result.joined_count || 0,

View File

@ -133,6 +133,7 @@ export interface GetSignSessionByInviteCodeResponse {
wallet_name: string; wallet_name: string;
message_hash: string; message_hash: string;
threshold_t: number; threshold_t: number;
threshold_n: number;
status: string; status: string;
invite_code: string; invite_code: string;
expires_at: number; expires_at: number;