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
- Variables
- func ComputeDomainSeparator(chainID *big.Int) [32]byte
- func Digest(domainSep [32]byte, structHash [32]byte) []byte
- func HashTransferAssets(assets []TransferAsset) ([32]byte, error)
- func NetworkChainID(networkID string) *big.Int
- func RecoverSigner(digest []byte, sig []byte) (common.Address, error)
- func RecoverSwap(chainID *big.Int, assetIn, assetOut string, ...) (common.Address, error)
- func RecoverTransfer(chainID *big.Int, to common.Address, assets []TransferAsset, maxFee *big.Int, ...) (common.Address, error)
- func RecoverWithdrawal(chainID *big.Int, asset string, amount *big.Int, targetChainID uint64, ...) (common.Address, error)
- func TransferStructHash(to common.Address, assets []TransferAsset, maxFee *big.Int, nonce uint64) ([32]byte, error)
- type TransferAsset
Constants ¶
const ( Name = "Clearnet" Version = "1" RouterHex = "0x00000000000000000000000000000000434C5200" )
Variables ¶
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 ¶
ComputeDomainSeparator computes the EIP-712 domain separator for the given chain ID.
func HashTransferAssets ¶
func HashTransferAssets(assets []TransferAsset) ([32]byte, error)
HashTransferAssets hashes the canonical EIP-712 array payload for TransferAsset[].
func NetworkChainID ¶
NetworkChainID derives a numeric EVM chain ID from a 4-byte NetworkID string. "YDEV" -> 0x59444556 -> 1497646422.
func RecoverSigner ¶
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 ¶
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.