addressHash static method

List<int> addressHash(
  1. List<int> pubKey,
  2. PubKeyModes pubKeyMode
)

Calculate the address hash from a public key and a specified public key mode.

Given a public key pubKey and a pubKeyMode, this method computes the address hash for Bitcoin addresses. It uses the P2PKH address encoder to encode the public key and then performs a double SHA-256 hash on the encoded address. The resulting hash is then truncated to the length defined in the Bip38AddrConst.addrHashLen constant.

  • pubKey: The public key for which the address hash is calculated.
  • pubKeyMode: The public key mode that specifies the type of address encoding.
  • Returns: A List

Implementation

static List<int> addressHash(List<int> pubKey, PubKeyModes pubKeyMode) {
  final address = P2PKHAddrEncoder().encodeKey(pubKey, {
    "net_ver": CoinsConf.bitcoinMainNet.params.p2pkhNetVer!,
    "pub_key_mode": pubKeyMode
  });
  return QuickCrypto.sha256DoubleHash(StringUtils.encode(address))
      .sublist(0, Bip38AddrConst.addrHashLen);
}