types

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2022 License: Apache-2.0 Imports: 20 Imported by: 40

Documentation

Overview

TODO: Move this package to the Go client-sdk.

Index

Constants

View Source
const (
	// CallFormatPlain is the plain text call format.
	CallFormatPlain = CallFormat(0)
	// CallFormatEncryptedX25519DeoxysII is the encrypted call format using X25519 for key exchange
	// and Deoxys-II for symmetric encryption.
	CallFormatEncryptedX25519DeoxysII = CallFormat(1)
)
View Source
const LatestTransactionVersion = 1

LatestTransactionVersion is the latest transaction format version.

View Source
const MaxDenominationSize = 32

MaxDenominationSize is the maximum length of a denomination.

Variables

View Source
var (
	// AddressV0Ed25519Context is the unique context for v0 Ed25519-based addresses.
	// It is shared with the consensus layer addresses on purpose.
	AddressV0Ed25519Context = staking.AddressV0Context
	// AddressV0Secp256k1EthContext is the unique context for v0 secp256k1-based addresses.
	AddressV0Secp256k1EthContext = address.NewContext("oasis-runtime-sdk/address: secp256k1eth", 0)
	// AddressV0Sr25519Context is the unique context for v0 Sr25519-based addresses.
	AddressV0Sr25519Context = address.NewContext("oasis-runtime-sdk/address: sr25519", 0)
	// AddressV0MultisigContext is the unique context for v0 multisig addresses.
	AddressV0MultisigContext = address.NewContext("oasis-runtime-sdk/address: multisig", 0)
	// AddressV0ModuleContext is the unique context for v0 module addresses.
	AddressV0ModuleContext = address.NewContext("oasis-runtime-sdk/address: module", 0)
	// AddressBech32HRP is the unique human readable part of Bech32 encoded
	// staking account addresses.
	AddressBech32HRP = staking.AddressBech32HRP
)
View Source
var NativeDenomination = Denomination([]byte{})

NativeDenomination is the denomination in native token.

View Source
var SignatureContextBase = []byte("oasis-runtime-sdk/tx: v0")

SignatureContextBase is the transaction signature domain separation context base.

Functions

This section is empty.

Types

type Address

type Address address.Address

Address is the account address.

func NewAddress

func NewAddress(spec SignatureAddressSpec) (a Address)

NewAddress creates a new address from the given signature address specification.

func NewAddressForModule added in v0.2.0

func NewAddressForModule(module string, kind []byte) Address

NewAddressForModule creates a new address for a specific module and raw kind.

func NewAddressFromBech32

func NewAddressFromBech32(data string) (a Address)

NewAddressFromBech32 creates a new address from the given bech-32 encoded string.

Panics in case of errors -- use UnmarshalText if you want to handle errors.

func NewAddressFromConsensus added in v0.2.0

func NewAddressFromConsensus(addr staking.Address) Address

NewAddressFromConsensus converts a consensus layer address into an address.

func NewAddressFromMultisig

func NewAddressFromMultisig(config *MultisigConfig) Address

NewAddressFromMultisig creates a new address from the given multisig configuration.

func NewAddressRaw added in v0.2.0

func NewAddressRaw(ctx address.Context, data []byte) Address

NewAddressRaw creates a new address from passed address context and data.

func (Address) ConsensusAddress added in v0.2.0

func (a Address) ConsensusAddress() staking.Address

ConsensusAddress converts this address into a consensus-layer address type.

func (Address) Equal

func (a Address) Equal(cmp Address) bool

Equal compares vs another address for equality.

func (Address) MarshalBinary

func (a Address) MarshalBinary() ([]byte, error)

MarshalBinary encodes an address into binary form.

func (Address) MarshalText

func (a Address) MarshalText() ([]byte, error)

MarshalText encodes an address into text form.

func (Address) String

func (a Address) String() string

String returns the string representation of an address.

func (*Address) UnmarshalBinary

func (a *Address) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes a binary marshaled address.

func (*Address) UnmarshalText

func (a *Address) UnmarshalText(text []byte) error

UnmarshalText decodes a text marshaled address.

type AddressSpec

