rpc

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: AGPL-3.0 Imports: 17 Imported by: 0

README

This package contains library code to allow client applications to connect to Ten nodes via RPC.

Viewing keys

Viewing keys are generated inside the wallet extension (or other users of the ten rpc client), and then signed by the wallet (e.g. MetaMask) to which the keys relate. The keys are then are sent to the enclave via RPC and processed by:

  • checking the validity of the signature over the viewing key
  • finding the account to which this viewing key corresponds

We can do that by retrieving the signing public key from the signature. By hashing the public key, we can then determine the address of the account.

  • finally the enclave will save the viewing key (which is a public key) against the account, and use it to encrypt any sensitive requests (e.g. "eth_call" and "eth_getBalance") permitted to be viewed by that account

Client requests to the enclave are encrypted by the client with the enclave's public key and the response will be encrypted with the relevant viewing key (pre-added using the method above) so only the intended recipient can read it.

Documentation

Index

Constants

View Source
const (
	BatchNumber           = "eth_blockNumber"
	Call                  = "eth_call"
	ChainID               = "eth_chainId"
	GetBalance            = "eth_getBalance"
	GetBatchByHash        = "eth_getBlockByHash"
	GetBatchByNumber      = "eth_getBlockByNumber"
	GetCode               = "eth_getCode"
	GetTransactionByHash  = "eth_getTransactionByHash"
	GetTransactionCount   = "eth_getTransactionCount"
	GetTransactionReceipt = "eth_getTransactionReceipt"
	SendRawTransaction    = "eth_sendRawTransaction"
	EstimateGas           = "eth_estimateGas"
	GetLogs               = "eth_getLogs"
	GetStorageAt          = "eth_getStorageAt"
	GasPrice              = "eth_gasPrice"

	Health = "obscuro_health"
	Config = "obscuro_config"

	StopHost                 = "test_stopHost"
	SubscribeNamespace       = "eth"
	SubscriptionTypeLogs     = "logs"
	SubscriptionTypeNewHeads = "newHeads"

	GetBatchByTx             = "scan_getBatchByTx"
	GetLatestRollupHeader    = "scan_getLatestRollupHeader"
	GetTotalTxCount          = "scan_getTotalTransactionCount"
	GetTotalContractCount    = "scan_getTotalContractCount"
	GetPublicTransactionData = "scan_getPublicTransactionData"
	GetBatchListing          = "scan_getBatchListing"
	GetBatchListingNew       = "scan_getBatchListingNew"
	GetBlockListing          = "scan_getBlockListing"
	GetRollupListing         = "scan_getRollupListing"
	GetBatch                 = "scan_getBatch"
	GetLatestBatch           = "scan_getLatestBatch"
	GetPublicBatchByHash     = "scan_getPublicBatchByHash"
	GetBatchByHeight         = "scan_getBatchByHeight"
)

Variables

SensitiveMethods for which the RPC requests and responses should be encrypted

Functions

func IsSensitiveMethod

func IsSensitiveMethod(method string) bool

IsSensitiveMethod indicates whether the RPC method's requests and responses should be encrypted.

Types

type Client

type Client interface {
	// Call executes the named method via RPC.
	Call(result interface{}, method string, args ...interface{}) error
	// CallContext If the context is canceled before the call has successfully returned, CallContext returns immediately.
	CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error
	// Subscribe creates a subscription to the Obscuro host.
	Subscribe(ctx context.Context, namespace string, channel interface{}, args ...interface{}) (*rpc.ClientSubscription, error)
	// Stop closes the client.
	Stop()
}

Client is used by client applications to interact with the Ten node

func NewNetworkClient

func NewNetworkClient(address string) (Client, error)

NewNetworkClient returns a client that can make RPC calls to an Obscuro node

type EncRPCClient

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

EncRPCClient is a Client wrapper that implements Client but also has extra functionality for managing viewing key registration and decryption

func NewEncNetworkClient

func NewEncNetworkClient(rpcAddress string, viewingKey *viewingkey.ViewingKey, logger gethlog.Logger) (*EncRPCClient, error)

NewEncNetworkClient returns a network RPC client with Viewing Key encryption/decryption

func NewEncNetworkClientFromConn added in v0.24.0

func NewEncNetworkClientFromConn(connection *gethrpc.Client, viewingKey *viewingkey.ViewingKey, logger gethlog.Logger) (*EncRPCClient, error)

func NewEncRPCClient

func NewEncRPCClient(client Client, viewingKey *viewingkey.ViewingKey, logger gethlog.Logger) (*EncRPCClient, error)

NewEncRPCClient sets up a client with a viewing key for encrypted communication

func (*EncRPCClient) Account

func (c *EncRPCClient) Account() *gethcommon.Address

func (*EncRPCClient) BackingClient added in v0.24.0

func (c *EncRPCClient) BackingClient() Client

func (*EncRPCClient) Call

func (c *EncRPCClient) Call(result interface{}, method string, args ...interface{}) error

Call handles JSON rpc requests without a context - see CallContext for details

func (*EncRPCClient) CallContext

func (c *EncRPCClient) CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error

CallContext is the main logic to execute JSON-RPC requests, the context can be nil. - if the method is sensitive it will encrypt the args before sending the request and then decrypts the response before returning - result must be a pointer so that package json can unmarshal into it. You can also pass nil, in which case the result is ignored. - callExec handles the delegated call, allows EncClient to use the same code for calling with or without a context

func (*EncRPCClient) Stop

func (c *EncRPCClient) Stop()

func (*EncRPCClient) Subscribe

func (c *EncRPCClient) Subscribe(ctx context.Context, namespace string, ch interface{}, args ...interface{}) (*gethrpc.ClientSubscription, error)

Jump to

Keyboard shortcuts

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