services

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2025 License: AGPL-3.0 Imports: 29 Imported by: 0

README

Implement session keys - guide for app developers

If the user selects "no-click UX" (or something) when the game starts, do the following:

  1. call eth_getStorageAt with the address 0x0000000000000000000000000000000000000003 (the other parameters don't matter). This will return the address of the session key.
  2. Create a transaction that transfers some eth to this address. (Maybe you ask the user to decide how many moves they want to prepay or something). The user has to sign this in their wallet. Then submit the tx.
  3. Once the receipt is received you call eth_getStorageAt with 0x0000000000000000000000000000000000000004 . This means that you tell the gateway to activate the session key.
  4. All the moves made by the user now can be sent with eth_sendRawTransaction or eth_sendTransaction unsigned. They will be signed by the gateway with the session key.
  5. When the game is finished create a tx that moves the funds back from the SK to the main address. This will get singed with the SK by the gateeway
  6. Call: eth_getStorageAt with 0x0000000000000000000000000000000000000005 - this deactivates the key.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithEncRPCConnection

func WithEncRPCConnection[R any](ctx context.Context, rpc *BackendRPC, acct *wecommon.GWAccount, execute func(*tenrpc.EncRPCClient) (*R, error)) (*R, error)

func WithPlainRPCConnection

func WithPlainRPCConnection[R any](ctx context.Context, b *BackendRPC, execute func(client *rpc.Client) (*R, error)) (*R, error)

Types

type BackendRPC

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

func NewBackendRPC

func NewBackendRPC(hostAddrHTTP string, hostAddrWS string, logger gethlog.Logger) *BackendRPC

func (*BackendRPC) ConnectHttp

func (rpc *BackendRPC) ConnectHttp(ctx context.Context, account *wecommon.GWAccount) (*tenrpc.EncRPCClient, error)

func (*BackendRPC) ConnectWS

func (rpc *BackendRPC) ConnectWS(ctx context.Context, account *wecommon.GWAccount) (*tenrpc.EncRPCClient, error)

func (*BackendRPC) PlainConnectWs

func (rpc *BackendRPC) PlainConnectWs(ctx context.Context) (*gethrpc.Client, error)

func (*BackendRPC) ReturnConn

func (rpc *BackendRPC) ReturnConn(conn tenrpc.Client) error

func (*BackendRPC) ReturnConnWS

func (rpc *BackendRPC) ReturnConnWS(conn tenrpc.Client) error

func (*BackendRPC) Stop

func (rpc *BackendRPC) Stop()

type NewHeadNotifier

type NewHeadNotifier interface {
	// contains filtered or unexported methods
}

type SKManager added in v1.0.0

type SKManager interface {
	CreateSessionKey(user *common.GWUser) (*common.GWSessionKey, error)
	ActivateSessionKey(user *common.GWUser) (bool, error)
	DeactivateSessionKey(user *common.GWUser) (bool, error)
	DeleteSessionKey(user *common.GWUser) (bool, error)
	SignTx(ctx context.Context, user *common.GWUser, input *types.Transaction) (*types.Transaction, error)
}

SKManager - session keys are Private Keys managed by the Gateway At the moment, each user can have a single Session Key. Which is either active or inactive when the SK is active, then all transactions submitted by that user will be signed with the session key The SK is also considered an "Account" of that user when the SK is created, it signs over the VK of the user so that it can interact with a node the standard way From the POV of the Ten network - a session key is a normal account key

func NewSKManager added in v1.0.0

func NewSKManager(storage storage.UserStorage, config *common.Config, logger gethlog.Logger) SKManager

type Services

type Services struct {
	HostAddrHTTP string // The HTTP address on which the TEN host can be reached
	HostAddrWS   string // The WS address on which the TEN host can be reached
	Storage      storage.UserStorage

	RPCResponsesCache cache.Cache
	BackendRPC        *BackendRPC
	RateLimiter       *ratelimiter.RateLimiter
	SKManager         SKManager
	Config            *common.Config
	NewHeadsService   *subscriptioncommon.NewHeadsService

	MetricsTracker metrics.Metrics
	// contains filtered or unexported fields
}

Services handles the various business logic for the api endpoints

func NewServices

func NewServices(hostAddrHTTP string, hostAddrWS string, storage storage.UserStorage, stopControl *stopcontrol.StopControl, version string, logger gethlog.Logger, metricsTracker metrics.Metrics, config *common.Config) *Services

func (*Services) AddAddressToUser

func (w *Services) AddAddressToUser(userID []byte, address string, signature []byte, signatureType viewingkey.SignatureType) error

AddAddressToUser checks if a message is in correct format and if signature is valid. If all checks pass we save address and signature against userID

func (*Services) GenerateAndStoreNewUser

func (w *Services) GenerateAndStoreNewUser() ([]byte, error)

GenerateAndStoreNewUser generates new key-pair and userID, stores it in the database and returns hex encoded userID and error

func (*Services) GenerateUserMessageToSign

func (w *Services) GenerateUserMessageToSign(encryptionToken []byte, formatsSlice []string) (string, error)

func (*Services) GetTenNetworkConfig

func (w *Services) GetTenNetworkConfig() (tencommon.TenNetworkInfo, error)

func (*Services) GetTenNodeHealthStatus

func (w *Services) GetTenNodeHealthStatus() (bool, error)

func (*Services) IsStopping

func (w *Services) IsStopping() bool

IsStopping returns whether the WE is stopping

func (*Services) Logger

func (w *Services) Logger() gethlog.Logger

Logger returns the WE set logger

func (*Services) Stop

func (w *Services) Stop()

func (*Services) UserExists

func (w *Services) UserExists(userID []byte) bool

func (*Services) UserHasAccount

func (w *Services) UserHasAccount(userID []byte, address string) (bool, error)

UserHasAccount checks if provided account exist in the database for given userID

func (*Services) Version

func (w *Services) Version() string

Jump to

Keyboard shortcuts

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