isValid method

bool isValid()

Verify the structure of an address @param {String} address to control

Implementation

bool isValid() {
  if (address == null) {
    return false;
  }
  if (address!.length != kAddressLength) {
    return false;
  }
  if (address!.length >= 4 && isHex(address!)) {
    final curveType = address!.substring(0, 2);
    if (curveType != '00' && curveType != '01' && curveType != '02') {
      return false;
    }
    var digestSize = 0;
    switch (address!.substring(2, 4)) {

      /// 00 = sha256
      case '00':
        digestSize = Digest('SHA-256').digestSize;
        break;

      /// 01 = sha512
      case '01':
        digestSize = Digest('SHA-512').digestSize;
        break;

      /// 02 = sha3-256
      case '02':
        digestSize = Digest('SHA3-256').digestSize;
        break;

      /// 03 = sha3-512
      case '03':
        digestSize = Digest('SHA3-512').digestSize;
        break;

      /// 04 = blake2b
      case '04':
        digestSize = Digest('Blake2b').digestSize;
        break;
      default:
        return false;
    }
    try {
      if (Uint8List.fromList(hexToUint8List(address!.substring(4))).length !=
          digestSize) {
        return false;
      } else {
        return true;
      }
    } catch (e) {
      return false;
    }
  } else {
    return false;
  }
}