decode static method
Decodes a base58 string into a byte-array
Implementation
static List<int> decode(String input) {
if (input.isEmpty) {
return Uint8List(0);
}
// generate base 58 index list from input string
var input58 = List<int>.generate(input.length, (int index) => 0);
for (var i = 0; i < input.length; i++) {
var charint = ALPHABET.indexOf(input[i]);
if (charint < 0) {
throw FormatException('Invalid input formatting for Base58 decoding.');
}
input58[i] = charint;
}
// count leading zeroes
var leadingZeroes = 0;
while (leadingZeroes < input58.length && input58[leadingZeroes] == 0) {
leadingZeroes++;
}
// decode
var output = Uint8List(input.length);
var j = output.length;
var startAt = leadingZeroes;
while (startAt < input58.length) {
var 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);
}