isValidEthSignature static method

bool isValidEthSignature(
  1. BigInt r,
  2. BigInt s,
  3. int v, {
  4. bool homesteadOrLater = true,
  5. int chainId = -1,
})

Implementation

static bool isValidEthSignature(BigInt r, BigInt s, int v,
    {bool homesteadOrLater = true, int chainId = -1}) {
  var SECP256K1_N_DIV_2 = hexToBigInt(dynamicToHex(
      '7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0'));
  var SECP256K1_N = hexToBigInt(dynamicToHex(
      'fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141'));

  if (encodeBigInt(r).length != 32 || encodeBigInt(s).length != 32)
    return false;
  if (!isValidEthSigRecovery(calculateEthSigRecovery(v, chainId: chainId)))
    return false;
  if (r == BigInt.zero ||
      r > SECP256K1_N ||
      s == BigInt.zero ||
      s > SECP256K1_N) return false;
  if (homesteadOrLater && s > SECP256K1_N_DIV_2) return false;

  return true;
}