|
86 | 86 | Entity: "signer", |
87 | 87 | Action: "generate", |
88 | 88 | }}, |
| 89 | + "/signrpc.Signer/MuSig2RegisterCombinedNonce": {{ |
| 90 | + Entity: "signer", |
| 91 | + Action: "generate", |
| 92 | + }}, |
| 93 | + "/signrpc.Signer/MuSig2GetCombinedNonce": {{ |
| 94 | + Entity: "signer", |
| 95 | + Action: "read", |
| 96 | + }}, |
89 | 97 | "/signrpc.Signer/MuSig2Sign": {{ |
90 | 98 | Entity: "signer", |
91 | 99 | Action: "generate", |
@@ -1080,6 +1088,62 @@ func (s *Server) MuSig2RegisterNonces(_ context.Context, |
1080 | 1088 | return &MuSig2RegisterNoncesResponse{HaveAllNonces: haveAllNonces}, nil |
1081 | 1089 | } |
1082 | 1090 |
|
| 1091 | +// MuSig2RegisterCombinedNonce registers a pre-aggregated combined nonce for a |
| 1092 | +// session identified by its ID. This is an alternative to MuSig2RegisterNonces |
| 1093 | +// and is used when a coordinator has already aggregated all individual nonces. |
| 1094 | +func (s *Server) MuSig2RegisterCombinedNonce(_ context.Context, |
| 1095 | + in *MuSig2RegisterCombinedNonceRequest) ( |
| 1096 | + *MuSig2RegisterCombinedNonceResponse, error) { |
| 1097 | + |
| 1098 | + // Check session ID length. |
| 1099 | + sessionID, err := parseMuSig2SessionID(in.SessionId) |
| 1100 | + if err != nil { |
| 1101 | + return nil, fmt.Errorf("error parsing session ID: %w", err) |
| 1102 | + } |
| 1103 | + |
| 1104 | + // Validate the combined nonce length. |
| 1105 | + if len(in.CombinedPublicNonce) != musig2.PubNonceSize { |
| 1106 | + return nil, fmt.Errorf("invalid combined nonce length, got "+ |
| 1107 | + "%d wanted %d", len(in.CombinedPublicNonce), |
| 1108 | + musig2.PubNonceSize) |
| 1109 | + } |
| 1110 | + |
| 1111 | + // Convert to the expected fixed-size array. |
| 1112 | + var combinedNonce [musig2.PubNonceSize]byte |
| 1113 | + copy(combinedNonce[:], in.CombinedPublicNonce) |
| 1114 | + |
| 1115 | + // Register the combined nonce. |
| 1116 | + err = s.cfg.Signer.MuSig2RegisterCombinedNonce(sessionID, combinedNonce) |
| 1117 | + if err != nil { |
| 1118 | + return nil, fmt.Errorf("error registering combined nonce: %w", |
| 1119 | + err) |
| 1120 | + } |
| 1121 | + |
| 1122 | + return &MuSig2RegisterCombinedNonceResponse{}, nil |
| 1123 | +} |
| 1124 | + |
| 1125 | +// MuSig2GetCombinedNonce retrieves the combined nonce for a signing session. |
| 1126 | +func (s *Server) MuSig2GetCombinedNonce(_ context.Context, |
| 1127 | + in *MuSig2GetCombinedNonceRequest) ( |
| 1128 | + *MuSig2GetCombinedNonceResponse, error) { |
| 1129 | + |
| 1130 | + // Check session ID length. |
| 1131 | + sessionID, err := parseMuSig2SessionID(in.SessionId) |
| 1132 | + if err != nil { |
| 1133 | + return nil, fmt.Errorf("error parsing session ID: %w", err) |
| 1134 | + } |
| 1135 | + |
| 1136 | + // Get the combined nonce from the signer. |
| 1137 | + combinedNonce, err := s.cfg.Signer.MuSig2GetCombinedNonce(sessionID) |
| 1138 | + if err != nil { |
| 1139 | + return nil, fmt.Errorf("error getting combined nonce: %w", err) |
| 1140 | + } |
| 1141 | + |
| 1142 | + return &MuSig2GetCombinedNonceResponse{ |
| 1143 | + CombinedPublicNonce: combinedNonce[:], |
| 1144 | + }, nil |
| 1145 | +} |
| 1146 | + |
1083 | 1147 | // MuSig2Sign creates a partial signature using the local signing key that was |
1084 | 1148 | // specified when the session was created. This can only be called when all |
1085 | 1149 | // public nonces of all participants are known and have been registered with |
|
0 commit comments