types

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 8 Imported by: 4

Documentation

Overview

Package types provides data structures for CREC transact operations.

This package defines the core types used for building and signing operations in the account abstraction transaction model.

Operation Structure

An Operation represents a batch of transactions to be executed atomically:

operation := &types.Operation{
    ID:      big.NewInt(1),
    Account: common.HexToAddress("0x..."),
    Transactions: []types.Transaction{
        {
            To:    common.HexToAddress("0x..."),
            Value: big.NewInt(1000000000000000000), // 1 ETH
            Data:  []byte{},
        },
    },
}

EIP-712 Typed Data

Operations are signed using EIP-712 typed data for secure, human-readable signatures. Generate typed data for signing:

typedData, err := operation.TypedData(chainID)
hash, _ := typedData.HashStruct(typedData.PrimaryType, typedData.Message)

Transaction Type

A Transaction represents a single call within an operation:

tx := types.Transaction{
    To:    common.HexToAddress("0x..."),  // Target contract
    Value: big.NewInt(0),                  // ETH value to send
    Data:  calldata,                       // Encoded function call
}

EIP-712 Domain

The EIP712Domain provides domain separation for signatures:

domain := types.SignatureVerifyingAccountEIP712Domain(chainID, accountAddress)

Domain parameters:

  • Name: "SignatureVerifyingAccount"
  • Version: "1"
  • ChainId: Target blockchain chain ID
  • VerifyingContract: The account contract address

Index

Constants

View Source
const (
	EIP712DomainName    = `SignatureVerifyingAccount`
	EIP712DomainVersion = `1`
)

Variables

This section is empty.

Functions

This section is empty.

Types

type EIP712Domain

type EIP712Domain struct {
	Name              string         `json:"name"`
	Version           string         `json:"version"`
	ChainId           int64          `json:"chainId"`
	VerifyingContract common.Address `json:"verifyingContract"`
}

EIP712Domain represents the EIP-712 domain for the Signature Verifying Account. It contains chainID and version metadata of the Signature Verifying Account contract, which are used for generating the EIP-712 typed data hash and for signing.

--------------------- ChainID Constraint ---------------------

ChainId is int64 because go-ethereum's apitypes.TypedDataDomain uses uses math.HexOrDecimal256 type for ChainID, whose constructor accepts only int64.

func SignatureVerifyingAccountEIP712Domain

func SignatureVerifyingAccountEIP712Domain(chainId int64, account common.Address) *EIP712Domain

func (*EIP712Domain) Type

func (d *EIP712Domain) Type() string

func (*EIP712Domain) TypedData

func (d *EIP712Domain) TypedData() apitypes.TypedDataDomain

func (*EIP712Domain) Types

func (d *EIP712Domain) Types() []apitypes.Type

type Operation

type Operation struct {
	ID           *big.Int       `json:"id"`
	Account      common.Address `json:"account"`
	Transactions []Transaction  `json:"transactions"`
}

func (*Operation) EIP712Message

func (op *Operation) EIP712Message() apitypes.TypedDataMessage

func (*Operation) EIP712Type

func (op *Operation) EIP712Type() string

func (*Operation) EIP712Types

func (op *Operation) EIP712Types() []apitypes.Type

func (*Operation) TypedData

func (op *Operation) TypedData(chainId string) (*apitypes.TypedData, error)

Creates the EIP-712 typed data for the operation to be hashed and signed.

--------------------- ChainID Constraint ---------------------

ChainId is parsed as int64 because go-ethereum's apitypes.TypedDataDomain uses math.HexOrDecimal256 type for ChainID, whose constructor accepts only int64.

type Transaction

type Transaction struct {
	To    common.Address `json:"to"`
	Value *big.Int       `json:"value,string"`
	Data  hexutil.Bytes  `json:"data"`
}

func (*Transaction) EIP712Message

func (tx *Transaction) EIP712Message() apitypes.TypedDataMessage

func (*Transaction) EIP712Type

func (tx *Transaction) EIP712Type() string

func (*Transaction) EIP712Types

func (tx *Transaction) EIP712Types() []apitypes.Type

Jump to

Keyboard shortcuts

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