convert method

  1. @override
Segwit convert(
  1. String input
)
override

Converts input and returns the result of the conversion.

Implementation

@override
Segwit convert(String input) {
  var decoded = bech32.decode(input);

  if (isInvalidHrp(decoded.hrp)) {
    throw InvalidHrp();
  }

  if (isEmptyProgram(decoded.data)) {
    throw InvalidProgramLength('empty');
  }

  var version = decoded.data[0];

  if (isInvalidVersion(version)) {
    throw InvalidWitnessVersion(version);
  }

  var program = _convertBits(decoded.data.sublist(1), 5, 8, false);

  if (isTooShortProgram(program)) {
    throw InvalidProgramLength('too short');
  }

  if (isTooLongProgram(program)) {
    throw InvalidProgramLength('too long');
  }

  if (isWrongVersion0Program(version, program)) {
    throw InvalidProgramLength(
        'version $version invalid with length ${program.length}');
  }

  return Segwit(decoded.hrp, version, program);
}