typeddata

package
v1.64.0-beta Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 22 Imported by: 3

Documentation

Index

Constants

View Source
const EIP712V3DomainVersion = "3.0.0"

EIP712V3DomainVersion identifies the EIP-712 V3 signing domain.

View Source
const EIP712V3Salt = "0x0000000000000000000000000000000000000000000000000000000000000000"

EIP712V3Salt is the hex encoding of the bytes32 zero salt used by EIP-712 V3.

Variables

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

Functions

func ComputeTypedDataAndHash added in v1.55.1

func ComputeTypedDataAndHash(typedData TypedData) (hash, data []byte, err error)

ComputeTypedDataAndHash computes the typed data and its keccak hash for signing

func SetCodec added in v1.55.1

func SetCodec(amino *codec.LegacyAmino, proto *codec.ProtoCodec)

func SignTextValidator

func SignTextValidator(validatorData ValidatorData) (hexutil.Bytes, string)

SignTextWithValidator signs the given message which can be further recovered with the given validator. hash = keccak256("\x19\x00"${address}${data}).

Types

type NameValueType

type NameValueType struct {
	Name  string `json:"name"`
	Value any    `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 SigFormat

type SigFormat struct {
	Mime        string
	ByteVersion byte
}

type Type

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

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"`
}

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]any, 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 any, 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]any

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"`
}

func (*TypedDataDomain) Map

func (domain *TypedDataDomain) Map() map[string]any

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

type TypedDataMessage

type TypedDataMessage = map[string]any

type Types

type Types map[string][]Type

func ExtractMsgTypes added in v1.55.1

func ExtractMsgTypes(unpacker codectypes.AnyUnpacker, msgTypeName string, msg cosmtypes.Msg) (Types, error)

func SignableTypes added in v1.55.1

func SignableTypes() Types

func SignableTypesV3

func SignableTypesV3() Types

SignableTypesV3 preserves the V2 payload types and uses bytes32 for the domain salt.

type ValidatorData

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

func UnmarshalValidatorData

func UnmarshalValidatorData(data any) (ValidatorData, error)

UnmarshalValidatorData converts the bytes input to typed data

Jump to

Keyboard shortcuts

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