core

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2020 License: GPL-3.0 Imports: 14 Imported by: 14

Documentation

Index

Constants

View Source
const (
	// BaseEIP2334Path is the base EIP2334 path.
	BaseEIP2334Path = "m/12381/3600"
)

EIP2334 paths.

Variables

This section is empty.

Functions

func EntropyToMnemonic

func EntropyToMnemonic(entropy []byte) (string, error)

Given an entropy, create the mnemonic passphrase.

func GenerateNewEntropy

func GenerateNewEntropy() ([]byte, error)

GenerateNewEntropy generates a new entropy

func InitBLS

func InitBLS() error

func SeedFromEntropy

func SeedFromEntropy(entropy []byte, password string) ([]byte, error)

the seed is the product of applying a key derivation algo (PBKDF2) on the mnemonic (as the entropy) and the password as salt. please see https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki

func SeedFromMnemonic

func SeedFromMnemonic(mnemonic string, password string) ([]byte, error)

SeedFromMnemonic generates a new seed. The seed is the product of applying a key derivation algo (PBKDF2) on the mnemonic (as the entropy) and the password as salt. Please see https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki

Types

type AttestationSlashStatus

type AttestationSlashStatus struct {
	Attestation *eth.AttestationData
	Status      VoteDetectionType
}

type HDKey

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

HDKey is a derived key from MasterDerivableKey which is able to sign messages, return thee public key and more.

func NewHDKeyFromPrivateKey

func NewHDKeyFromPrivateKey(priv []byte, path string) (*HDKey, error)

NewHDKeyFromPrivateKey is the constructor of HDKey

func (*HDKey) MarshalJSON

func (key *HDKey) MarshalJSON() ([]byte, error)

func (*HDKey) Path

func (key *HDKey) Path() string

func (*HDKey) PublicKey

func (key *HDKey) PublicKey() *bls.PublicKey

func (*HDKey) Sign

func (key *HDKey) Sign(data []byte) ([]byte, error)

func (*HDKey) UnmarshalJSON

func (key *HDKey) UnmarshalJSON(data []byte) error

type MasterDerivableKey

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

MasterDerivableKey is responsible for managing privKey derivation, signing and encryption. follows EIP 2333,2334 MasterDerivableKey is not intended to be used a signing key, just as a medium for managing keys

func MasterKeyFromSeed

func MasterKeyFromSeed(seed []byte, network Network) (*MasterDerivableKey, error)

MasterKeyFromSeed is the constructor of MasterDerivableKey. Base privKey is m / purpose / coin_type / as EIP 2334 defines

func (*MasterDerivableKey) Derive

func (master *MasterDerivableKey) Derive(relativePath string) (*HDKey, error)

Derive derives a HD key based on the given relative path.

type Network

type Network string

Network represents the network.

const (
	// PyrmontNetwork represents the Pyrmont test network.
	PyrmontNetwork Network = "pyrmont"

	// MainNetwork represents the main network.
	MainNetwork Network = "mainnet"
)

Available networks.

func NetworkFromString

func NetworkFromString(n string) Network

NetworkFromString returns network from the given string value

func (Network) DepositContractAddress

func (n Network) DepositContractAddress() string

DepositContractAddress returns the deposit contract address of the network.

func (Network) EstimatedCurrentSlot

func (n Network) EstimatedCurrentSlot() uint64

func (Network) EstimatedEpochAtSlot

func (n Network) EstimatedEpochAtSlot(slot uint64) uint64

func (Network) EstimatedSlotAtTime

func (n Network) EstimatedSlotAtTime(time int64) uint64

func (Network) ForkVersion

func (n Network) ForkVersion() []byte

ForkVersion returns the fork version of the network.

func (Network) FullPath

func (n Network) FullPath(relativePath string) string

ForkVersion returns the fork version of the network.

func (Network) MinGenesisTime

func (n Network) MinGenesisTime() uint64

func (Network) SlotDurationSec

func (n Network) SlotDurationSec() time.Duration

func (Network) SlotsPerEpoch

func (n Network) SlotsPerEpoch() uint64

type ProposalDetectionType

type ProposalDetectionType string
const (
	DoubleProposal      ProposalDetectionType = "DoubleProposal"
	HighestProposalVote ProposalDetectionType = "HighestProposalVote"
	ValidProposal       ProposalDetectionType = "Valid"
	Error               ProposalDetectionType = "Error"
)

type ProposalSlashStatus

type ProposalSlashStatus struct {
	Proposal *eth.BeaconBlock
	Status   ProposalDetectionType
	Error    error
}

type SlashingProtector

type SlashingProtector interface {
	IsSlashableAttestation(pubKey []byte, attestation *eth.AttestationData) (*AttestationSlashStatus, error)
	IsSlashableProposal(pubKey []byte, block *eth.BeaconBlock) (*ProposalSlashStatus, error)
	// Will potentially update the highest attestation given this latest attestation.
	UpdateHighestAttestation(pubKey []byte, attestation *eth.AttestationData) error
	UpdateHighestProposal(pubKey []byte, block *eth.BeaconBlock) error
	RetrieveHighestAttestation(pubKey []byte) (*eth.AttestationData, error)
}

