mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
API Middleware for Keymanager Standard API Endpoints (#9936)
* begin the middleware approach * attempt middleware * middleware works in tandem with web ui * handle delete as well * delete request * DELETE working * tool to perform imports * functioning * commentary * build * gaz * smol test * enable keymanager api use protonames * edit * one rule * rem gw * Fix custom compiler (cherry picked from commit 3b1f65919e04ddf7e07c8f60cba1be883a736476) * gen proto * imports * Update validator/node/node.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * remaining comments * update item * rpc * add * run gateway * simplify * rem flag * deep source Co-authored-by: prestonvanloon <preston@prysmaticlabs.com> Co-authored-by: Radosław Kapka <rkapka@wp.pl> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
15
validator/rpc/apimiddleware/BUILD.bazel
Normal file
15
validator/rpc/apimiddleware/BUILD.bazel
Normal file
@@ -0,0 +1,15 @@
|
||||
load("@prysm//tools/go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"endpoint_factory.go",
|
||||
"structs.go",
|
||||
],
|
||||
importpath = "github.com/prysmaticlabs/prysm/validator/rpc/apimiddleware",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//api/gateway/apimiddleware:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
],
|
||||
)
|
||||
38
validator/rpc/apimiddleware/endpoint_factory.go
Normal file
38
validator/rpc/apimiddleware/endpoint_factory.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package apimiddleware
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prysmaticlabs/prysm/api/gateway/apimiddleware"
|
||||
)
|
||||
|
||||
// ValidatorEndpointFactory creates endpoints used for running validator API calls through the API Middleware.
|
||||
type ValidatorEndpointFactory struct {
|
||||
}
|
||||
|
||||
func (f *ValidatorEndpointFactory) IsNil() bool {
|
||||
return f == nil
|
||||
}
|
||||
|
||||
// Paths is a collection of all valid validator API paths.
|
||||
func (*ValidatorEndpointFactory) Paths() []string {
|
||||
return []string{
|
||||
"/eth/v1/keystores",
|
||||
}
|
||||
}
|
||||
|
||||
// Create returns a new endpoint for the provided API path.
|
||||
func (*ValidatorEndpointFactory) Create(path string) (*apimiddleware.Endpoint, error) {
|
||||
endpoint := apimiddleware.DefaultEndpoint()
|
||||
switch path {
|
||||
case "/eth/v1/keystores":
|
||||
endpoint.GetResponse = &listKeystoresResponseJson{}
|
||||
endpoint.PostRequest = &importKeystoresRequestJson{}
|
||||
endpoint.PostResponse = &importKeystoresResponseJson{}
|
||||
endpoint.DeleteRequest = &deleteKeystoresRequestJson{}
|
||||
endpoint.DeleteResponse = &deleteKeystoresResponseJson{}
|
||||
default:
|
||||
return nil, errors.New("invalid path")
|
||||
}
|
||||
endpoint.Path = path
|
||||
return &endpoint, nil
|
||||
}
|
||||
34
validator/rpc/apimiddleware/structs.go
Normal file
34
validator/rpc/apimiddleware/structs.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package apimiddleware
|
||||
|
||||
type listKeystoresResponseJson struct {
|
||||
Keystores []*keystoreJson `json:"keystores"`
|
||||
}
|
||||
|
||||
type keystoreJson struct {
|
||||
ValidatingPubkey string `json:"validating_pubkey" hex:"true"`
|
||||
DerivationPath string `json:"derivation_path"`
|
||||
}
|
||||
|
||||
type importKeystoresRequestJson struct {
|
||||
Keystores []string `json:"keystores"`
|
||||
Passwords []string `json:"passwords"`
|
||||
SlashingProtection string `json:"slashing_protection"`
|
||||
}
|
||||
|
||||
type importKeystoresResponseJson struct {
|
||||
Statuses []*statusJson `json:"statuses"`
|
||||
}
|
||||
|
||||
type deleteKeystoresRequestJson struct {
|
||||
PublicKeys []string `json:"public_keys" hex:"true"`
|
||||
}
|
||||
|
||||
type statusJson struct {
|
||||
Status string `json:"status"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
type deleteKeystoresResponseJson struct {
|
||||
Statuses []*statusJson `json:"statuses"`
|
||||
SlashingProtection string `json:"slashing_protection"`
|
||||
}
|
||||
@@ -97,6 +97,9 @@ func (s *Server) DeleteKeystores(
|
||||
if !ok {
|
||||
return nil, status.Error(codes.Internal, "Keymanager kind cannot delete keys")
|
||||
}
|
||||
if len(req.PublicKeys) == 0 {
|
||||
return ðpbservice.DeleteKeystoresResponse{Statuses: make([]*ethpbservice.DeletedKeystoreStatus, 0)}, nil
|
||||
}
|
||||
statuses, err := deleter.DeleteKeystores(ctx, req.PublicKeys)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not delete keys: %v", err)
|
||||
|
||||
@@ -203,7 +203,6 @@ func TestServer_ImportKeystores(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestServer_DeleteKeystores(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
srv := setupServerWithWallet(t)
|
||||
@@ -247,6 +246,14 @@ func TestServer_DeleteKeystores(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Run("no slashing protection response if no keys in request even if we have a history in DB", func(t *testing.T) {
|
||||
resp, err := srv.DeleteKeystores(context.Background(), ðpbservice.DeleteKeystoresRequest{
|
||||
PublicKeys: nil,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "", resp.SlashingProtection)
|
||||
})
|
||||
|
||||
// For ease of test setup, we'll give each public key a string identifier.
|
||||
publicKeysWithId := map[string][48]byte{
|
||||
"a": publicKeys[0],
|
||||
|
||||
Reference in New Issue
Block a user