Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docs with return payload #469

Merged
merged 6 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion signature-aggregator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,20 @@ The only exposed endpoint is `/aggregate-signatures` expecting `application/jso
"message": "", // (string) hex-encoded unsigned message bytes to be signed
"justification": "", // (string) hex-encoded bytes to supply to the validators as justification
"signing-subnet-id": "", // (string) hex or cb58 encoded signing subnet ID. Defaults to source blockchain's subnet from data if omitted.
"quorum-percentage": 67 // (int) quorum percentage required to sign the message. Defaults to 67 if omitted
"quorum-percentage": 67 // (int) quorum percentage required to sign the message. Defaults to 67 if omitted
}
```

The successful `HTTP 200` response format is

```json
{
"signed-message": "" // (string) hex-encoded signed message bytes signed by at least `quorum-percentage` of the validator set.
}
```

Unsuccessful responses will include a `40x-50x` status codes with an explanatory `application/json` encoded message in the body of the response.

## Sample workflow
If you want to manually test a locally running service pointed to the Fuji testnet you can do so with the following steps.

Expand Down
16 changes: 9 additions & 7 deletions signature-aggregator/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func HandleAggregateSignaturesByRawMsgRequest(
func writeJSONError(
logger logging.Logger,
w http.ResponseWriter,
httpStatusCode int,
errorMsg string,
) {
resp, err := json.Marshal(struct{ error string }{error: errorMsg})
Expand All @@ -68,6 +69,7 @@ func writeJSONError(
}

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(httpStatusCode)

w.Write(resp)
if err != nil {
Expand All @@ -89,7 +91,7 @@ func signatureAggregationAPIHandler(
if err != nil {
msg := "Could not decode request body"
logger.Warn(msg, zap.Error(err))
writeJSONError(logger, w, msg)
writeJSONError(logger, w, http.StatusBadRequest, msg)
return
}
var decodedMessage []byte
Expand All @@ -103,14 +105,14 @@ func signatureAggregationAPIHandler(
zap.String("msg", req.UnsignedMessage),
zap.Error(err),
)
writeJSONError(logger, w, msg)
writeJSONError(logger, w, http.StatusBadRequest, msg)
return
}
unsignedMessage, err := types.UnpackWarpMessage(decodedMessage)
if err != nil {
msg := "Error unpacking warp message"
logger.Warn(msg, zap.Error(err))
writeJSONError(logger, w, msg)
writeJSONError(logger, w, http.StatusBadRequest, msg)
return
}
quorumPercentage := req.QuorumPercentage
Expand All @@ -119,7 +121,7 @@ func signatureAggregationAPIHandler(
} else if req.QuorumPercentage > 100 {
msg := "Invalid quorum number"
logger.Warn(msg, zap.Uint64("quorum-num", req.QuorumPercentage))
writeJSONError(logger, w, msg)
writeJSONError(logger, w, http.StatusBadRequest, msg)
return
}
var signingSubnetID ids.ID
Expand All @@ -134,7 +136,7 @@ func signatureAggregationAPIHandler(
zap.Error(err),
zap.String("input", req.SigningSubnetID),
)
writeJSONError(logger, w, msg)
writeJSONError(logger, w, http.StatusBadRequest, msg)
return
}
}
Expand All @@ -147,7 +149,7 @@ func signatureAggregationAPIHandler(
if err != nil {
msg := "Failed to aggregate signatures"
logger.Warn(msg, zap.Error(err))
writeJSONError(logger, w, msg)
writeJSONError(logger, w, http.StatusInternalServerError, msg)
return
}
resp, err := json.Marshal(
Expand All @@ -161,7 +163,7 @@ func signatureAggregationAPIHandler(
if err != nil {
msg := "Failed to marshal response"
logger.Error(msg, zap.Error(err))
writeJSONError(logger, w, msg)
writeJSONError(logger, w, http.StatusInternalServerError, msg)
return
}
w.Header().Set("Content-Type", "application/json")
Expand Down