encodeBech32 method

  1. @override
String encodeBech32(
  1. String hex,
  2. String hrp
)
override

Encodes a hex string into a bech32 string with a hrp human readable part.

final npubString = Nostr.instance.keysService.encodeBech32(yourHexString, 'npub');
print(npubString); // ...

Implementation

@override
String encodeBech32(String hex, String hrp) {
  final bytes = HEX.decode(hex);
  final fiveBitWords = _convertBits(bytes, 8, 5, true);

  return bech32.encode(Bech32(hrp, fiveBitWords), hex.length + hrp.length);
}