decode static method

(BuBytes, BuBytes) decode(
  1. String? hrp,
  2. String address
)

Implementation

static (BuBytes, BuBytes) decode(String? hrp, String address) {
  final decoded = Bech32DecoderBase.decodeBech32(
    address,
    BchBech32Const.separator,
    BchBech32Const.checksumStrLen,
    _BchBech32Utils.verifyChecksum,
  );
  if (hrp != null && decoded.$1 != hrp) {
    throw BuError(
      DefaultErrorType.badBech32,
      'Incorrect bech32 hrp.',
      details: {'expected': hrp, 'hrp': decoded.$1},
    );
  }
  final convData = Bech32BaseUtils.convertFromBase32(decoded.$2);
  if (convData.isEmpty) {
    throw const BuError(
      DefaultErrorType.badBech32,
      'Invalid bech32 format.',
      details: {'reason': 'empty data payload'},
    );
  }
  final ver = convData[0];
  return (ver.toLeBytes(), convData.sublist(1));
}