decode static method

List<int> decode(
  1. String? hrp,
  2. String address
)

Decodes a Bech32-encoded address into a byte array.

This method takes a Human-Readable Part (HRP) and a Bech32-encoded address and decodes them into a byte array using the standard Bech32 decoding.

  • hrp: The expected Human-Readable Part (prefix) of the address.
  • address: The Bech32-encoded address to decode.

Returns the decoded byte array.

Throws an ArgumentException if the decoding fails or if the HRP doesn't match.

Implementation

static List<int> decode(String? hrp, String address) {
  final decode = Bech32DecoderBase.decodeBech32(
      address,
      Bech32Const.separator,
      Bech32Const.checksumStrLen,
      Bech32Utils.verifyChecksum);
  if (hrp != decode.item1) {
    throw ArgumentException(
        "Invalid format (HRP not valid, expected {$hrp}, got {${decode.item1}})");
  }
  final result = Bech32BaseUtils.convertFromBase32(decode.item2);
  return result;
}