convert method

  1. @override
List<int> convert(
  1. String input
)
override

Converts input and returns the result of the conversion.

Implementation

@override
List<int> convert(String input) {
  if (input.length == 0) return new Uint8List(0);

  // generate base 58 index list from input string
  var input58 = List<int>.filled(input.length, 0);
  for (int i = 0; i < input.length; i++) {
    int charint = alphabet.indexOf(input[i]);
    if (charint < 0)
      throw new FormatException(
          "Invalid input formatting for Base58 decoding.");
    input58[i] = charint;
  }

  // count leading zeroes
  int leadingZeroes = 0;
  while (leadingZeroes < input58.length && input58[leadingZeroes] == 0)
    leadingZeroes++;

  // decode
  Uint8List output = new Uint8List(input.length);
  int j = output.length;
  int startAt = leadingZeroes;
  while (startAt < input58.length) {
    int mod = _divmod256(input58, startAt);
    if (input58[startAt] == 0) startAt++;
    output[--j] = mod;
  }

  // remove unnecessary leading zeroes
  while (j < output.length && output[j] == 0) j++;
  return output.sublist(j - leadingZeroes);
}