type AddressSpec struct {
	// Signature is for signature authentication.
	Signature *SignatureAddressSpec `json:"signature,omitempty"`
	// Multisig is for multisig authentication.
	Multisig *MultisigConfig `json:"multisig,omitempty"`
}

AddressSpec is common information that specifies an address as well as how to authenticate.

func (*AddressSpec) Address

func (as *AddressSpec) Address() (Address, error)

Address derives the address.

func (*AddressSpec) Batch

func (as *AddressSpec) Batch(ap AuthProof) ([]PublicKey, [][]byte, error)

Batch checks that the address specification and the authentication proof are acceptable. Returns vectors of public keys and signatures for batch verification of included signatures.

type AuthInfo

type AuthInfo struct {
	SignerInfo []SignerInfo `json:"si"`
	Fee        Fee          `json:"fee"`
}

AuthInfo contains transaction authentication information.

type AuthProof

type AuthProof struct {
	// Signature is for signature authentication.
	Signature []byte `json:"signature,omitempty"`
	// Multisig is for multisig authentication.
	Multisig [][]byte `json:"multisig,omitempty"`
	// Module is a flag to use module-controlled decoding. The string is an encoding scheme name
	// that a module must handle. When using this variant, the scheme name must not be empty.
	Module string `json:"module,omitempty"`
}

AuthProof is a container for data that authenticates a transaction.

type BaseUnits

type BaseUnits struct {
	Amount       quantity.Quantity
	Denomination Denomination
	// contains filtered or unexported fields
}

BaseUnits is the token amount of given denomination in base units.

func NewBaseUnits

func NewBaseUnits(amount quantity.Quantity, denomination Denomination) BaseUnits

NewBaseUnits creates a new token amount of given denomination.

func (BaseUnits) String

func (bu BaseUnits) String() string

String returns a string representation of this token amount.

type Call

type Call struct {
	Format CallFormat      `json:"format,omitempty"`
	Method string          `json:"method,omitempty"`
	Body   cbor.RawMessage `json:"body"`
}

Call is a method call.

type CallEnvelopeX25519DeoxysII added in v0.2.0

type CallEnvelopeX25519DeoxysII struct {
	// Pk is the caller's ephemeral public key used for X25519.
	Pk [32]byte `json:"pk"`
	// Nonce.
	Nonce [deoxysii.NonceSize]byte `json:"nonce"`
	// Data is the encrypted call data.
	Data []byte `json:"data"`
}

CallEnvelopeX25519DeoxysII is a call envelope when using the EncryptedX25519DeoxysII format.

type CallFormat added in v0.2.0

type CallFormat uint8

CallFormat is the format used for encoding the call (and output) information.

type CallResult

type CallResult struct {
	Ok      cbor.RawMessage   `json:"ok,omitempty"`
	Failed  *FailedCallResult `json:"fail,omitempty"`
	Unknown cbor.RawMessage   `json:"unknown,omitempty"`
}

CallResult is the method call result.

func (*CallResult) IsSuccess

func (cr *CallResult) IsSuccess() bool

IsSuccess checks whether the call result indicates success.

func (*CallResult) IsUnknown added in v0.2.0

func (cr *CallResult) IsUnknown() bool

IsUnknown checks whether the call result is unknown.

type CallerAddress added in v0.2.0

type CallerAddress struct {
	// Address is an oasis address.
	Address *Address `json:"address,omitempty"`
	// EthAddress is an ethereum address.
	EthAddress *[20]byte `json:"eth_address,omitempty"`
}

CallerAddress is a caller address.

type Denomination

type Denomination string

Denomination is the name/type of the token.

func (Denomination) IsNative

func (d Denomination) IsNative() bool

IsNative checks whether the denomination represents the native token.

func (Denomination) MarshalBinary

func (d Denomination) MarshalBinary() ([]byte, error)

MarshalBinary encodes a denomination into binary form.

func (Denomination) String

func (d Denomination) String() string

String returns a string representation of this denomination.

func (*Denomination) UnmarshalBinary

func (d *Denomination) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes a binary marshaled denomination.

type Event added in v0.2.0

type Event struct {
	Module string
	Code   uint32
	Value  []byte
}

Event is an event emitted by a runtime in the form of a runtime transaction tag.

Key and value semantics are runtime-dependent.

func (*Event) Key added in v0.2.0

