swcommon

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: AGPL-3.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Stakewise validators deposit a full 32 ETH
	StakewiseDepositAmount uint64 = 32e9
)

Variables

View Source
var (
	ErrUnregisteredNode   error = errors.New("node hasn't been registered with the NodeSet server yet")
	ErrAlreadyRegistered  error = errors.New("node has already been registered with the NodeSet server")
	ErrNotWhitelisted     error = errors.New("node address hasn't been whitelisted on the provided NodeSet account")
	ErrVaultNotFound      error = errors.New("deposit data has withdrawal creds that don't match a StakeWise vault")
	ErrInvalidPermissions error = errors.New("deposit data can't be uploaded to Mainnet because you aren't permitted to use Mainnet yet")
)

Functions

func GetNodesetStatus added in v1.0.0

func GetNodesetStatus(pubKey beacon.ValidatorPubkey, registeredPubkeysStatusMapping map[beacon.ValidatorPubkey]string) swtypes.NodesetStatus

func IsUploadedToNodeset added in v0.1.2

func IsUploadedToNodeset(pubKey beacon.ValidatorPubkey, registeredPubkeys []beacon.ValidatorPubkey) bool

Types

type DepositDataData added in v0.2.0

type DepositDataData struct {
	Version     int                         `json:"version"`
	DepositData []types.ExtendedDepositData `json:"depositData"`
}

Response to a deposit data request

type DepositDataManager

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

DepositDataManager manages the aggregated deposit data file that Stakewise uses

func NewDepositDataManager

func NewDepositDataManager(sp *StakeWiseServiceProvider) (*DepositDataManager, error)

Creates a new manager

func (*DepositDataManager) ComputeMerkleRoot

func (m *DepositDataManager) ComputeMerkleRoot(data []types.ExtendedDepositData) (common.Hash, error)

Compute the Merkle root of the aggregated deposit data using the Stakewise rules NOTE: reverse engineered from https://github.com/stakewise/v3-operator/blob/fa4ac2673a64a486ced51098005376e56e2ddd19/src/validators/utils.py#L207

func (*DepositDataManager) GenerateDepositData

func (m *DepositDataManager) GenerateDepositData(keys []*eth2types.BLSPrivateKey) ([]*types.ExtendedDepositData, error)

Generates deposit data for the provided keys

func (*DepositDataManager) GetDepositData

func (m *DepositDataManager) GetDepositData() ([]byte, error)

Read the deposit data file

func (*DepositDataManager) UpdateDepositData

func (m *DepositDataManager) UpdateDepositData(data []types.ExtendedDepositData) error

Save the deposit data file

type DepositDataMetaData added in v0.2.0

type DepositDataMetaData struct {
	Version int `json:"version"`
}

Response to a deposit data meta request

type ExitData

type ExitData struct {
	Pubkey      string      `json:"pubkey"`
	ExitMessage ExitMessage `json:"exit_message"`
}

Data for a pubkey's voluntary exit message

type ExitMessage

type ExitMessage struct {
	Message   ExitMessageDetails `json:"message"`
	Signature string             `json:"signature"`
}

Voluntary exit message

type ExitMessageDetails

type ExitMessageDetails struct {
	Epoch          string `json:"epoch"`
	ValidatorIndex string `json:"validator_index"`
}

Details of an exit message

type LoginData added in v0.2.0

type LoginData struct {
	Token string `json:"token"`
}

Response to a login request

type LoginRequest added in v0.2.0

type LoginRequest struct {
	Nonce     string `json:"nonce"`
	Address   string `json:"address"`
	Signature string `json:"signature"` // Must be 0x-prefixed hex encoded
}

Request to log into the NodeSet server

type NodeSetClient_v1 added in v0.2.0

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

Client for interacting with the Nodeset server

func NewNodeSetClient_v1 added in v0.2.0

func NewNodeSetClient_v1(sp *StakeWiseServiceProvider) *NodeSetClient_v1

