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..."),
Deadline: big.NewInt(0),
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.SmartAccountEIP712Domain(chainID, accountAddress)
Domain parameters:
- Name: "CLLSmartAccount"
- Version: "1"
- ChainId: Target blockchain chain ID
- VerifyingContract: The account contract address
Index ¶
Constants ¶
const ( // EIP712DomainName is the EIP-712 domain name for all smart account contracts. EIP712DomainName = `CLLSmartAccount` // EIP712DomainVersion is the EIP-712 domain version for all smart account contracts. 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 smart account contract. It contains chainID and version metadata of the smart 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 SmartAccountEIP712Domain ¶ added in v0.6.2
func SmartAccountEIP712Domain(chainId int64, account common.Address) *EIP712Domain
SmartAccountEIP712Domain creates the EIP-712 domain for the smart account contract.
func (*EIP712Domain) Type ¶
func (d *EIP712Domain) Type() string
Type returns the EIP-712 type name for the domain.
func (*EIP712Domain) TypedData ¶
func (d *EIP712Domain) TypedData() apitypes.TypedDataDomain
TypedData returns the go-ethereum TypedDataDomain representation.
func (*EIP712Domain) Types ¶
func (d *EIP712Domain) Types() []apitypes.Type
Types returns the EIP-712 type definitions for the domain fields.
type Operation ¶
type Operation struct {
ID *big.Int `json:"id"`
Account common.Address `json:"account"`
Deadline *big.Int `json:"deadline"`
Transactions []Transaction `json:"transactions"`
}
Operation represents a batch of transactions to be executed atomically by a smart account.
func (*Operation) EIP712Message ¶
func (op *Operation) EIP712Message() apitypes.TypedDataMessage
EIP712Message returns the EIP-712 message representation of the operation.
func (*Operation) EIP712Type ¶
EIP712Type returns the EIP-712 type name for Operation.
func (*Operation) EIP712Types ¶
EIP712Types returns the EIP-712 type definitions for Operation fields.
func (*Operation) TypedData ¶
TypedData creates the EIP-712 typed data for the operation to be hashed and signed using the default CLLSmartAccount domain. Returns an error if chainId is invalid or the operation has no transactions. ChainId is parsed as int64 because go-ethereum's apitypes.TypedDataDomain uses math.HexOrDecimal256 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"`
}
Transaction represents a single transaction within an operation for EIP-712 signing.
func (*Transaction) EIP712Message ¶
func (tx *Transaction) EIP712Message() apitypes.TypedDataMessage
EIP712Message returns the EIP-712 message representation of the transaction.
func (*Transaction) EIP712Type ¶
func (tx *Transaction) EIP712Type() string
EIP712Type returns the EIP-712 type name for Transaction.
func (*Transaction) EIP712Types ¶
func (tx *Transaction) EIP712Types() []apitypes.Type
EIP712Types returns the EIP-712 type definitions for Transaction fields.