decode static method

List<int> decode(
  1. String dataStr
)

Decode the provided Monero Base58 encoded dataStr into a BytesData of dataBytes.

Implementation

static List<int> decode(String dataStr) {
  List<int> dec = List.empty();

  /// Get lengths
  final dataLen = dataStr.length;
  const blockDecLen = Base58XmrConst.blockDecMaxByteLen;
  const blockEncLen = Base58XmrConst.blockEncMaxByteLen;

  /// Compute block count and last block length
  final totBlockCnt = dataLen ~/ blockEncLen;
  final lastBlockEncLen = dataLen % blockEncLen;

  /// Get last block decoded length
  final lastBlockDecLen =
      Base58XmrConst.blockEncByteLens.indexOf(lastBlockEncLen);

  /// Decode each single block and unpad
  for (var i = 0; i < totBlockCnt; i++) {
    final blockDec = Base58Decoder.decode(
        dataStr.substring(i * blockEncLen, (i + 1) * blockEncLen));
    dec = List<int>.from([...dec, ..._unPad(blockDec, blockDecLen)]);
  }

  /// Decode last block and unpad
  if (lastBlockEncLen > 0) {
    final blockDec = Base58Decoder.decode(dataStr.substring(
        totBlockCnt * blockEncLen,
        totBlockCnt * blockEncLen + lastBlockEncLen));
    dec = List<int>.from([...dec, ..._unPad(blockDec, lastBlockDecLen)]);
  }

  return dec;
}