eip712

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package eip712 provides shared EIP-712 signature verification for both the gateway (HTTP->TCP relay) and the clearnode (TCP command verification).

Index

Constants

View Source
const (
	Name      = "Clearnet"
	Version   = "1"
	RouterHex = "0x00000000000000000000000000000000434C5200"
)

Variables

View Source
var (
	RouterAddr = common.HexToAddress(RouterHex)

	DomainTypeHash = crypto.Keccak256Hash([]byte(
		"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"))

	// Per ADR-009 §6.1, every user-authorized field of an operation MUST
	// appear in its EIP-712 typehash preimage. The schema here matches the
	// authoritative table in ADR-009 §6.1; `docs/specs/edge/gateway.md §5.2`
	// is the descriptive mirror. Any relay that could otherwise mutate a
	// listed field post-signing is closed by inclusion in the preimage.
	TransferAssetTypeHash = crypto.Keccak256Hash([]byte(
		"TransferAsset(string asset,uint256 amount)"))

	TransferTypeHash = crypto.Keccak256Hash([]byte(
		"Transfer(address to,TransferAsset[] assets,uint256 maxFee,uint64 nonce)TransferAsset(string asset,uint256 amount)"))

	SwapTypeHash = crypto.Keccak256Hash([]byte(
		"Swap(string assetIn,string assetOut,uint256 amountIn,uint256 minAmountOut,uint256 maxFee,uint64 nonce)"))

	WithdrawalTypeHash = crypto.Keccak256Hash([]byte(
		"Withdrawal(string asset,uint256 amount,uint256 chainId,address recipient,uint256 maxFee,uint64 nonce)"))
)

Functions

func ComputeDomainSeparator

func ComputeDomainSeparator(chainID *big.Int) [32]byte

ComputeDomainSeparator computes the EIP-712 domain separator for the given chain ID.

func Digest

func Digest(domainSep [32]byte, structHash [32]byte) []byte

Digest computes keccak256("\x19\x01" || domainSeparator || structHash).

func HashTransferAssets

func HashTransferAssets(assets []TransferAsset) ([32]byte, error)

HashTransferAssets hashes the canonical EIP-712 array payload for TransferAsset[].

func NetworkChainID

func NetworkChainID(networkID string) *big.Int

NetworkChainID derives a numeric EVM chain ID from a 4-byte NetworkID string. "YDEV" -> 0x59444556 -> 1497646422.

func RecoverSigner

func RecoverSigner(digest []byte, sig []byte) (common.Address, error)

RecoverSigner recovers the ECDSA signer from an EIP-712 digest and signature.

func RecoverSwap

func RecoverSwap(chainID *big.Int, assetIn, assetOut string, amountIn, minAmountOut, maxFee *big.Int, nonce uint64, sig []byte) (common.Address, error)

RecoverSwap recovers the signer of a Swap EIP-712 message. Per ADR-009 §6.1: Swap(string assetIn, string assetOut, uint256 amountIn, uint256 minAmountOut, uint256 maxFee, uint64 nonce).

func RecoverTransfer

func RecoverTransfer(chainID *big.Int, to common.Address, assets []TransferAsset, maxFee *big.Int, nonce uint64, sig []byte) (common.Address, error)

RecoverTransfer recovers the signer of a Transfer EIP-712 message. Per ADR-009 §6.1: Transfer(address to, TransferAsset[] assets, uint256 maxFee, uint64 nonce).

func RecoverWithdrawal

func RecoverWithdrawal(chainID *big.Int, asset string, amount *big.Int, targetChainID uint64, recipient common.Address, maxFee *big.Int, nonce uint64, sig []byte) (common.Address, error)

RecoverWithdrawal recovers the signer of a Withdrawal EIP-712 message. Per ADR-009 §6.1: Withdrawal(string asset, uint256 amount, uint256 chainId, address recipient, uint256 maxFee, uint64 nonce).

func TransferStructHash

func TransferStructHash(to common.Address, assets []TransferAsset, maxFee *big.Int, nonce uint64) ([32]byte, error)

TransferStructHash returns the EIP-712 struct hash for the canonical multi-asset Transfer schema.

Types

type TransferAsset

type TransferAsset struct {
	Asset  string
	Amount *big.Int
}

TransferAsset is the EIP-712 projection of one TransferOp asset leg.

func NormalizeTransferAssets

func NormalizeTransferAssets(in []TransferAsset) ([]TransferAsset, error)

NormalizeTransferAssets returns a sorted, duplicate-free copy of the Transfer asset list used by the frozen EIP-712 Transfer schema.

Jump to

Keyboard shortcuts

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