decode static method

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

Decode a Bech32 encoded BCH address into its components: the Human-Readable Part (HRP), network version bytes, and data.

Parameters:

  • hrp: The expected Human-Readable Part (HRP) of the BCH address.
  • address: The Bech32 encoded BCH address to be decoded.

Returns: A tuple (pair) containing the network version bytes and data.

Throws:

  • ArgumentException: If the decoded HRP does not match the expected HRP.

Implementation

static (List<int>, List<int>) decode(String hrp, String address) {
  final decode = Bech32DecoderBase.decodeBech32(
    address,
    BchBech32Const.separator,
    BchBech32Const.checksumStrLen,
    _BchBech32Utils.verifyChecksum,
  );
  if (decode.$1 != hrp) {
    throw Bech32Error(
      "Incorrect bech32 hrp.",
      details: {"expected": hrp, "hrp": decode.$1},
    );
  }
  final convData = Bech32BaseUtils.convertFromBase32(decode.$2);
  final ver = convData[0];
  return (
    IntUtils.toBytes(ver, byteOrder: Endian.little),
    convData.sublist(1),
  );
}