checkDecode static method

List<int> checkDecode(
  1. String data, [
  2. Base58Alphabets base58alphabets = Base58Alphabets.bitcoin
])

Decode and verify the provided Base58 encoded data into a List

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

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(
      "Invalid checksum (expected ${BytesUtils.toHexString(computedChecksum)}, got ${BytesUtils.toHexString(checksumBytes)})",
    );
  }

  return dataBytes;
}