sapphire

package
v0.0.0-...-0f47a2f Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2023 License: ISC Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Plain          = iota
	X25519DeoxysII = 1
)
View Source
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
)
View Source
const ZeroAddress = "0x0000000000000000000000000000000000000000"

Variables

View Source
var (
	ErrCallFailed       = errors.New("call failed in module")
	ErrCallResultDecode = errors.New("could not decode call result")
)

Functions

func UseLogger

func UseLogger(sLogger btclog.Logger)

UseLogger sets the subsystem logs to use the provided loggers.

Types

type AeadEnvelope

type AeadEnvelope struct {
	Nonce []byte `json:"nonce"`
	Data  []byte `json:"data"`
}

type Body

type Body struct {
	PK    []byte `json:"pk"`
	Data  []byte `json:"data"`
	Nonce []byte `json:"nonce"`
}

type CallDataPublicKey

type CallDataPublicKey struct {
	// PublicKey is the requested public key.
	PublicKey hexutil.Bytes `json:"key"`
	// Checksum is the checksum of the key manager state.
	Checksum hexutil.Bytes `json:"checksum"`
	// Signature is the Sign(sk, (key || checksum)) from the key manager.
	Signature hexutil.Bytes `json:"signature"`
}

CallDataPublicKey is the public key alongside the key manager's signature.

type CallResult

type CallResult struct {
	Fail    *Failure      `json:"failure,omitempty"`
	OK      []byte        `json:"ok,omitempty"`
	Unknown *AeadEnvelope `json:"unknown,omitempty"`
}

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)
}

func NewCipher

func NewCipher(ctx context.Context, net utils.NetworkType) (Cipher, error)

NewCipher creates a default cipher.

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 Data

type Data struct {
	Body []byte `json:"body"`
}

Data is the plain data in the datapack.

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

type EncryptedBodyEnvelope struct {
	Body   Body   `json:"body"`
	Format uint64 `json:"format"`
}

EncryptedBodyEnvelope is an oasis-sdk `Call` with optional fields.

type Error

type Error struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

type Failure

type Failure struct {
	Module  string `json:"module"`
	Code    uint64 `json:"code"`
	Message string `json:"message,omitempty"`
}

type Inner

type Inner struct {
	Fail *Failure `json:"fail"`
	OK   []byte   `json:"ok"`
}

type Kind

type Kind uint64

type Leash

type Leash struct {
	Nonce       uint64 `json:"nonce"`
	BlockNumber uint64 `json:"block_number"`
	BlockHash   []byte `json:"block_hash"`
	BlockRange  uint64 `json:"block_range"`
}

func NewLeash

func NewLeash(nonce uint64, blockNumber uint64, blockHash []byte, blockRange uint64) Leash

type Request

type Request struct {
	Version string      `json:"jsonrpc"`
	Method  string      `json:"method"`
	Params  interface{} `json:"params"`
	ID      int         `json:"id"`
}

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, privateKey []byte, 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 SignerFn

type SignerFn = func(digest [32]byte, privateKey []byte) ([]byte, error)

SignerFn is a function that produces secp256k1 signatures in RSV format.

type WrappedBackend

type WrappedBackend struct {
	bind.ContractBackend
	// contains filtered or unexported fields
}

func WrapClient

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 executes a Sapphire paratime contract call with the specified data as the input. CallContract implements ContractCaller.

func (*WrappedBackend) EstimateGas

func (b *WrappedBackend) EstimateGas(ctx context.Context, call ethereum.CallMsg) (gas uint64, err error)

EstimateGas implements ContractTransactor.

func (*WrappedBackend) SetClientSigningKey

func (b *WrappedBackend) SetClientSigningKey(privateKey []byte)

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

Jump to

Keyboard shortcuts

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