rpc

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2023 License: AGPL-3.0 Imports: 21 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"

	Health = "obscuro_health"
	Config = "obscuro_config"

	GetBlockHeaderByHash = "obscuroscan_getBlockHeaderByHash"
	GetBatch             = "obscuroscan_getBatch"
	GetBatchForTx        = "obscuroscan_getBatchForTx"
	GetLatestTxs         = "obscuroscan_getLatestTransactions"
	GetTotalTxs          = "obscuroscan_getTotalTransactions"
	Attestation          = "obscuroscan_attestation"
	StopHost             = "test_stopHost"
	Subscribe            = "eth_subscribe"
	Unsubscribe          = "eth_unsubscribe"
	SubscribeNamespace   = "eth"
	SubscriptionTypeLogs = "logs"

	GetLatestRollupHeader    = "scan_getLatestRollupHeader"
	GetTotalTransactionCount = "scan_getTotalTransactionCount"
	GetTotalContractCount    = "scan_getTotalContractCount"
	GetPublicTransactionData = "scan_getPublicTransactionData"
	GetBatchListing          = "scan_getBatchListing"
	GetBlockListing          = "scan_getBlockListing"
	GetFullBatchByHash       = "scan_getBatchByHash"
)

Variables

View Source
var ErrNilResponse = errors.New("nil response received from Obscuro node")

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. (Returns `ErrNilResponse` on nil response from Node, this is used as "not found" for some method calls)
	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, result interface{}, namespace string, channel interface{}, args ...interface{}) (*rpc.ClientSubscription, error)
	// Stop closes the client.
	Stop()
}

Client is used by client applications to interact with the Obscuro 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 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) 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, _ interface{}, namespace string, ch interface{}, args ...interface{}) (*rpc.ClientSubscription, error)

Jump to

Keyboard shortcuts

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