feat(account): add GET /sign/:sessionId endpoint for co-sign session status

🤖 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-30 19:41:05 -08:00
parent b688b0176e
commit cd1d2cf8d2
1 changed files with 57 additions and 0 deletions

View File

@ -60,6 +60,7 @@ func (h *CoManagedHTTPHandler) RegisterRoutes(router *gin.RouterGroup) {
// Sign session routes (new - does not affect existing functionality)
coManaged.POST("/sign", h.CreateSignSession)
coManaged.GET("/sign/:sessionId", h.GetSignSessionStatus)
coManaged.GET("/sign/by-invite-code/:inviteCode", h.GetSignSessionByInviteCode)
}
}
@ -588,6 +589,62 @@ func (h *CoManagedHTTPHandler) CreateSignSession(c *gin.Context) {
})
}
// GetSignSessionStatus handles getting the status of a co-managed sign session
func (h *CoManagedHTTPHandler) GetSignSessionStatus(c *gin.Context) {
sessionID := c.Param("sessionId")
if sessionID == "" {
c.JSON(http.StatusBadRequest, gin.H{"error": "session_id is required"})
return
}
// Validate session ID format
if _, err := uuid.Parse(sessionID); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid session_id format"})
return
}
// Call session coordinator via gRPC
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
resp, err := h.sessionCoordinatorClient.GetSessionStatus(ctx, sessionID)
if err != nil {
logger.Error("Failed to get sign session status", zap.Error(err))
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
result := gin.H{
"session_id": sessionID,
"status": resp.Status,
"session_type": resp.SessionType,
"threshold_t": resp.ThresholdT,
"threshold_n": resp.ThresholdN,
"completed_parties": resp.CompletedParties,
"total_parties": resp.TotalParties,
}
// Add signature if sign completed
if resp.SessionType == "sign" && len(resp.Signature) > 0 {
result["signature"] = hex.EncodeToString(resp.Signature)
}
// Include participants with party_index
if len(resp.Participants) > 0 {
participants := make([]gin.H, len(resp.Participants))
for i, p := range resp.Participants {
participants[i] = gin.H{
"party_id": p.PartyID,
"party_index": p.PartyIndex,
"status": p.Status,
}
}
result["participants"] = participants
}
c.JSON(http.StatusOK, result)
}
// GetSignSessionByInviteCode handles looking up a sign session by its invite code
// This is a completely new endpoint that does not affect existing functionality
func (h *CoManagedHTTPHandler) GetSignSessionByInviteCode(c *gin.Context) {