isValidAuthorizationFormat static method

bool isValidAuthorizationFormat(
  1. Authorization authorization
)

Checks if an authorization is properly formatted.

Validates:

  • Chain ID is positive
  • Address is a valid Ethereum address
  • Nonce is non-negative
  • If signed, signature components are valid

Implementation

static bool isValidAuthorizationFormat(Authorization authorization) {
  try {
    // Check chain ID
    if (authorization.chainId <= 0) return false;

    // Check address format
    if (!_isValidEthereumAddress(authorization.address)) return false;

    // Check nonce
    if (authorization.nonce < BigInt.zero) return false;

    // If signed, check signature components
    if (authorization.isSigned) {
      // Check y-parity is 0 or 1
      if (authorization.yParity != 0 && authorization.yParity != 1)
        return false;

      // Check r and s are not zero (both zero means unsigned)
      if (authorization.r == BigInt.zero && authorization.s == BigInt.zero)
        return false;

      // Check r and s are in valid range (less than secp256k1 order)
      final secp256k1Order = BigInt.parse(
        'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141',
        radix: 16,
      );
      if (authorization.r >= secp256k1Order ||
          authorization.s >= secp256k1Order) return false;
    }

    return true;
  } on Exception catch (_) {
    return false;
  }
}