convert method

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

Converts input and returns the result of the conversion.

Implementation

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

  if (isInvalidHrp(decoded.hrp, input.validHrp.toLowerCase())) {
    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);
}