Documentation
¶
Index ¶
- Variables
- func TypedDataAndHash(typedData TypedData) ([]byte, string, error)
- type NameValueType
- type Type
- type TypePriority
- type TypedData
- func (typedData *TypedData) Dependencies(primaryType string, found []string) []string
- func (typedData *TypedData) EncodeData(primaryType string, data map[string]interface{}, depth int) (hexutil.Bytes, error)
- func (typedData *TypedData) EncodePrimitiveValue(encType string, encValue interface{}, depth int) ([]byte, error)
- func (typedData *TypedData) EncodeType(primaryType string) hexutil.Bytes
- func (typedData *TypedData) Format() ([]*NameValueType, error)
- func (typedData *TypedData) HashStruct(primaryType string, data TypedDataMessage) (hexutil.Bytes, error)
- func (typedData *TypedData) Map() map[string]interface{}
- func (typedData *TypedData) TypeHash(primaryType string) hexutil.Bytes
- type TypedDataDomain
- type TypedDataMessage
- type Types
Constants ¶
This section is empty.
Variables ¶
var (
Uint256, _ = abi.NewType("uint256", "", nil)
Uint32, _ = abi.NewType("uint32", "", nil)
Uint16, _ = abi.NewType("uint16", "", nil)
Uint8, _ = abi.NewType("uint8", "", nil)
String, _ = abi.NewType("string", "", nil)
Bool, _ = abi.NewType("bool", "", nil)
Bytes, _ = abi.NewType("bytes", "", nil)
Bytes32, _ = abi.NewType("bytes32", "", nil)
Address, _ = abi.NewType("address", "", nil)
Uint64Arr, _ = abi.NewType("uint64[]", "", nil)
AddressArr, _ = abi.NewType("address[]", "", nil)
Int8, _ = abi.NewType("int8", "", nil)
Int16T, _ = abi.NewType("int16", "", nil)
Bytes1T, _ = abi.NewType("bytes1", "", nil)
)
Types solidity=>go types Src: https://github.com/ethereum/go-ethereum/blob/master/accounts/abi/abi_test.go
Functions ¶
func TypedDataAndHash ¶
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 TypePriority ¶
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 ¶
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 ¶
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
type TypedDataDomain ¶
type TypedDataDomain struct {
Name string `json:"name"`
Version string `json:"version"`
ChainId string `json:"chainId"` // Decimal string for Cobo compatibility
VerifyingContract string `json:"verifyingContract"`
Salt string `json:"salt"`
}
TypedDataDomain represents the domain part of an EIP-712 message. Modified for Cobo compatibility: ChainId is string (decimal) instead of *math.HexOrDecimal256
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{}