SlashingProtector represents the behavior of the slashing protector

type SlashingStore

type SlashingStore interface {
	SaveHighestAttestation(pubKey []byte, attestation *eth.AttestationData) error
	RetrieveHighestAttestation(pubKey []byte) *eth.AttestationData
	SaveHighestProposal(pubKey []byte, block *eth.BeaconBlock) error
	RetrieveHighestProposal(pubKey []byte) *eth.BeaconBlock
}

SlashingStore represents the behavior of the slashing store

type Storage

type Storage interface {
	// Name returns storage name.
	Name() string

	// Network returns the network storage is related to.
	Network() Network

	//-------------------------
	//	Wallet specific
	//-------------------------
	// SaveWallet stores the given wallet.
	SaveWallet(wallet Wallet) error
	// OpenWallet returns nil,err if no wallet was found
	OpenWallet() (Wallet, error)
	// ListAccounts returns an empty array for no accounts
	ListAccounts() ([]ValidatorAccount, error)

	//-------------------------
	//	Account specific
	//-------------------------
	SaveAccount(account ValidatorAccount) error
	// Delete account by uuid
	DeleteAccount(accountId uuid.UUID) error
	// will return nil,nil if no account was found
	OpenAccount(accountId uuid.UUID) (ValidatorAccount, error)

	// SetEncryptor sets the given encryptor to the wallet.
	SetEncryptor(encryptor encryptor.Encryptor, password []byte)
}

Implements methods to store and retrieve data Any encryption is done on the implementation level but is not obligatory

type ValidatorAccount

type ValidatorAccount interface {
	// ID provides the ID for the account.
	ID() uuid.UUID

	// Name provides the name for the account.
	Name() string

	// BasePath provides the basePath of the account.
	BasePath() string

	// ValidatorPublicKey provides the public key for the validation key.
	ValidatorPublicKey() []byte

	// WithdrawalPublicKey provides the public key for the withdrawal key.
	WithdrawalPublicKey() []byte

	// ValidationKeySign signs data with the validation key.
	ValidationKeySign(data []byte) ([]byte, error)

	// GetDepositData returns deposit data
	GetDepositData() (map[string]interface{}, error)

	// SetContext sets the given context
	SetContext(ctx *WalletContext)
}

A validator account holds the information and actions needed by validator account keys. It holds 2 keys, a validation and a withdrawal key. As a minimum, the ValidatorAccount should have at least the validation key. Withdrawal key is not mandatory to be present.

type VoteDetectionType

type VoteDetectionType string
const (
	DoubleVote             VoteDetectionType = "DoubleVote"
	SurroundingVote        VoteDetectionType = "SurroundingVote"
	SurroundedVote         VoteDetectionType = "SurroundedVote"
	HighestAttestationVote VoteDetectionType = "HighestAttestationVote"
)

type Wallet

type Wallet interface {
	// ID provides the ID for the wallet.
	ID() uuid.UUID

	// Type provides the type of the wallet.
	Type() WalletType

	// CreateValidatorKey creates a new validation (validator) key pair in the wallet.
	// Keep in mind ND wallets will probably not allow this function, use AddValidatorAccount.
	CreateValidatorAccount(seed []byte, indexPointer *int) (ValidatorAccount, error)

	// Used to specifically add an account.
	// Keep in mind HD wallets will probably not allow this function, use CreateValidatorAccount.
	AddValidatorAccount(account ValidatorAccount) error

	// Accounts provides all accounts in the wallet.
	Accounts() []ValidatorAccount

	// AccountByID provides a single account from the wallet given its ID.
	// This will error if the account is not found.
	// should return account = nil if not found (not an error!)
	AccountByID(id uuid.UUID) (ValidatorAccount, error)

	// AccountByPublicKey provides a single account from the wallet given its public key.
	// This will error if the account is not found.
	// should return account = nil if not found (not an error!)
	AccountByPublicKey(pubKey string) (ValidatorAccount, error)

	// DeleteAccountByPublicKey delete an account from the wallet given its public key.
	// This will error if the account is not found.
	// should return nil if not error otherwise the error
	DeleteAccountByPublicKey(pubKey string) error

	// SetContext sets the given context
	SetContext(ctx *WalletContext)
}

A wallet is a container of accounts. Accounts = key pairs

type WalletContext

type WalletContext struct {
	Storage Storage
}

WalletContext represents the wallet's context type

type WalletType

type WalletType = string
const (
	HDWallet WalletType = "HD" // hierarchical deterministic wallet
	NDWallet WalletType = "ND" // non - deterministic
)

Jump to

Keyboard shortcuts

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