decode static method

List<int> decode(
  1. String? hrp,
  2. String address, {
  3. Bech32Encodings encoding = Bech32Encodings.bech32,
})

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, {
  Bech32Encodings encoding = Bech32Encodings.bech32,
}) {
  final decode = Bech32DecoderBase.decodeBech32(
    address,
    Bech32Const.separator,
    Bech32Const.checksumStrLen,
    (hrp, data) => Bech32Utils.verifyChecksum(hrp, data, encoding),
  );
  if (hrp != decode.$1) {
    throw Bech32Error(
      "Incorrect bech32 hrp.",
      details: {"expected": hrp, "hrp": decode.$1},
    );
  }
  final result = Bech32BaseUtils.convertFromBase32(decode.$2);
  return result;
}