tdata

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2023 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

nolint

Index

Constants

This section is empty.

Variables

View Source
var EIP712Domain = []Type{
	{Name: "name", Type: "string"},
	{Name: "magic", Type: "uint64"},
}

Functions

func DigestHash

func DigestHash(td *TypedData) ([]byte, error)

Types

type Type

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

Type is the inner type of an EIP-712 message

type TypedData

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

func CreateTypedData

func CreateTypedData(magic uint64, txType string, txFields []Type, msg TypedDataMessage) *TypedData

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) 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"`
	Magic string `json:"magic"`
}

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

func (*TypedDataDomain) Map

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

Checks if the primitive value is valid 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

Jump to

Keyboard shortcuts

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