Bech32 constructor

Bech32({
  1. required String hrp,
  2. required List<int> words,
  3. required Bech32Type type,
})

Creates an encodable object with the human-readable-part (hrp), words for the given bech32 type (bech32 or bech32m).

Implementation

Bech32({
  required String hrp, required List<int> words, required this.type,
}) : hrp = hrp.toLowerCase(), words = List.unmodifiable(words) {

  if (hrp.isEmpty) throw InvalidBech32("Missing HRP");
  _throwOnInvalidHrp(hrp);

  if (words.any((w) => w < 0 || w > 31)) {
    throw InvalidBech32("Words outside of 5-bit range");
  }

  if (hrp.length + 1 + words.length + checksumLength > maxLength) {
    throw InvalidBech32("Bech32 too long");
  }

}