func (ev *Event) Key() EventKey

Key returns the event key.

func (*Event) UnmarshalRaw added in v0.2.0

func (ev *Event) UnmarshalRaw(key, value []byte) error

UnmarshalRaw decodes the event from a raw key/value pair.

type EventKey added in v0.2.0

type EventKey []byte

EventKey is an event tag key.

func NewEventKey added in v0.2.0

func NewEventKey(module string, code uint32) EventKey

NewEventKey generates an event tag key from a module name and event code.

func (EventKey) IsEqual added in v0.2.0

func (ek EventKey) IsEqual(other []byte) bool

IsEqual compares this event key against another for equality.

type FailedCallResult

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

FailedCallResult is a failed call result.

func (FailedCallResult) Error

func (cr FailedCallResult) Error() string

Error is a trivial implementation of error.

func (FailedCallResult) String

func (cr FailedCallResult) String() string

String returns the string representation of a failed call result.

type Fee

type Fee struct {
	Amount            BaseUnits `json:"amount"`
	Gas               uint64    `json:"gas,omitempty"`
	ConsensusMessages uint32    `json:"consensus_messages,omitempty"`
}

Fee contains the transaction fee information.

func (*Fee) GasPrice added in v0.2.0

func (f *Fee) GasPrice() *quantity.Quantity

GasPrice returns the gas price implied by the amount and gas.

type MultisigConfig

type MultisigConfig struct {
	Signers   []MultisigSigner `json:"signers"`
	Threshold uint64           `json:"threshold"`
}

MultisigConfig is a multisig configuration. A set of signers with total "weight" greater than or equal to a "threshold" can authenticate for the configuration.

func (*MultisigConfig) Batch

func (mc *MultisigConfig) Batch(signatureSet [][]byte) ([]PublicKey, [][]byte, error)

Batch checks that enough signers have signed and returns vectors of public keys and signatures for batch verification of those signatures. This internally calls `ValidateBasic`.

func (*MultisigConfig) ValidateBasic

func (mc *MultisigConfig) ValidateBasic() error

ValidateBasic performs some sanity checks. This looks at the configuration only. There is no cryptographic verification of any signatures.

type MultisigSigner

type MultisigSigner struct {
	PublicKey PublicKey `json:"public_key"`
	Weight    uint64    `json:"weight"`
}

MultisigSigner is one of the signers in a multisig configuration.

type PublicKey

type PublicKey struct {
	signature.PublicKey
}

PublicKey is a serializable public key.

func (*PublicKey) MarshalCBOR

func (pk *PublicKey) MarshalCBOR() ([]byte, error)

MarshalCBOR encodes the public key as CBOR.

func (*PublicKey) MarshalJSON

func (pk *PublicKey) MarshalJSON() ([]byte, error)

MarshalJSON encodes the public key as JSON.

func (*PublicKey) UnmarshalCBOR

func (pk *PublicKey) UnmarshalCBOR(data []byte) error

UnmarshalCBOR decodes the public key from CBOR.

func (*PublicKey) UnmarshalJSON

func (pk *PublicKey) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes the public key from JSON.

type Quantity

type Quantity = quantity.Quantity

Quantity is a arbitrary precision unsigned integer that never underflows.

type ResultEnvelopeX25519DeoxysII added in v0.2.0

type ResultEnvelopeX25519DeoxysII struct {
	// Nonce.
	Nonce [deoxysii.NonceSize]byte `json:"nonce"`
	// Data is the encrypted call data.
	Data []byte `json:"data"`
}

ResultEnvelopeX25519DeoxysII is a result envelope when using the EncryptedX25519DeoxysII format.

type RuntimeInfo

type RuntimeInfo struct {
	// ID is the runtime identifier.
	ID common.Namespace
	// ChainContext is the chain domain separation context used by the runtime.
	ChainContext signature.Context
}

RuntimeInfo is information about a runtime.

type SignatureAddressSpec added in v0.2.0

type SignatureAddressSpec struct {
	// Ed25519 address derivation compatible with the consensus layer.
	Ed25519 *ed25519.PublicKey `json:"ed25519,omitempty"`

	// Secp256k1Eth is ethereum-compatible address derivation from Secp256k1 public keys.
	Secp256k1Eth *secp256k1.PublicKey `json:"secp256k1eth,omitempty"`

	// Sr25519 address derivation.
	Sr25519 *sr25519.PublicKey `json:"sr25519,omitempty"`
}

