Documentation
¶
Index ¶
- Constants
- Variables
- func GetRuntimePublicKey(chainID uint64) (*[32]byte, error)
- func PackCall(msg ethereum.CallMsg, cipher Cipher) (*ethereum.CallMsg, error)
- func PackSignedCall(msg ethereum.CallMsg, cipher Cipher, sign SignerFn, chainID big.Int, ...) (*ethereum.CallMsg, error)
- func PackTx(tx types.Transaction, cipher Cipher) (*types.Transaction, error)
- type Body
- type CallResult
- type Cipher
- type Curve25519KeyPair
- type Data
- type DataEnvelope
- type EncryptedBodyEnvelope
- type Error
- type Failure
- type Inner
- type Kind
- type Leash
- type NetworkParams
- type PlainCipher
- func (c PlainCipher) Decrypt(nonce []byte, ciphertext []byte) (plaintext []byte, err error)
- func (c PlainCipher) DecryptCallResult(response []byte) ([]byte, error)
- func (c PlainCipher) DecryptEncoded(response []byte) ([]byte, error)
- func (c PlainCipher) Encrypt(plaintext []byte) (ciphertext []byte, nonce []byte)
- func (c PlainCipher) EncryptEncode(plaintext []byte) []byte
- func (c PlainCipher) EncryptEnvelope(plaintext []byte) *DataEnvelope
- func (c PlainCipher) Kind() uint64
- type Request
- type Response
- type SignedCallDataPack
- type SignerFn
- type Unknown
- type WrappedBackend
- func (b WrappedBackend) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
- func (b WrappedBackend) CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error)
- func (b WrappedBackend) EstimateGas(ctx context.Context, call ethereum.CallMsg) (gas uint64, err error)
- func (b WrappedBackend) FilterLogs(ctx context.Context, query ethereum.FilterQuery) ([]types.Log, error)
- func (b WrappedBackend) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)
- func (b WrappedBackend) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)
- func (b WrappedBackend) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
- func (b WrappedBackend) SendTransaction(ctx context.Context, tx *types.Transaction) error
- func (b WrappedBackend) SubscribeFilterLogs(ctx context.Context, query ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)
- func (b WrappedBackend) SuggestGasPrice(ctx context.Context) (*big.Int, error)
- func (b WrappedBackend) SuggestGasTipCap(ctx context.Context) (*big.Int, error)
- func (b WrappedBackend) Transactor(from common.Address) *bind.TransactOpts
- type X25519DeoxysIICipher
- func (c X25519DeoxysIICipher) Decrypt(nonce []byte, ciphertext []byte) ([]byte, error)
- func (c X25519DeoxysIICipher) DecryptCallResult(response []byte) ([]byte, error)
- func (c X25519DeoxysIICipher) DecryptEncoded(response []byte) ([]byte, error)
- func (c X25519DeoxysIICipher) Encrypt(plaintext []byte) (ciphertext []byte, nonce []byte)
- func (c X25519DeoxysIICipher) EncryptEncode(plaintext []byte) []byte
- func (c X25519DeoxysIICipher) EncryptEnvelope(plaintext []byte) *EncryptedBodyEnvelope
- func (c X25519DeoxysIICipher) Kind() uint64
Constants ¶
const ( Plain = iota X25519DeoxysII = 1 )
const ( DefaultGasPrice = 100_000_000_000 // DefaultGasLimit is set on all transactions without explicit gas limit to avoid being set on signed queries by the web3 gateway. DefaultGasLimit = 30_000_000 DefaultBlockRange = 15 )
const ZeroAddress = "0x0000000000000000000000000000000000000000"
Variables ¶
var ( ErrCallFailed = errors.New("call failed in module") ErrCallResultDecode = errors.New("could not decode call result") )
var Networks = map[uint64]NetworkParams{ 0x5aff: { Name: "testnet", ChainID: *big.NewInt(0x5aff), DefaultGateway: "https://testnet.sapphire.oasis.dev", RuntimeID: "0x000000000000000000000000000000000000000000000000a6d1e3ebf60dff6c", }, 0x5afe: { Name: "mainnet", ChainID: *big.NewInt(0x5afe), DefaultGateway: "https://sapphire.oasis.dev", RuntimeID: "0x0000000000000000000000000000000000000000000000000000000000000000", }, }
Functions ¶
func GetRuntimePublicKey ¶
GetRuntimePublicKey fetches the runtime calldata public key from the default Sapphire gateway.
func PackCall ¶
PackCall prepares `msg` for being sent to Sapphire. The call will be end-to-end encrypted, but the `from` address will be zero.
func PackSignedCall ¶
func PackSignedCall(msg ethereum.CallMsg, cipher Cipher, sign SignerFn, chainID big.Int, leash Leash) (*ethereum.CallMsg, error)
PackSignedCall prepares `msg` in-place for being sent to Sapphire. The call will be end-to-end encrypted and a signature will be used to authenticate the `from` address.
func PackTx ¶
func PackTx(tx types.Transaction, cipher Cipher) (*types.Transaction, error)
PackTx prepares a regular Eth transaction for Sapphire. The transaction returned from this function is what must be signed.
Types ¶
type CallResult ¶
type Cipher ¶
type Cipher interface { Kind() uint64 Encrypt(plaintext []byte) (ciphertext []byte, nonce []byte) Decrypt(nonce []byte, ciphertext []byte) (plaintext []byte, err error) EncryptEncode(plaintext []byte) []byte DecryptEncoded(result []byte) ([]byte, error) DecryptCallResult(result []byte) ([]byte, error) }
type Curve25519KeyPair ¶
type Curve25519KeyPair struct { PublicKey [curve25519.PointSize]byte SecretKey [curve25519.ScalarSize]byte }
func NewCurve25519KeyPair ¶
func NewCurve25519KeyPair() (*Curve25519KeyPair, error)
NewCurve25519KeyPair generates a random keypair suitable for use with the X25519DeoxysII cipher.
type DataEnvelope ¶
type DataEnvelope struct { Body []byte `json:"body"` Format uint64 `json:"format,omitempty"` // reuse for now, TODO swap later }
DataEnvelope is an oasis-sdk `Call` without optional fields.
type EncryptedBodyEnvelope ¶
EncryptedBodyEnvelope is an oasis-sdk `Call` with optional fields.
type Leash ¶
type NetworkParams ¶
type PlainCipher ¶
type PlainCipher struct{}
func NewPlainCipher ¶
func NewPlainCipher() PlainCipher
func (PlainCipher) Decrypt ¶
func (c PlainCipher) Decrypt(nonce []byte, ciphertext []byte) (plaintext []byte, err error)
func (PlainCipher) DecryptCallResult ¶
func (c PlainCipher) DecryptCallResult(response []byte) ([]byte, error)
func (PlainCipher) DecryptEncoded ¶
func (c PlainCipher) DecryptEncoded(response []byte) ([]byte, error)
func (PlainCipher) Encrypt ¶
func (c PlainCipher) Encrypt(plaintext []byte) (ciphertext []byte, nonce []byte)
func (PlainCipher) EncryptEncode ¶
func (c PlainCipher) EncryptEncode(plaintext []byte) []byte
func (PlainCipher) EncryptEnvelope ¶
func (c PlainCipher) EncryptEnvelope(plaintext []byte) *DataEnvelope
func (PlainCipher) Kind ¶
func (c PlainCipher) Kind() uint64
type Response ¶
type Response struct { Error *Error `json:"error"` ID int `json:"id"` Result json.RawMessage `json:"result,omitempty"` }
type SignedCallDataPack ¶
type SignedCallDataPack struct { Data Data `json:"data"` Leash Leash `json:"leash"` Signature []byte `json:"signature"` }
SignedCallDataPack defines a signed call.
It should be encoded and sent in the `data` field of an Ethereum call.
func NewDataPack ¶
func NewDataPack(sign SignerFn, chainID uint64, caller, callee []byte, gasLimit uint64, gasPrice, value *big.Int, data []byte, leash Leash) (*SignedCallDataPack, error)
NewDataPack returns a SignedCallDataPack.
This method does not encrypt `data`, so that should be done afterwards.
func (SignedCallDataPack) Encode ¶
func (p SignedCallDataPack) Encode() []byte
func (SignedCallDataPack) EncryptEncode ¶
func (p SignedCallDataPack) EncryptEncode(cipher Cipher) []byte
type WrappedBackend ¶
type WrappedBackend struct {
// contains filtered or unexported fields
}
func NewWrappedBackend ¶
func NewWrappedBackend(backend bind.ContractBackend, chainID big.Int, cipher Cipher, sign SignerFn) WrappedBackend
func WrapClient ¶
func WrapClient(c ethclient.Client, sign SignerFn) (*WrappedBackend, error)
WrapClient wraps an ethclient.Client so that it can talk to Sapphire.
func (WrappedBackend) CallContract ¶
func (b WrappedBackend) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)
CallContract implements ContractCaller.
func (WrappedBackend) CodeAt ¶
func (b WrappedBackend) CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error)
CodeAt implements ContractCaller.
func (WrappedBackend) EstimateGas ¶
func (b WrappedBackend) EstimateGas(ctx context.Context, call ethereum.CallMsg) (gas uint64, err error)
EstimateGas implements ContractTransactor.
func (WrappedBackend) FilterLogs ¶
func (b WrappedBackend) FilterLogs(ctx context.Context, query ethereum.FilterQuery) ([]types.Log, error)
FilterLogs implements ContractFilterer.
func (WrappedBackend) HeaderByNumber ¶
HeaderByNumber implements ContractTransactor.
func (WrappedBackend) PendingCodeAt ¶
PendingCodeAt implements ContractTransactor.
func (WrappedBackend) PendingNonceAt ¶
PendingNonceAt implements ContractTransactor.
func (WrappedBackend) SendTransaction ¶
func (b WrappedBackend) SendTransaction(ctx context.Context, tx *types.Transaction) error
SendTransaction implements ContractTransactor.
func (WrappedBackend) SubscribeFilterLogs ¶
func (b WrappedBackend) SubscribeFilterLogs(ctx context.Context, query ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)
SubscribeFilterLogs implements ContractFilterer.
func (WrappedBackend) SuggestGasPrice ¶
SuggestGasPrice implements ContractTransactor.
func (WrappedBackend) SuggestGasTipCap ¶
SuggestGasTipCap implements ContractTransactor.
func (WrappedBackend) Transactor ¶
func (b WrappedBackend) Transactor(from common.Address) *bind.TransactOpts
Transactor returns a TransactOpts that can be used with Sapphire.
type X25519DeoxysIICipher ¶
type X25519DeoxysIICipher struct {
// contains filtered or unexported fields
}
X25519DeoxysIICipher is the default cipher that does what it says on the tin.
func NewX25519DeoxysIICipher ¶
func NewX25519DeoxysIICipher(keypair Curve25519KeyPair, peerPublicKey [curve25519.PointSize]byte) (*X25519DeoxysIICipher, error)
func (X25519DeoxysIICipher) Decrypt ¶
func (c X25519DeoxysIICipher) Decrypt(nonce []byte, ciphertext []byte) ([]byte, error)
func (X25519DeoxysIICipher) DecryptCallResult ¶
func (c X25519DeoxysIICipher) DecryptCallResult(response []byte) ([]byte, error)
func (X25519DeoxysIICipher) DecryptEncoded ¶
func (c X25519DeoxysIICipher) DecryptEncoded(response []byte) ([]byte, error)
func (X25519DeoxysIICipher) Encrypt ¶
func (c X25519DeoxysIICipher) Encrypt(plaintext []byte) (ciphertext []byte, nonce []byte)
func (X25519DeoxysIICipher) EncryptEncode ¶
func (c X25519DeoxysIICipher) EncryptEncode(plaintext []byte) []byte
func (X25519DeoxysIICipher) EncryptEnvelope ¶
func (c X25519DeoxysIICipher) EncryptEnvelope(plaintext []byte) *EncryptedBodyEnvelope
func (X25519DeoxysIICipher) Kind ¶
func (c X25519DeoxysIICipher) Kind() uint64