Creates a new Nodeset client

func (*NodeSetClient_v1) GetNodeRegistrationStatus added in v1.0.0

func (c *NodeSetClient_v1) GetNodeRegistrationStatus(ctx context.Context) (swapi.NodesetRegistrationStatus, error)

Returns whether the node is registered with the NodeSet server

func (*NodeSetClient_v1) GetRegisteredValidators added in v0.2.0

func (c *NodeSetClient_v1) GetRegisteredValidators(ctx context.Context) ([]ValidatorStatus, error)

Get a list of all of the pubkeys that have already been registered with NodeSet for this node

func (*NodeSetClient_v1) GetServerDepositData added in v0.2.0

func (c *NodeSetClient_v1) GetServerDepositData(ctx context.Context) (int, []types.ExtendedDepositData, error)

Get the aggregated deposit data from the server

func (*NodeSetClient_v1) GetServerDepositDataVersion added in v0.2.0

func (c *NodeSetClient_v1) GetServerDepositDataVersion(ctx context.Context) (int, error)

Get the current version of the aggregated deposit data on the server

func (*NodeSetClient_v1) Login added in v1.0.0

func (c *NodeSetClient_v1) Login(ctx context.Context) error

Logs into the NodeSet API server, grabbing a new authentication token

func (*NodeSetClient_v1) Logout added in v1.0.0

func (c *NodeSetClient_v1) Logout()

Logs out of the NodeSet service, resetting the registration status in the process.

func (*NodeSetClient_v1) RegisterNode added in v0.2.0

func (c *NodeSetClient_v1) RegisterNode(ctx context.Context, email string, nodeWallet common.Address) error

Registers the node with the NodeSet server. Assumes wallet validation has already been done and the actual wallet address is provided here; if it's not, the signature won't come from the node being registered so it will fail validation.

func (*NodeSetClient_v1) UploadDepositData added in v0.2.0

func (c *NodeSetClient_v1) UploadDepositData(ctx context.Context, depositData []byte) error

Uploads deposit data to Nodeset

func (*NodeSetClient_v1) UploadSignedExitData added in v0.2.0

func (c *NodeSetClient_v1) UploadSignedExitData(ctx context.Context, exitData []ExitData) error

Submit signed exit data to Nodeset

type NodeSetResponse added in v0.2.0

type NodeSetResponse[DataType any] struct {
	OK      bool     `json:"ok"`
	Message string   `json:"message,omitempty"`
	Data    DataType `json:"data,omitempty"`
	Error   string   `json:"error,omitempty"`
}

All responses from the NodeSet API will have this format `message` may or may not be populated (but should always be populated if `ok` is false) `data` should be populated if `ok` is true, and will be omitted if `ok` is false

type NonceData added in v0.2.0

type NonceData struct {
	Nonce string `json:"nonce"`
	Token string `json:"token"`
}

Data used returned from nonce requests

type RegisterNodeRequest added in v0.2.0

type RegisterNodeRequest struct {
	Email       string `json:"email"`
	NodeAddress string `json:"node_address"`
	Signature   string `json:"signature"` // Must be 0x-prefixed hex encoded
}

Request to register a node with the NodeSet server

type StakeWiseServiceProvider added in v1.0.0

type StakeWiseServiceProvider struct {
	*services.ServiceProvider
	// contains filtered or unexported fields
}

func NewStakeWiseServiceProvider added in v1.0.0

func NewStakeWiseServiceProvider(sp *services.ServiceProvider) (*StakeWiseServiceProvider, error)

Create a new service provider with Stakewise daemon-specific features

func NewStakeWiseServiceProviderFromCustomServices added in v1.0.0

func NewStakeWiseServiceProviderFromCustomServices(sp *services.ServiceProvider, cfg *swconfig.StakeWiseConfig, resources *swconfig.StakewiseResources) (*StakeWiseServiceProvider, error)

