checkDecode static method
Decode and verify the provided Base58 encoded data into a List of data bytes using a specified Base58 alphabet.
This method verifies the checksum of the decoded data to ensure its integrity.
Parameters:
- data: The Base58 encoded string to be decoded and verified.
- base58alphabets: Optional Base58Alphabets enum to choose the alphabet (default is Base58Alphabets.bitcoin).
Returns: A List containing the decoded data bytes if the checksum is valid.
Throws:
- Base58ChecksumError: If the checksum verification fails.
Implementation
static List<int> checkDecode(
String data, [
Base58Alphabets base58alphabets = Base58Alphabets.bitcoin,
]) {
final decodedBytes = decode(data, base58alphabets);
final dataBytes = decodedBytes.sublist(
0,
decodedBytes.length - Base58Const.checksumByteLen,
);
final checksumBytes = decodedBytes.sublist(
decodedBytes.length - Base58Const.checksumByteLen,
);
final computedChecksum = Base58Utils.computeChecksum(dataBytes);
if (!BytesUtils.bytesEqual(checksumBytes, computedChecksum)) {
throw Base58ChecksumError();
}
return dataBytes;
}