decodeAddr method

  1. @override
BuBytes decodeAddr(
  1. String addr, {
  2. List<int>? netVersion,
  3. String? hrp,
})
override

Decodes a given blockchain address string.

Throws AddressConverterException on invalid input.

Implementation

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

  final result = BchBech32Decoder.decode(hrp, addr);
  final BuBytes netVerBytesGot = result.$1;
  final BuBytes addrDecBytes = result.$2;

  // Decoded network version must match the one requested.
  if (!BytesUtils.bytesEqual(netVersion, netVerBytesGot)) {
    throw CoreErrors.addressKeyValidationFailed(
      reason: "Invalid address network version.",
    );
  }

  AddrDecUtils.validateBytesLength(
    addrDecBytes,
    QuickCrypto.hash160DigestSize,
  );
  return addrDecBytes;
}