@@ -712,6 +712,11 @@ func (ec *eventConsumer) consumeReshareEvent() error {
712712 ec .handleReshareSessionError (walletID , keyType , msg .NewThreshold , err , "Failed to get session type" , natMsg )
713713 return
714714 }
715+ // Handle CMP reshare separately
716+ if keyType == types .KeyTypeTaurusCmp {
717+ ec .handleCMPReshare (msg , natMsg )
718+ return
719+ }
715720
716721 createSession := func (isNewPeer bool ) (mpc.ReshareSession , error ) {
717722 return ec .node .CreateReshareSession (
@@ -851,6 +856,72 @@ func (ec *eventConsumer) consumeReshareEvent() error {
851856 return err
852857}
853858
859+ // NOTE: In CMP reshare, it just refresh the keyshare of each node but keep the same public key and threshold.
860+ // Therefore, we don't need to create new party sessions for CMP reshare.
861+ func (ec * eventConsumer ) handleCMPReshare (msg types.ResharingMessage , natMsg * nats.Msg ) {
862+ logger .Info ("Starting CMP reshare" , "walletID" , msg .WalletID , "sessionID" , msg .SessionID )
863+
864+ // Create CMP session for reshare
865+ taurusSession , err := ec .node .CreateCMPSession (msg .WalletID , msg .NewThreshold , taurus .ActReshare )
866+ if err != nil {
867+ logger .Error ("Failed to create Taurus CMP reshare session" , err , "walletID" , msg .WalletID )
868+ ec .handleReshareSessionError (msg .WalletID , msg .KeyType , msg .NewThreshold , err , "Failed to create Taurus CMP reshare session" , natMsg )
869+ return
870+ }
871+
872+ // Load the existing key for reshare
873+ if err := taurusSession .LoadKey (msg .WalletID ); err != nil {
874+ logger .Error ("Failed to load key for CMP reshare" , err , "walletID" , msg .WalletID )
875+ ec .handleReshareSessionError (msg .WalletID , msg .KeyType , msg .NewThreshold , err , "Failed to load key for CMP reshare" , natMsg )
876+ return
877+ }
878+
879+ // Create context for reshare
880+ ctx , cancel := context .WithTimeout (context .Background (), 60 * time .Second ) // Longer timeout for reshare
881+ defer cancel ()
882+
883+ // Perform CMP reshare
884+ keyData , err := taurusSession .Reshare (ctx )
885+ if err != nil {
886+ logger .Error ("CMP reshare failed" , err , "walletID" , msg .WalletID , "sessionID" , msg .SessionID )
887+ ec .handleReshareSessionError (msg .WalletID , msg .KeyType , msg .NewThreshold , err , "CMP reshare failed" , natMsg )
888+ return
889+ }
890+
891+ // Create reshare result event
892+ reshareResult := event.ResharingResultEvent {
893+ ResultType : event .ResultTypeSuccess ,
894+ WalletID : msg .WalletID ,
895+ NewThreshold : keyData .Threshold ,
896+ KeyType : msg .KeyType ,
897+ PubKey : keyData .PubKeyBytes ,
898+ }
899+
900+ // Marshal and enqueue the result
901+ reshareResultBytes , err := json .Marshal (reshareResult )
902+ if err != nil {
903+ logger .Error ("Failed to marshal CMP reshare result event" , err , "walletID" , msg .WalletID , "sessionID" , msg .SessionID )
904+ ec .handleReshareSessionError (msg .WalletID , msg .KeyType , msg .NewThreshold , err , "Failed to marshal CMP reshare result" , natMsg )
905+ return
906+ }
907+
908+ // Enqueue the reshare result
909+ key := fmt .Sprintf (mpc .TypeReshareWalletResultFmt , msg .SessionID )
910+ err = ec .reshareResultQueue .Enqueue (key , reshareResultBytes , & messaging.EnqueueOptions {
911+ IdempotententKey : composeReshareIdempotentKey (msg .SessionID , natMsg ),
912+ })
913+ if err != nil {
914+ logger .Error ("Failed to enqueue CMP reshare result event" , err , "walletID" , msg .WalletID , "sessionID" , msg .SessionID )
915+ ec .handleReshareSessionError (msg .WalletID , msg .KeyType , msg .NewThreshold , err , "Failed to enqueue CMP reshare result" , natMsg )
916+ return
917+ }
918+
919+ // Remove this line - don't send reply for reshare messages
920+ // ec.sendReplyToRemoveMsg(natMsg)
921+
922+ logger .Info ("[COMPLETED CMP RESHARE] CMP reshare completed successfully" , "walletID" , msg .WalletID , "sessionID" , msg .SessionID )
923+ }
924+
854925// handleReshareSessionError handles errors that occur during reshare operations
855926func (ec * eventConsumer ) handleReshareSessionError (
856927 walletID string ,
0 commit comments