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 decoded = SegwitBech32Decoder.decode(hrp, addr);
  final witVerGot = decoded.$1;
  final addrDecBytes = decoded.$2;

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

  return addrDecBytes;
}