decode static method
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 Tuple<List<int>, List<int>> decode(String hrp, String address) {
final decode = Bech32DecoderBase.decodeBech32(
address,
BchBech32Const.separator,
BchBech32Const.checksumStrLen,
_BchBech32Utils.verifyChecksum);
if (decode.item1 != hrp) {
throw ArgumentException(
"Invalid format (HRP not valid, expected $hrp, got ${decode.item2})");
}
final convData = Bech32BaseUtils.convertFromBase32(decode.item2);
final ver = convData[0];
return Tuple(
IntUtils.toBytes(ver,
length: IntUtils.bitlengthInBytes(ver), byteOrder: Endian.little),
convData.sublist(1));
}