encodeBech32 function
Function to encode data as a Bech32 string.
Implementation
String? encodeBech32(String hrp, Uint8List data, int? version) {
final type = (version ?? 0) == 0 ? Bech32Type.bech32 : Bech32Type.bech32M;
List<int>? bits = convertBits(data, 8, 5);
if (bits == null) {
return null;
}
if (version != null) {
bits = [version, ...bits];
}
final en = _bech32Encode(hrp, bits, type);
if (decodeBech32(en, versifyVersion: version != null) == null) {
return null;
}
return en;
}