core

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2024 License: GPL-3.0 Imports: 15 Imported by: 0

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 *phase0.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 MasterKeyFromPrivateKey added in v1.0.8

func MasterKeyFromPrivateKey(privateKey []byte, network Network) (*MasterDerivableKey, error)

MasterKeyFromPrivateKey gets the private key from master key

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"

	// HoleskyNetwork represents the Holesky test network.
	HoleskyNetwork Network = "holesky"

	// 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() phase0.Epoch

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() phase0.Slot

EstimatedCurrentSlot returns the estimation of the current slot

func (Network) EstimatedEpochAtSlot

func (n Network) EstimatedEpochAtSlot(slot phase0.Slot) phase0.Epoch

EstimatedEpochAtSlot estimates epoch at the given slot

func (Network) EstimatedSlotAtTime

func (n Network) EstimatedSlotAtTime(time int64) phase0.Slot

EstimatedSlotAtTime estimates slot at the given time

func (Network) FullPath

func (n Network) FullPath(relativePath string) string

FullPath returns the full path of the network.

func (Network) GenesisForkVersion added in v1.3.0

func (n Network) GenesisForkVersion() phase0.Version

GenesisForkVersion returns the genesis fork version of the network.

func (Network) GenesisValidatorsRoot added in v1.3.0

func (n Network) GenesisValidatorsRoot() phase0.Root

GenesisValidatorsRoot returns the genesis validators root 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 {
	Slot   phase0.Slot
	Status ProposalDetectionType
	Error  error
}

ProposalSlashStatus represents proposal slashing status

type SlashingProtector

type SlashingProtector interface {
	IsSlashableAttestation(pubKey []byte, attestation *phase0.AttestationData) (*AttestationSlashStatus, error)
	IsSlashableProposal(pubKey []byte, slot phase0.Slot) (*ProposalSlashStatus, error)
	UpdateHighestAttestation(pubKey []byte, attestation *phase0.AttestationData) error
	UpdateHighestProposal(pubKey []byte, slot phase0.Slot) error
	FetchHighestAttestation(pubKey []byte) (*phase0.AttestationData, bool, error)
	FetchHighestProposal(pubKey []byte) (phase0.Slot, bool, error)
}

SlashingProtector represents the behavior of the slashing protector

type SlashingStore

type SlashingStore interface {
	SaveHighestAttestation(pubKey []byte, attestation *phase0.AttestationData) error
	RetrieveHighestAttestation(pubKey []byte) (*phase0.AttestationData, bool, error)
	SaveHighestProposal(pubKey []byte, slot phase0.Slot) error
	RetrieveHighestProposal(pubKey []byte) (phase0.Slot, bool, error)
}

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 ValidatorInfo added in v1.3.0

type ValidatorInfo struct {
	Index                 phase0.ValidatorIndex
	Pubkey                phase0.BLSPubKey
	WithdrawalCredentials []byte
	ToExecutionAddress    bellatrix.ExecutionAddress
}

ValidatorInfo represents the information of a validator

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

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

	// CreateValidatorAccountFromPrivateKey creates validator account from Private Key
	CreateValidatorAccountFromPrivateKey(privateKey []byte, indexPointer *int) (ValidatorAccount, error)

	// AddValidatorAccount 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
	WithdrawalMode bool
}

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