decodeCheck static method

Uint8List decodeCheck(
  1. VersionByte versionByte,
  2. String encData
)

Implementation

static Uint8List decodeCheck(VersionByte versionByte, String encData) {
  Uint8List decoded = Base32.decode(encData);
  int decodedVersionByte = decoded[0];
  Uint8List payload =
      Uint8List.fromList(decoded.getRange(0, decoded.length - 2).toList());
  Uint8List data =
      Uint8List.fromList(payload.getRange(1, payload.length).toList());
  Uint8List checksum = Uint8List.fromList(
      decoded.getRange(decoded.length - 2, decoded.length).toList());

  if (decodedVersionByte != versionByte.getValue()) {
    throw new FormatException("Version byte is invalid");
  }

  Uint8List expectedChecksum = StrKey.calculateChecksum(payload);

  if (!ListEquality().equals(expectedChecksum, checksum)) {
    throw new FormatException("Checksum invalid");
  }

  return data;
}