isValid static method

bool isValid(
  1. int accountType,
  2. String account
)

Implementation

static bool isValid(int accountType, String account) {
  assert(accountType == NanoAccountType.BANANO ||
      accountType == NanoAccountType.NANO ||
      accountType == NanoAccountType.PAW);
  assert(account != null);
  if (account == null) {
    return false;
  }
  // Ensure regex match
  RegExp regEx = RegExp(NanoAccountType.getRegex(accountType));
  if (!regEx.hasMatch(account)) {
    return false;
  }
  String expectedChecksum = account.substring(account.length - 8);
  String encodedChecksum;
  try {
    encodedChecksum = calculatedEncodedChecksum(extractPublicKey(account));
  } catch (e) {
    return false;
  }
  return expectedChecksum == encodedChecksum;
}