common

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: AGPL-3.0 Imports: 13 Imported by: 7

Documentation

Index

Constants

View Source
const (
	// Header to include when sending messages that have been logged in
	AuthHeader string = "Authorization"

	// Format for the authorization header
	AuthHeaderFormat string = "Bearer %s"
)
View Source
const (
	// Value of the auth response header if the login token has expired
	InvalidSessionKey string = "invalid_session"

	// The signature provided can't be verified
	InvalidSignatureKey string = "invalid_signature"

	// The request didn't have the correct fields or the fields were malformed
	MalformedInputKey string = "malformed_input"

	// The provided deployment doesn't correspond to a deployment recognized by the service
	InvalidDeploymentKey string = "invalid_deployment"

	// The requester doesn't own the provided validator
	InvalidValidatorOwnerKey string = "invalid_validator_owner"

	// The exit message provided was invalid
	InvalidExitMessage string = "invalid_exit_message"

	// The user doesn't have permission to do this
	InvalidPermissionsKey string = "invalid_permissions"
)

Error keys

View Source
const (
	// Path for the deployments route
	DeploymentsPath string = "deployments"
)

Routes

Variables

View Source
var (
	// The session token is invalid, probably expired
	ErrInvalidSession error = errors.New("session token is invalid")

	// The provided signature could not be verified
	ErrInvalidSignature error = errors.New("the provided signature could not be verified")

	// The request didn't have the correct fields or the fields were malformed
	ErrMalformedInput error = errors.New("the request didn't have the correct fields or the fields were malformed")

	// The provided deployment doesn't correspond to a deployment recognized by the service
	ErrInvalidDeployment error = errors.New("the provided deployment doesn't correspond to a deployment recognized by the service")

	// The requester doesn't own the provided validator
	ErrInvalidValidatorOwner error = errors.New("this node doesn't own one of the provided validators")

	// The exit message provided was invalid
	ErrInvalidExitMessage error = errors.New("the provided exit message was invalid")

	// The user doesn't have permission to do this
	ErrInvalidPermissions error = errors.New("the user doesn't have permission from the nodeset.io service to do this yet")
)

Errors

Functions

func EncryptMessage added in v1.2.0

func EncryptMessage(message string, recipientPubkey string) ([]byte, error)

Encrypt an arbitrary message for submission to NodeSet.io using the age encryption library. The recipient is the public key of the recipient that will decrypt the message, typically the NodeSet.io service.

func EncryptSignedExitMessage added in v1.2.0

func EncryptSignedExitMessage(message ExitMessage, recipientPubkey string) (string, error)

Encrypt a hex-encoded signed exit message for submission to NodeSet.io using the age encryption library. The recipient is the public key of the recipient that will decrypt the message, typically the NodeSet.io service.

func SafeDebugLog added in v1.1.0

func SafeDebugLog(logger *slog.Logger, msg string, args ...any)

Logs a message at the debug level if the logger is not nil

Types

type CommonNodeSetClient

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

Client for interacting with the NodeSet server

func NewCommonNodeSetClient

func NewCommonNodeSetClient(baseUrl string, timeout time.Duration) *CommonNodeSetClient

Creates a new NodeSet client baseUrl: The base URL to use for the client, for example [https://nodeset.io/api]

func (*CommonNodeSetClient) SetSessionToken

func (c *CommonNodeSetClient) SetSessionToken(token string)

Set the session token for the client after logging in

type Deployment

type Deployment struct {
	// The Ethereum chain ID of the deployment
	ChainID string `json:"chainId"`

	// The name of the deployment, used as a key in subsequent requests
	Name string `json:"name"`
}

A deployment of the service

type DeploymentsData

type DeploymentsData struct {
	Deployments []Deployment `json:"deployments"`
}

Standard response data for a list of service deployments

type EncryptedExitData added in v1.2.0

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

Data for a pubkey's voluntary exit message

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 NodeSetResponse

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

func SubmitRequest

func SubmitRequest[DataType any](c *CommonNodeSetClient, ctx context.Context, logger *slog.Logger, requireAuth bool, method string, body io.Reader, queryParams map[string]string, subroutes ...string) (int, NodeSetResponse[DataType], error)

Send a request to the server and read the response NOTE: this is better suited to be a method of c but Go doesn't allow for generic methods yet

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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