eip712

package
v0.0.0-...-54fe0b3 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyString   = &decError{"empty hex string"}
	ErrSyntax        = &decError{"invalid hex string"}
	ErrMissingPrefix = &decError{"hex string without 0x prefix"}
	ErrOddLength     = &decError{"hex string of odd length"}
	ErrEmptyNumber   = &decError{"hex string \"0x\""}
	ErrLeadingZero   = &decError{"hex number with leading zero digits"}
	ErrUint64Range   = &decError{"hex number > 64 bits"}
	ErrUintRange     = &decError{fmt.Sprintf("hex number > %d bits", uintBits)}
	ErrBig256Range   = &decError{"hex number > 256 bits"}
)

Errors

View Source
var (
	Big1   = big.NewInt(1)
	Big2   = big.NewInt(2)
	Big3   = big.NewInt(3)
	Big0   = big.NewInt(0)
	Big32  = big.NewInt(32)
	Big256 = big.NewInt(256)
	Big257 = big.NewInt(257)
)

Common big integers often used

View Source
var (
	MaxBig256 = new(big.Int).Set(tt256m1)
	MaxBig63  = new(big.Int).Sub(tt63, big.NewInt(1))
)

Various big integer limit values.

Functions

func BigPow

func BigPow(a, b int64) *big.Int

BigPow returns a ** b as a big integer.

func Decode

func Decode(input string) ([]byte, error)

Decode decodes a hex string with 0x prefix.

func Keccak256

func Keccak256(data ...[]byte) []byte

Keccak256 calculates and returns the Keccak256 hash of the input data.

func PaddedBigBytes

func PaddedBigBytes(bigint *big.Int, n int) []byte

PaddedBigBytes encodes a big integer as a big-endian byte slice. The length of the slice is at least n bytes.

func ParseBig256

func ParseBig256(s string) (*big.Int, bool)

ParseBig256 parses s as a 256 bit integer in decimal or hexadecimal syntax. Leading zeros are accepted. The empty string parses as zero.

func ReadBits

func ReadBits(bigint *big.Int, buf []byte)

ReadBits encodes the absolute value of bigint as big-endian bytes. Callers must ensure that buf has enough space. If buf is too short the result will be incomplete.

func Recover

func Recover(typedData *TypedData, sig []byte) (string, error)

func Sign

func Sign(pk *ecdsa.PrivateKey, typedData *TypedData) ([]byte, error)

func U256

func U256(x *big.Int) *big.Int

U256 encodes as a 256 bit two's complement number. This operation is destructive.

func U256Bytes

func U256Bytes(n *big.Int) []byte

U256Bytes converts a big Int into a 256bit EVM number. This operation is destructive.

Types

type HexOrDecimal256

type HexOrDecimal256 big.Int

HexOrDecimal256 marshals big.Int as hex or decimal.

func NewHexOrDecimal256

func NewHexOrDecimal256(x int64) *HexOrDecimal256

NewHexOrDecimal256 creates a new HexOrDecimal256

func (*HexOrDecimal256) MarshalText

func (i *HexOrDecimal256) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (*HexOrDecimal256) UnmarshalText

func (i *HexOrDecimal256) UnmarshalText(input []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type KeccakState

type KeccakState interface {
	hash.Hash
	Read([]byte) (int, error)
}

KeccakState wraps sha3.state. In addition to the usual hash methods, it also supports Read to get a variable amount of data from the hash state. Read is faster than Sum because it doesn't copy the internal state, but also modifies the internal state.

func NewKeccakState

func NewKeccakState() KeccakState

NewKeccakState creates a new KeccakState

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 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]interface{}, depth int) ([]byte, 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) []byte

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) ([]byte, 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) []byte

TypeHash creates the keccak256 hash of the data

type TypedDataDomain

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

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

Jump to

Keyboard shortcuts

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