decodeAddr method

  1. @override
List<int> decodeAddr(
  1. String addr, [
  2. Map<String, dynamic> kwargs = const {}
])
override

Overrides the base class method to decode a P2PKH (Pay-to-Public-Key-Hash) address.

This method decodes a P2PKH address from the provided input string using Base58 encoding. It expects an optional map of keyword arguments with 'net_ver' specifying the network version bytes, and 'base58_alph' for the Base58 alphabet. It validates the arguments, decodes the address, checks its length and network version, and returns the decoded P2PKH address as a List

Parameters:

  • addr: The P2PKH address to be decoded.
  • kwargs: Optional keyword arguments with 'net_ver' for the network version and 'base58_alph' for Base58 alphabet.

Returns: A List

Implementation

@override
List<int> decodeAddr(String addr, [Map<String, dynamic> kwargs = const {}]) {
  /// Validate network version and Base58 alphabet arguments.
  AddrKeyValidator.validateAddressArgs<List<int>>(kwargs, "net_ver");
  List<int> netVarBytes = kwargs["net_ver"];

  final Base58Alphabets alphabet =
      kwargs["base58_alph"] ?? Base58Alphabets.bitcoin;

  /// Decode the address using the specified Base58 alphabet.
  List<int> addrDecBytes = Base58Decoder.checkDecode(addr, alphabet);

  /// Validate the length of the decoded address and its network version.
  AddrDecUtils.validateBytesLength(
      addrDecBytes, QuickCrypto.hash160DigestSize + netVarBytes.length);

  /// Remove and validate the network version prefix bytes.
  return List<int>.from(
      AddrDecUtils.validateAndRemovePrefixBytes(addrDecBytes, netVarBytes));
}