decodeAddr method

  1. @override
BuBytes decodeAddr(
  1. String addr, {
  2. String? hrp,
})
override

Decodes a given blockchain address string.

Throws AddressConverterException on invalid input.

Implementation

@override
BuBytes decodeAddr(String addr, {String? hrp}) {
  hrp = AddrKeyValidator.getAddrArg<String>(hrp, "hrp");

  final decode = SegwitBech32Decoder.decode(hrp, addr);
  final witVerGot = decode.$1;
  final addrDecBytes = decode.$2;

  AddrDecUtils.validateBytesLength(
    addrDecBytes,
    EcdsaKeysConst.pubKeyCompressedByteLen - 1,
  );

  if (witVerGot != P2TRConst.witnessVer) {
    throw CoreErrors.addressValidationFailed(
      reason: "Invalid address witness version.",
    );
  }

  return addrDecBytes;
}