decodeChecked function

List<int> decodeChecked(
  1. String input
)

Implementation

List<int> decodeChecked(String input) {

    List<int> decoded  = decode(input);
    if (decoded.length < 4)
        throw new AddressFormatException("Input too short");


    List<int> data = decoded.sublist(0, decoded.length - 4);
    List<int> checksum = decoded.sublist(decoded.length - 4, decoded.length);
    List<int> actualChecksum = sha256Twice(data).sublist(0, 4);

    var byteConverted = actualChecksum.map((elem) => elem.toSigned(8)); //convert unsigned list back to signed
    if ( !IterableEquality().equals(checksum ,byteConverted) )
        throw new BadChecksumException("Checksum does not validate");

    return data;
}