apitypes

package
v0.0.0-...-4511306 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2022 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WARN = "WARNING"
	CRIT = "CRITICAL"
	INFO = "Info"
)

Variables

View Source
var (
	IntendedValidator = SigFormat{
		accounts.MimetypeDataWithValidator,
		0x00,
	}
	DataTyped = SigFormat{
		accounts.MimetypeTypedData,
		0x01,
	}
	ApplicationClique = SigFormat{
		accounts.MimetypeClique,
		0x02,
	}
	TextPlain = SigFormat{
		accounts.MimetypeTextPlain,
		0x45,
	}
)

Functions

func TypedDataAndHash

func TypedDataAndHash(typedData TypedData) ([]byte, string, error)

TypedDataAndHash is a helper function that calculates a hash for typed data conforming to EIP-712. This hash can then be safely used to calculate a signature.

See https://eips.ethereum.org/EIPS/eip-712 for the full specification.

This gives context to the signed typed data and prevents signing of transactions.

Types

type NameValueType

type NameValueType struct {
	Name  string      `json:"name"`
	Value interface{} `json:"value"`
	Typ   string      `json:"type"`
}

NameValueType is a very simple struct with Name, Value and Type. It's meant for simple json structures used to communicate signing-info about typed data with the UI

func (*NameValueType) Pprint

func (nvt *NameValueType) Pprint(depth int) string

Pprint returns a pretty-printed version of nvt

type SendTxArgs

type SendTxArgs struct {
	From                 common.MixedcaseAddress  `json:"from"`
	To                   *common.MixedcaseAddress `json:"to"`
	Gas                  hexutil.Uint64           `json:"gas"`
	GasPrice             *hexutil.Big             `json:"gasPrice"`
	MaxFeePerGas         *hexutil.Big             `json:"maxFeePerGas"`
	MaxPriorityFeePerGas *hexutil.Big             `json:"maxPriorityFeePerGas"`
	Value                hexutil.Big              `json:"value"`
	Nonce                hexutil.Uint64           `json:"nonce"`

	// We accept "data" and "input" for backwards-compatibility reasons.
	// "input" is the newer name and should be preferred by clients.
	// Issue detail: https://github.com/ethereum/go-ethereum/issues/15628
	Data  *hexutil.Bytes `json:"data"`
	Input *hexutil.Bytes `json:"input,omitempty"`

	// For non-legacy transactions
	AccessList *types.AccessList `json:"accessList,omitempty"`
	ChainID    *hexutil.Big      `json:"chainId,omitempty"`
}

SendTxArgs represents the arguments to submit a transaction This struct is identical to ethapi.TransactionArgs, except for the usage of common.MixedcaseAddress in From and To

func (SendTxArgs) String

func (args SendTxArgs) String() string

func (*SendTxArgs) ToTransaction

func (args *SendTxArgs) ToTransaction() *types.Transaction

ToTransaction converts the arguments to a transaction.

type SigFormat

type SigFormat struct {
	Mime        string
	ByteVersion byte
}

type Type

type Type struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

Type is the inner type of an EIP-712 message

type TypePriority

type TypePriority struct {
	Type  string
	Value uint
}

type TypedData

type TypedData struct {
	Types       Types            `json:"types"`
	PrimaryType string           `json:"primaryType"`
	Domain      TypedDataDomain  `json:"domain"`
	Message     TypedDataMessage `json:"message"`
}

TypedData is a type to encapsulate EIP-712 typed messages

func (*TypedData) Dependencies

func (typedData *TypedData) Dependencies(primaryType string, found []string) []string

Dependencies returns an array of custom types ordered by their hierarchical reference tree

func (*TypedData) EncodeData

func (typedData *TypedData) EncodeData(primaryType string, data map[string]interface{}, depth int) (hexutil.Bytes, error)

EncodeData generates the following encoding: `enc(value₁) ‖ enc(value₂) ‖ … ‖ enc(valueₙ)`

each encoded member is 32-byte long

func (*TypedData) EncodePrimitiveValue

func (typedData *TypedData) EncodePrimitiveValue(encType string, encValue interface{}, depth int) ([]byte, error)

EncodePrimitiveValue deals with the primitive values found while searching through the typed data

func (*TypedData) EncodeType

func (typedData *TypedData) EncodeType(primaryType string) hexutil.Bytes

EncodeType generates the following encoding: `name ‖ "(" ‖ member₁ ‖ "," ‖ member₂ ‖ "," ‖ … ‖ memberₙ ")"`

each member is written as `type ‖ " " ‖ name` encodings cascade down and are sorted by name

func (*TypedData) Format

func (typedData *TypedData) Format() ([]*NameValueType, error)

Format returns a representation of typedData, which can be easily displayed by a user-interface without in-depth knowledge about 712 rules

func (*TypedData) HashStruct

func (typedData *TypedData) HashStruct(primaryType string, data TypedDataMessage) (hexutil.Bytes, error)

HashStruct generates a keccak256 hash of the encoding of the provided data

func (*TypedData) Map

func (typedData *TypedData) Map() map[string]interface{}

Map generates a map version of the typed data

func (*TypedData) TypeHash

func (typedData *TypedData) TypeHash(primaryType string) hexutil.Bytes

TypeHash creates the keccak256 hash of the data

type TypedDataDomain

type TypedDataDomain struct {
	Name              string                `json:"name"`
	Version           string                `json:"version"`
	ChainId           *math.HexOrDecimal256 `json:"chainId"`
	VerifyingContract string                `json:"verifyingContract"`
	Salt              string                `json:"salt"`
}

TypedDataDomain represents the domain part of an EIP-712 message.

func (*TypedDataDomain) Map

func (domain *TypedDataDomain) Map() map[string]interface{}

Map is a helper function to generate a map version of the domain

type TypedDataMessage

type TypedDataMessage = map[string]interface{}

type Types

type Types map[string][]Type

type ValidationInfo

type ValidationInfo struct {
	Typ     string `json:"type"`
	Message string `json:"message"`
}

type ValidationMessages

type ValidationMessages struct {
	Messages []ValidationInfo
}

func (*ValidationMessages) Crit

func (vs *ValidationMessages) Crit(msg string)

func (*ValidationMessages) GetWarnings

func (v *ValidationMessages) GetWarnings() error

/ getWarnings returns an error with all messages of type WARN of above, or nil if no warnings were present

func (*ValidationMessages) Info

func (vs *ValidationMessages) Info(msg string)

func (*ValidationMessages) Warn

func (vs *ValidationMessages) Warn(msg string)

type ValidatorData

type ValidatorData struct {
	Address common.Address
	Message hexutil.Bytes
}

Jump to

Keyboard shortcuts

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