decodeCheck function
Decode a base58check-encoded string into a Uint8List payload.
Implementation
Uint8List decodeCheck(String string, {String alphabet = bs58.bitcoin}) {
final bytes = bs58.decode(string, alphabet: alphabet);
if (bytes.length < 5) {
throw ArgumentError("invalid base58check");
}
Uint8List payload = bytes.sublist(0, bytes.length - 4);
Uint8List checksum = bytes.sublist(bytes.length - 4);
Uint8List newChecksum = doubleHash(payload).sublist(0, 4);
if (!bytesListEqual(checksum, newChecksum)) {
throw ArgumentError("Invalid checksum");
}
return payload;
}