Skip to content

Commit 16b9192

Browse files
committed
signrpc: implement combined nonce RPC server handlers
Add server-side RPC handlers for MuSig2RegisterCombinedNonce and MuSig2GetCombinedNonce. The handlers: - Delegate to the Signer interface methods - Validate input (session ID format, combined nonce length) - Include macaroon permissions (generate for register, read for get) These handlers complete the server-side RPC implementation.
1 parent c945f67 commit 16b9192

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

lnrpc/signrpc/signer_server.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ var (
8686
Entity: "signer",
8787
Action: "generate",
8888
}},
89+
"/signrpc.Signer/MuSig2RegisterCombinedNonce": {{
90+
Entity: "signer",
91+
Action: "generate",
92+
}},
93+
"/signrpc.Signer/MuSig2GetCombinedNonce": {{
94+
Entity: "signer",
95+
Action: "read",
96+
}},
8997
"/signrpc.Signer/MuSig2Sign": {{
9098
Entity: "signer",
9199
Action: "generate",
@@ -1080,6 +1088,62 @@ func (s *Server) MuSig2RegisterNonces(_ context.Context,
10801088
return &MuSig2RegisterNoncesResponse{HaveAllNonces: haveAllNonces}, nil
10811089
}
10821090

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+
10831147
// MuSig2Sign creates a partial signature using the local signing key that was
10841148
// specified when the session was created. This can only be called when all
10851149
// public nonces of all participants are known and have been registered with

0 commit comments

Comments
 (0)