decodeAddr method

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

Overrides the base class method to decode a P2WPKH address.

Implementation

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

  /// Decode the Bech32-encoded P2WPKH address, and validate its length.
  final decoded = SegwitBech32Decoder.decode(hrp, addr);
  final witVerGot = decoded.$1;
  final addrDecBytes = decoded.$2;

  /// Check the witness version.
  if (witVerGot != P2WPKHAddrConst.witnessVer) {
    throw AddressConverterException.addressValidationFailed(
      reason: "Invalid address checksum",
    );
  }

  /// Return the decoded P2WPKH address as a `List<int>`.
  return addrDecBytes;
}