binaryToBase58 function

String binaryToBase58(
  1. Uint8List bignum, {
  2. dynamic minDigits = 1,
})

Convert bignum to a base-58 number @param minDigits 0-pad result to this many digits

Implementation

String binaryToBase58(Uint8List bignum, {minDigits = 1}) {
  var result = [].cast<int>();
  for (var byte in bignum) {
    var carry = byte;
    for (var j = 0; j < result.length; ++j) {
      var x = (base58Map[result[j]] << 8) + carry;
      result[j] = base58Chars.codeUnitAt(x % 58);
      carry = (x ~/ 58) | 0;
    }
    while (carry != 0) {
      result.add(base58Chars.codeUnitAt(carry % 58));
      carry = (carry ~/ 58) | 0;
    }
  }
  for (var byte in bignum) {
    if (byte != 0) {
      break;
    } else {
      result.add('1'.codeUnitAt(0));
    }
  }
  return String.fromCharCodes(result.reversed.toList());
}