keystore

package
v0.3.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2020 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// StandardScryptN is the N parameter of Scrypt encryption algorithm, using 256MB
	// memory and taking approximately 1s CPU time on a modern processor.
	StandardScryptN = 1 << 18

	// StandardScryptP is the P parameter of Scrypt encryption algorithm, using 256MB
	// memory and taking approximately 1s CPU time on a modern processor.
	StandardScryptP = 1

	// LightScryptN is the N parameter of Scrypt encryption algorithm, using 4MB
	// memory and taking approximately 100ms CPU time on a modern processor.
	LightScryptN = 1 << 12

	// LightScryptP is the P parameter of Scrypt encryption algorithm, using 4MB
	// memory and taking approximately 100ms CPU time on a modern processor.
	LightScryptP = 6
)

Variables

View Source
var (
	// ErrDecrypt is the standard error message when decryption is a failure.
	ErrDecrypt = errors.New("could not decrypt key with given passphrase")
)

Functions

func DepositInput

func DepositInput(depositKey *Key, withdrawalKey *Key, amountInGwei uint64) (*ethpb.Deposit_Data, [32]byte, error)

DepositInput for a given key. This input data can be used to when making a validator deposit. The input data includes a proof of possession field signed by the deposit key.

Spec details about general deposit workflow:

To submit a deposit:

- Pack the validator's initialization parameters into deposit_data, a Deposit_Data SSZ object.
- Let amount be the amount in Gwei to be deposited by the validator where MIN_DEPOSIT_AMOUNT <= amount <= MAX_EFFECTIVE_BALANCE.
- Set deposit_data.amount = amount.
- Let signature be the result of bls_sign of the signing_root(deposit_data) with domain=compute_domain(DOMAIN_DEPOSIT). (Deposits are valid regardless of fork version, compute_domain will default to zeroes there).
- Send a transaction on the Ethereum 1.0 chain to DEPOSIT_CONTRACT_ADDRESS executing def deposit(pubkey: bytes[48], withdrawal_credentials: bytes[32], signature: bytes[96]) along with a deposit of amount Gwei.

See: https://github.com/ethereum/eth2.0-specs/blob/master/specs/validator/0_beacon-chain-validator.md#submit-deposit

func EncryptKey

func EncryptKey(key *Key, password string, scryptN, scryptP int) ([]byte, error)

EncryptKey encrypts a key using the specified scrypt parameters into a json blob that can be decrypted later on.

func Keccak256

func Keccak256(data ...[]byte) []byte

Keccak256 calculates and returns the Keccak256 hash of the input data.

func RetrievePubKey

func RetrievePubKey(directory string, password string) (*bls.PublicKey, error)

RetrievePubKey retrieves the public key from the keystore.

func StoreRandomKey

func StoreRandomKey(dir, password string, scryptN, scryptP int) error

StoreRandomKey generates a key, encrypts with 'auth' and stores in the given directory

Types

type Key

type Key struct {
	ID uuid.UUID // Version 4 "random" for unique id not derived from key data

	PublicKey *bls.PublicKey // Represents the public key of the user.

	SecretKey *bls.SecretKey // Represents the private key of the user.
}

Key is the object that stores all the user data related to their public/secret keys.

func DecryptKey

func DecryptKey(keyjson []byte, password string) (*Key, error)

DecryptKey decrypts a key from a json blob, returning the private key itself.

func NewKey

func NewKey() (*Key, error)

NewKey generates a new random key.

func NewKeyFromBLS

func NewKeyFromBLS(blsKey *bls.SecretKey) (*Key, error)

NewKeyFromBLS creates a new keystore Key type using a BLS private key.

func (*Key) MarshalJSON

func (k *Key) MarshalJSON() (j []byte, err error)

MarshalJSON marshalls a key struct into a JSON blob.

func (*Key) UnmarshalJSON

func (k *Key) UnmarshalJSON(j []byte) (err error)

UnmarshalJSON unmarshals a blob into a key struct.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store defines a keystore with a directory path and scrypt values.

func NewKeystore

func NewKeystore(directory string) Store

NewKeystore from a directory.

func (Store) GetKey

func (ks Store) GetKey(filename, password string) (*Key, error)

GetKey from file using the filename path and a decryption password.

func (Store) GetKeys

func (ks Store) GetKeys(directory, fileprefix, password string, warnOnFail bool) (map[string]*Key, error)

GetKeys from directory using the prefix to filter relevant files and a decryption password.

func (Store) JoinPath

func (ks Store) JoinPath(filename string) string

JoinPath joins the filename with the keystore directory path.

func (Store) StoreKey

func (ks Store) StoreKey(filename string, key *Key, auth string) error

StoreKey in filepath and encrypt it with a password.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL