bsscore

package module
v0.0.0-...-5cda5f8 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2023 License: MIT Imports: 26 Imported by: 7

Documentation

Overview

Package etherkeyms utilises the Key Management Service (KMS) from the Google Cloud Platform (GCP) for Ethereum operations.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCannotGetPrivateKey signals that an both or neither combination of
	// mnemonic+hdpath or private key string was used in the configuration.
	ErrCannotGetPrivateKey = errors.New("invalid combination of privkey " +
		"or mnemonic+hdpath")
)

Functions

func DerivePrivateKey

func DerivePrivateKey(mnemonic, hdPath string) (*ecdsa.PrivateKey, error)

DerivePrivateKey derives the private key from a given mnemonic and BIP32 deriviation path.

func GetConfiguredPrivateKey

func GetConfiguredPrivateKey(mnemonic, hdPath, privKeyStr string) (
	*ecdsa.PrivateKey, error)

GetConfiguredPrivateKey computes the private key for our configured services. The two supported methods are:

  • Derived from BIP39 mnemonic and BIP32 HD derivation path.
  • Directly from a serialized private key.

func ParseAddress

func ParseAddress(address string) (common.Address, error)

ParseAddress parses an ETH address from a hex string. This method will fail if the address is not a valid hexadecimal address.

func ParsePrivateKeyStr

func ParsePrivateKeyStr(privKeyStr string) (*ecdsa.PrivateKey, error)

ParsePrivateKeyStr parses a hexadecimal encoded private key, the encoding may optionally have an "0x" prefix.

func ParseWalletPrivKeyAndContractAddr

func ParseWalletPrivKeyAndContractAddr(
	name string,
	mnemonic string,
	hdPath string,
	privKeyStr string,
	contractAddrStr string,
) (*ecdsa.PrivateKey, common.Address, error)

ParseWalletPrivKeyAndContractAddr returns the wallet private key to use for sending transactions as well as the contract address to send to for a particular sub-service.

func SentryStreamHandler

func SentryStreamHandler(wr io.Writer, fmtr log.Format) log.Handler

SentryStreamHandler creates a log.Handler that behaves similarly to log.StreamHandler, however it writes any log with severity greater than or equal to log.LvlError to Sentry. In that case, the passed log.Record is encoded using JSON rather than the default terminal output, so that it can be captured for debugging in the Sentry dashboard.

func TraceRateToFloat64

func TraceRateToFloat64(rate time.Duration) float64

TraceRateToFloat64 converts a time.Duration into a valid float64 for the Sentry client. The client only accepts values between 0.0 and 1.0, so this method clamps anything greater than 1 second to 1.0.

Types

type BatchSubmitter

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

BatchSubmitter is a service that configures the necessary resources for running the TxBatchSubmitter and StateBatchSubmitter sub-services.

func NewBatchSubmitter

func NewBatchSubmitter(
	ctx context.Context,
	cancel func(),
	services []*Service,
) (*BatchSubmitter, error)

NewBatchSubmitter initializes the BatchSubmitter, gathering any resources that will be needed by the TxBatchSubmitter and StateBatchSubmitter sub-services.

func (*BatchSubmitter) Start

func (b *BatchSubmitter) Start() error

Start starts all provided services.

func (*BatchSubmitter) Stop

func (b *BatchSubmitter) Stop()

Stop stops all provided services and blocks until shutdown.

type Driver

type Driver interface {
	// Name is an identifier used to prefix logs for a particular service.
	Name() string

	// WalletAddr is the wallet address used to pay for batch transaction
	// fees.
	WalletAddr() common.Address

	// Metrics returns the subservice telemetry object.
	Metrics() metrics.Metrics

	// ClearPendingTx a publishes a transaction at the next available nonce in
	// order to clear any transactions in the mempool left over from a prior
	// running instance of the batch submitter.
	ClearPendingTx(context.Context, txmgr.TxManager, *ethclient.Client) error

	// GetBatchBlockRange returns the start and end L2 block heights that
	// need to be processed. Note that the end value is *exclusive*,
	// therefore if the returned values are identical nothing needs to be
	// processed.
	GetBatchBlockRange(ctx context.Context) (*big.Int, *big.Int, error)

	// CraftBatchTx transforms the L2 blocks between start and end into a batch
	// transaction using the given nonce. A dummy gas price is used in the
	// resulting transaction to use for size estimation. The driver may return a
	// nil value for transaction if there is no action that needs to be
	// performed.
	//
	// NOTE: This method SHOULD NOT publish the resulting transaction.
	CraftBatchTx(
		ctx context.Context,
		start, end, nonce *big.Int,
	) (*types.Transaction, error)

	// UpdateGasPrice signs an otherwise identical txn to the one provided but
	// with updated gas prices sampled from the existing network conditions.
	//
	// NOTE: Thie method SHOULD NOT publish the resulting transaction.
	UpdateGasPrice(
		ctx context.Context,
		tx *types.Transaction,
	) (*types.Transaction, error)

	// SendTransaction injects a signed transaction into the pending pool for
	// execution.
	SendTransaction(ctx context.Context, tx *types.Transaction) error
}

Driver is an interface for creating and submitting batch transactions for a specific contract.

type ManagedKey

type ManagedKey struct {
	// KMS uses a slash-separated path for identification.
	// This field is read-only.
	KeyName string
	// Each (public) key maps to one address on the blockchain.
	// This field is read-only.
	EthereumAddr common.Address

	Gclient *kms.KeyManagementClient
}

ManagedKey represents a key from the Key Management Service (KMS).

func NewManagedKey

func NewManagedKey(ctx context.Context, client *kms.KeyManagementClient, address string, keyName string) (*ManagedKey, error)

NewManagedKey executes a fail-fast initialization. Key names from the Google cloud are slash-separated paths.

func (*ManagedKey) NewEthereumSigner

func (mk *ManagedKey) NewEthereumSigner(ctx context.Context, txIdentification types.Signer) bind.SignerFn

NewEthereumSigner returns a KMS-backed instance. Ctx applies to the entire lifespan of the bind.SignerFn.

func (*ManagedKey) NewEthereumTransactor

func (mk *ManagedKey) NewEthereumTransactor(ctx context.Context, txIdentification types.Signer) *bind.TransactOpts

NewEthereumTransactor returns a KMS-backed instance. Ctx applies to the entire lifespan of the bind.TransactOpts.

func (*ManagedKey) NewEthereumTransactorrWithChainID

func (mk *ManagedKey) NewEthereumTransactorrWithChainID(ctx context.Context, chainID *big.Int) (*bind.TransactOpts, error)

NewEthereumTransactor returns a KMS-backed instance. Ctx applies to the entire lifespan of the bind.TransactOpts.

func (*ManagedKey) SignHash

func (mk *ManagedKey) SignHash(ctx context.Context, hash common.Hash) ([]byte, error)

SignHash returns the signature bytes.

type Service

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

func NewService

func NewService(cfg ServiceConfig) *Service

func (*Service) InitService

func (s *Service) InitService() error

func (*Service) Start

func (s *Service) Start() error

func (*Service) Stop

func (s *Service) Stop() error

type ServiceConfig

type ServiceConfig struct {
	Context         context.Context
	Driver          Driver
	PollInterval    time.Duration
	ClearPendingTx  bool
	L1Client        *ethclient.Client
	TxManagerConfig txmgr.Config
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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