github.com/prysmaticlabs/prysm@v1.4.4/validator/keymanager/types.go (about)

     1  package keymanager
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	validatorpb "github.com/prysmaticlabs/prysm/proto/validator/accounts/v2"
     8  	"github.com/prysmaticlabs/prysm/shared/bls"
     9  	"github.com/prysmaticlabs/prysm/shared/event"
    10  )
    11  
    12  // IKeymanager defines a general keymanager interface for Prysm wallets.
    13  type IKeymanager interface {
    14  	// FetchValidatingPublicKeys fetches the list of active public keys that should be used to validate with.
    15  	FetchValidatingPublicKeys(ctx context.Context) ([][48]byte, error)
    16  	// Sign signs a message using a validator key.
    17  	Sign(context.Context, *validatorpb.SignRequest) (bls.Signature, error)
    18  	// SubscribeAccountChanges subscribes to changes made to the underlying keys.
    19  	SubscribeAccountChanges(pubKeysChan chan [][48]byte) event.Subscription
    20  }
    21  
    22  // Keystore json file representation as a Go struct.
    23  type Keystore struct {
    24  	Crypto  map[string]interface{} `json:"crypto"`
    25  	ID      string                 `json:"uuid"`
    26  	Pubkey  string                 `json:"pubkey"`
    27  	Version uint                   `json:"version"`
    28  	Name    string                 `json:"name"`
    29  }
    30  
    31  // Kind defines an enum for either imported, derived, or remote-signing
    32  // keystores for Prysm wallets.
    33  type Kind int
    34  
    35  const (
    36  	// Imported keymanager defines an on-disk, encrypted keystore-capable store.
    37  	Imported Kind = iota
    38  	// Derived keymanager using a hierarchical-deterministic algorithm.
    39  	Derived
    40  	// Remote keymanager capable of remote-signing data.
    41  	Remote
    42  )
    43  
    44  // String marshals a keymanager kind to a string value.
    45  func (k Kind) String() string {
    46  	switch k {
    47  	case Derived:
    48  		return "derived"
    49  	case Imported:
    50  		return "direct"
    51  	case Remote:
    52  		return "remote"
    53  	default:
    54  		return fmt.Sprintf("%d", int(k))
    55  	}
    56  }
    57  
    58  // ParseKind from a raw string, returning a keymanager kind.
    59  func ParseKind(k string) (Kind, error) {
    60  	switch k {
    61  	case "derived":
    62  		return Derived, nil
    63  	case "direct":
    64  		return Imported, nil
    65  	case "remote":
    66  		return Remote, nil
    67  	default:
    68  		return 0, fmt.Errorf("%s is not an allowed keymanager", k)
    69  	}
    70  }