moneroBase58Decode function
Implementation
Uint8List moneroBase58Decode(String encoded) {
if (encoded.isEmpty) return Uint8List(0);
final fullBlocks = encoded.length ~/ _fullEncodedBlockSize;
final remainderChars = encoded.length % _fullEncodedBlockSize;
if (remainderChars != 0 && !_decodedBlockSizes.containsKey(remainderChars)) {
throw FormatException(
'Invalid Monero base58 string length: ${encoded.length}');
}
final remainderBytes =
remainderChars > 0 ? _decodedBlockSizes[remainderChars]! : 0;
final totalBytes = fullBlocks * _fullBlockSize + remainderBytes;
final result = Uint8List(totalBytes);
var offset = 0;
for (var i = 0; i < fullBlocks; i++) {
final start = i * _fullEncodedBlockSize;
final block = _decodeBlock(
encoded.substring(start, start + _fullEncodedBlockSize));
result.setRange(offset, offset + _fullBlockSize, block);
offset += _fullBlockSize;
}
if (remainderChars > 0) {
final start = fullBlocks * _fullEncodedBlockSize;
final block = _decodeBlock(encoded.substring(start));
result.setRange(offset, offset + remainderBytes, block);
}
return result;
}