Create a new service provider with Stakewise daemon-specific features, using custom services instead of loading them from the module service provider.

func (*StakeWiseServiceProvider) GetDepositDataManager added in v1.0.0

func (s *StakeWiseServiceProvider) GetDepositDataManager() *DepositDataManager

func (*StakeWiseServiceProvider) GetModuleConfig added in v1.0.0

func (s *StakeWiseServiceProvider) GetModuleConfig() *swconfig.StakeWiseConfig

func (*StakeWiseServiceProvider) GetNodesetClient added in v1.0.0

func (s *StakeWiseServiceProvider) GetNodesetClient() *NodeSetClient_v1

func (*StakeWiseServiceProvider) GetResources added in v1.0.0

func (*StakeWiseServiceProvider) GetWallet added in v1.0.0

func (s *StakeWiseServiceProvider) GetWallet() *Wallet

func (*StakeWiseServiceProvider) RequireStakewiseWalletReady added in v1.0.0

func (sp *StakeWiseServiceProvider) RequireStakewiseWalletReady(ctx context.Context, status wallet.WalletStatus) error

func (*StakeWiseServiceProvider) WaitForNodeSetRegistration added in v1.0.0

func (sp *StakeWiseServiceProvider) WaitForNodeSetRegistration(ctx context.Context) bool

Wait until the node has been registered with NodeSet. Returns true if the context was cancelled and the caller should exit.

func (*StakeWiseServiceProvider) WaitForStakewiseWallet added in v1.0.0

func (sp *StakeWiseServiceProvider) WaitForStakewiseWallet(ctx context.Context) error

type ValidatorStatus

type ValidatorStatus struct {
	Pubkey              beacon.ValidatorPubkey `json:"pubkey"`
	Status              string                 `json:"status"`
	ExitMessageUploaded bool                   `json:"exitMessage"`
}

Validator status info

type ValidatorsData added in v0.2.0

type ValidatorsData struct {
	Validators []ValidatorStatus `json:"validators"`
}

Response to a validators request

type Wallet

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

Wallet manager for the Stakewise daemon

func NewWallet

func NewWallet(sp *services.ServiceProvider) (*Wallet, error)

Create a new wallet

func (*Wallet) CheckIfStakewiseWalletExists

func (w *Wallet) CheckIfStakewiseWalletExists() (bool, error)

Check if the Stakewise wallet and password files exist

func (*Wallet) DerivePubKeys

func (w *Wallet) DerivePubKeys(privateKeys []*eth2types.BLSPrivateKey) ([]beacon.ValidatorPubkey, error)

Get the private validator key with the corresponding pubkey

func (*Wallet) GenerateNewValidatorKey

func (w *Wallet) GenerateNewValidatorKey() (*eth2types.BLSPrivateKey, error)

Generate a new validator key and save it

func (*Wallet) GetAllPrivateKeys

func (w *Wallet) GetAllPrivateKeys() ([]*eth2types.BLSPrivateKey, error)

Gets all of the validator private keys that are stored in the Stakewise keystore folder

func (*Wallet) GetLatestDepositDataVersion

func (w *Wallet) GetLatestDepositDataVersion() int

Get the version of the aggregated deposit data from the NodeSet server that's stored on disk

func (*Wallet) GetPrivateKeyForPubkey

func (w *Wallet) GetPrivateKeyForPubkey(pubkey beacon.ValidatorPubkey) (*eth2types.BLSPrivateKey, error)

Get the private validator key with the corresponding pubkey

func (*Wallet) Reload added in v1.0.0

func (w *Wallet) Reload() error

Reload the wallet data from disk

func (*Wallet) SaveStakewiseWallet

func (w *Wallet) SaveStakewiseWallet(ethKey []byte, password string) error

Saves the Stakewise wallet and password files

func (*Wallet) SetLatestDepositDataVersion

func (w *Wallet) SetLatestDepositDataVersion(version int) error

Set the latest deposit data version and save the wallet data

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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