core

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2021 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)

EntropyToMnemonic creates the mnemonic passphrase.

func GenerateNewEntropy

func GenerateNewEntropy() ([]byte, error)

GenerateNewEntropy generates a new entropy

func InitBLS

func InitBLS() error

InitBLS initializes BLS

func SeedFromEntropy

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

SeedFromEntropy creates seed from the given entropy 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 AccountStorage added in v1.0.1

type AccountStorage interface {
	// SaveAccount saves the given account
	SaveAccount(account ValidatorAccount) error

	// DeleteAccount deletes account by uuid
	DeleteAccount(accountID uuid.UUID) error

	// OpenAccount returns 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)
}

AccountStorage represents the behavior of the account storage

type AttestationSlashStatus

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

AttestationSlashStatus represents attestation slashing status

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)

MarshalJSON is the custom JSON marshaler

func (*HDKey) Path

func (key *HDKey) Path() string

Path returns path

func (*HDKey) PublicKey

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

PublicKey returns the public key

func (*HDKey) Sign

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

Sign signs the given data

func (*HDKey) UnmarshalJSON

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

UnmarshalJSON is the custom JSON unmarshaler

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"

	// PraterNetwork represents the Prater test network.
	PraterNetwork Network = "prater"

	// 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) EstimatedCurrentEpoch

func (n Network) EstimatedCurrentEpoch() uint64

EstimatedCurrentEpoch estimates the current epoch https://github.com/ethereum/eth2.0-specs/blob/dev/specs/phase0/beacon-chain.md#compute_start_slot_at_epoch

func (Network) EstimatedCurrentSlot

func (n Network) EstimatedCurrentSlot() uint64

EstimatedCurrentSlot returns the estimation of the current slot

func (Network) EstimatedEpochAtSlot

func (n Network) EstimatedEpochAtSlot(slot uint64) uint64

EstimatedEpochAtSlot estimates epoch at the given slot

func (Network) EstimatedSlotAtTime

func (n Network) EstimatedSlotAtTime(time int64) uint64

EstimatedSlotAtTime estimates slot at the given time

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

FullPath returns the full path of the network.

func (Network) MinGenesisTime

func (n Network) MinGenesisTime() uint64

MinGenesisTime returns min genesis time value

func (Network) SlotDurationSec

func (n Network) SlotDurationSec() time.Duration

SlotDurationSec returns slot duration

func (Network) SlotsPerEpoch

func (n Network) SlotsPerEpoch() uint64

SlotsPerEpoch returns number of slots per one epoch

type ProposalDetectionType

type ProposalDetectionType string

ProposalDetectionType represents proposal slashing detection type

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

Proposal slashing detection types

type ProposalSlashStatus

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

ProposalSlashStatus represents proposal slashing status

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 {
	WalletStorage
	AccountStorage

	// Name returns storage name.
	Name() string

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

Storage represents storage behavior 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)
}

ValidatorAccount 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

VoteDetectionType represents vote detection type

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

Vote detection types

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)
}

Wallet is a container of accounts. Accounts = key pairs

type WalletContext

type WalletContext struct {
	Storage Storage
}

WalletContext represents the wallet's context type

type WalletStorage added in v1.0.1

type WalletStorage interface {
	// 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)
}

WalletStorage represents the behavior of the wallet storage

type WalletType

type WalletType = string

WalletType represents wallet type

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

Wallet types

Jump to

Keyboard shortcuts

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