SignatureAddressSpec is information for signature-based authentication and public key-based address derivation.

func NewSignatureAddressSpecEd25519 added in v0.2.0

func NewSignatureAddressSpecEd25519(pk ed25519.PublicKey) SignatureAddressSpec

NewSignatureAddressSpecEd25519 creates a new address specification for an Ed25519 public key.

func NewSignatureAddressSpecSecp256k1Eth added in v0.2.0

func NewSignatureAddressSpecSecp256k1Eth(pk secp256k1.PublicKey) SignatureAddressSpec

NewSignatureAddressSpecSecp256k1Eth creates a new Ethereum-compatible address specification for an Secp256k1 public key.

func NewSignatureAddressSpecSr25519 added in v0.2.0

func NewSignatureAddressSpecSr25519(pk sr25519.PublicKey) SignatureAddressSpec

NewSignatureAddressSpecSr25519 creates a new address specification for an Sr25519 public key.

func (*SignatureAddressSpec) PublicKey added in v0.2.0

func (as *SignatureAddressSpec) PublicKey() PublicKey

PublicKey returns the public key of the authentication/address derivation specification.

type SignedPublicKey added in v0.2.0

type SignedPublicKey struct {
	// PublicKey is the requested public key.
	PublicKey [32]byte `json:"key"`
	// Checksum is the checksum of the key manager state.
	Checksum []byte `json:"checksum"`
	// Signature is the Sign(sk, (key || checksum)) from the key manager.
	Signature signature.RawSignature `json:"signature"`
}

SignedPublicKey is the public key signed by the key manager.

type SignerInfo

type SignerInfo struct {
	AddressSpec AddressSpec `json:"address_spec"`
	Nonce       uint64      `json:"nonce"`
}

SignerInfo contains transaction signer information.

type Transaction

type Transaction struct {
	cbor.Versioned

	Call     Call     `json:"call"`
	AuthInfo AuthInfo `json:"ai"`
}

Transaction is a runtime transaction.

func NewTransaction

func NewTransaction(fee *Fee, method string, body interface{}) *Transaction

NewTransaction creates a new unsigned transaction.

func (*Transaction) AppendAuthMultisig

func (t *Transaction) AppendAuthMultisig(config *MultisigConfig, nonce uint64)

AppendAuthMultisig appends a new transaction signer information with a multisig address specification to the transaction.

func (*Transaction) AppendAuthSignature

func (t *Transaction) AppendAuthSignature(spec SignatureAddressSpec, nonce uint64)

AppendAuthSignature appends a new transaction signer information with a signature address specification to the transaction.

func (*Transaction) AppendSignerInfo

func (t *Transaction) AppendSignerInfo(addressSpec AddressSpec, nonce uint64)

AppendSignerInfo appends a new transaction signer information to the transaction.

func (*Transaction) PrepareForSigning

func (t *Transaction) PrepareForSigning() *TransactionSigner

func (*Transaction) ValidateBasic

func (t *Transaction) ValidateBasic() error

ValidateBasic performs basic validation on the transaction.

type TransactionSigner

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

func (*TransactionSigner) AppendSign

func (ts *TransactionSigner) AppendSign(ctx signature.Context, signer signature.Signer) error

AppendSign signs the transaction and appends the signature.

The signer must be specified in the AuthInfo.

func (*TransactionSigner) UnverifiedTransaction

func (ts *TransactionSigner) UnverifiedTransaction() *UnverifiedTransaction

UnverifiedTransaction returns the (signed) unverified transaction.

type UnverifiedTransaction

type UnverifiedTransaction struct {
	Body       []byte
	AuthProofs []AuthProof
	// contains filtered or unexported fields
}

UnverifiedTransaction is an unverified transaction.

func (*UnverifiedTransaction) Hash added in v0.2.0

func (ut *UnverifiedTransaction) Hash() hash.Hash

Hash returns the cryptographic hash of the encoded transaction.

func (*UnverifiedTransaction) Verify

Verify verifies and deserializes the unverified transaction.

Jump to

Keyboard shortcuts

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