eip3009

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package eip3009 implements EIP-3009 transferWithAuthorization typed data building and signing for USDC gasless transfers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeCalldata

func EncodeCalldata(auth *Authorization) []byte

EncodeCalldata ABI-encodes the transferWithAuthorization call for on-chain submission. Layout: selector(4) + from(32) + to(32) + value(32) + validAfter(32) + validBefore(32) + nonce(32) + v(32) + r(32) + s(32).

func TypedDataHash

func TypedDataHash(
	auth *UnsignedAuth,
	chainID int64,
	usdcAddr common.Address,
) ([]byte, error)

TypedDataHash computes the EIP-712 hash to be signed for a transferWithAuthorization on the given chain and USDC contract.

func Verify

func Verify(
	auth *Authorization,
	expectedFrom common.Address,
	chainID int64,
	usdcAddr common.Address,
) error

Verify recovers the signer from the authorization signature and checks that it matches the expected from address.

Types

type Authorization

type Authorization struct {
	From        common.Address
	To          common.Address
	Value       *big.Int
	ValidAfter  *big.Int
	ValidBefore *big.Int
	Nonce       [32]byte
	V           uint8
	R, S        [32]byte
}

Authorization is a fully signed EIP-3009 transferWithAuthorization.

func Sign

func Sign(
	ctx context.Context,
	wallet WalletSigner,
	auth *UnsignedAuth,
	chainID int64,
	usdcAddr common.Address,
) (*Authorization, error)

Sign computes the typed data hash and signs it with the provided wallet.

type UnsignedAuth

type UnsignedAuth struct {
	From        common.Address
	To          common.Address
	Value       *big.Int
	ValidAfter  *big.Int
	ValidBefore *big.Int
	Nonce       [32]byte
}

UnsignedAuth holds the authorization parameters before signing.

func NewUnsigned

func NewUnsigned(
	from, to common.Address,
	value *big.Int,
	deadline time.Time,
) *UnsignedAuth

NewUnsigned creates an unsigned EIP-3009 authorization with a random nonce. validAfter is set to now; validBefore is set to the given deadline.

type WalletSigner

type WalletSigner interface {
	// SignTransaction signs raw bytes (no additional hashing).
	SignTransaction(ctx context.Context, rawTx []byte) ([]byte, error)
	// SignMessage signs an arbitrary message (applies keccak256 before signing).
	SignMessage(ctx context.Context, message []byte) ([]byte, error)
	Address(ctx context.Context) (string, error)
}

WalletSigner abstracts wallet signing to avoid direct wallet package imports.

Jump to

Keyboard shortcuts

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