prysm-pulse/validator/keymanager/v2/direct/direct.go
Raul Jordan 2d6f4ebf18
Part 1: Implement Accounts-V2 New, Wallet Creation (#6451)
* begin accounts-v2 new

* password validation

* validator accounts new with eip-2335 keystore

* select different wallet type based on enum

* clean up code significantly

* more robust code structure

* check if wallet exists

* define read and create wallet methods

* fmt

* go mod and comment

* comment

* redundant name

* satify gofmt

* add instructions with keymanager opts

* wrap up create and read wallet functionality

* prep for readiness

* doc improvements

* tests for create and read wallet

* update deps

* tidy

* visibility

* gaz

* fix up

* refactor for proper usage, with wallet and keymanager ifaces

* Update validator/flags/flags.go

Co-authored-by: Ivan Martinez <ivanthegreatdev@gmail.com>

* import

* improve structure

* wrap up all comments

* simplify

* lint

* Update validator/accounts/v2/cmd.go

* viz check

* add interface methods as needed

* fix build

* lint

* nishant feedback

* simplify structure

* add tests for strong password check

* all feedback done

* ivan feedback

* ivan feedback

Co-authored-by: Ivan Martinez <ivanthegreatdev@gmail.com>
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2020-07-01 16:30:01 -05:00

75 lines
2.2 KiB
Go

package direct
import (
"context"
"errors"
"io"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/sirupsen/logrus"
)
var log = logrus.WithField("prefix", "keymanager-v2")
// Wallet defines a struct which has capabilities and knowledge of how
// to read and write important accounts-related files to the filesystem.
// Useful for keymanager to have persistent capabilities for accounts on-disk.
type Wallet interface {
AccountsPath() string
AccountPasswordsPath() string
WriteAccountToDisk(ctx context.Context, filename string, encoded []byte) error
WriteKeymanagerConfigToDisk(ctx context.Context, encoded []byte) error
ReadKeymanagerConfigFromDisk(ctx context.Context) (io.ReadCloser, error)
}
// Config for a direct keymanager.
type Config struct{}
// Keymanager implementation for direct keystores.
type Keymanager struct {
wallet Wallet
}
// DefaultConfig for a direct keymanager implementation.
func DefaultConfig() *Config {
return &Config{}
}
// NewKeymanager instantiates a new direct keymanager from configuration options.
func NewKeymanager(ctx context.Context, wallet Wallet, cfg *Config) *Keymanager {
return &Keymanager{
wallet: wallet,
}
}
// NewKeymanagerFromConfigFile instantiates a direct keymanager instance
// from a configuration file accesed via a wallet.
// TODO(#6220): Implement.
func NewKeymanagerFromConfigFile(ctx context.Context, wallet Wallet) (*Keymanager, error) {
return &Keymanager{
wallet: wallet,
}, nil
}
// CreateAccount for a direct keymanager implementation.
// TODO(#6220): Implement.
func (dr *Keymanager) CreateAccount(ctx context.Context, password string) error {
return errors.New("unimplemented")
}
// MarshalConfigFile returns a marshaled configuration file for a direct keymanager.
// TODO(#6220): Implement.
func (dr *Keymanager) MarshalConfigFile(ctx context.Context) ([]byte, error) {
return nil, nil
}
// FetchValidatingPublicKeys fetches the list of public keys from the direct account keystores.
func (dr *Keymanager) FetchValidatingPublicKeys() ([][48]byte, error) {
return nil, errors.New("unimplemented")
}
// Sign signs a message using a validator key.
func (dr *Keymanager) Sign(context.Context, interface{}) (bls.Signature, error) {
return nil, errors.New("unimplemented")
}