convert method
Converts input
and returns the result of the conversion.
Implementation
@override
String convert(Bech32 input,
[int maxLength = Bech32Validations.maxInputLength]) {
var hrp = input.hrp;
var data = input.data;
if (hrp.length +
data.length +
separator.length +
Bech32Validations.checksumLength >
maxLength) {
throw TooLong(
hrp.length + data.length + 1 + Bech32Validations.checksumLength);
}
if (hrp.isEmpty) {
throw TooShortHrp();
}
if (hasOutOfRangeHrpCharacters(hrp)) {
throw OutOfRangeHrpCharacters(hrp);
}
if (isMixedCase(hrp)) {
throw MixedCase(hrp);
}
hrp = hrp.toLowerCase();
var checksummed = data + _createChecksum(hrp, data);
if (hasOutOfBoundsChars(checksummed)) {
// TODO this could be more informative
throw OutOfBoundChars('<unknown>');
}
return hrp + separator + checksummed.map((i) => charset[i]).join();
}