public static function pubKeyHashFromKey($prefix, $publicKey)
    {
        $length = strlen($publicKey);
        if ($length === 33) {
            if ($publicKey[0] !== "\x02" && $publicKey[0] !== "\x03") {
                throw new CashAddressException("Invalid public key");
            }
        } else if ($length === 65) {
            if ($publicKey[0] !== "\x04") {
                throw new CashAddressException("Invalid public key");
            }
        } else {
            throw new CashAddressException("Invalid public key");
        }

        return self::pubKeyHash($prefix, hash('ripemd160', hash('sha256', $publicKey, true), true));
    }
public static function pubKeyHashFromKey($prefix, $publicKey)
    {
        $length = strlen($publicKey);
        if ($length === 33) {
            if ($publicKey[0] !== "\x02" && $publicKey[0] !== "\x03") {
                throw new CashAddressException("Invalid public key");
            }
        } else if ($length === 65) {
            if ($publicKey[0] !== "\x04") {
                throw new CashAddressException("Invalid public key");
            }
        } else {
            throw new CashAddressException("Invalid public key");
        }

        return self::pubKeyHash($prefix, hash('ripemd160', hash('sha256', $publicKey, true), true));
    }
public static function pubKeyHashFromKey ( $ prefix , $ publicKey ) { $ length = strlen ( $ publicKey ) ; if ( $ length === 33 ) { if ( $ publicKey [ 0 ] !== "\x02" && $ publicKey [ 0 ] !== "\x03" ) { throw new CashAddressException ( "Invalid public key" ) ; } } else if ( $ length === 65 ) { if ( $ publicKey [ 0 ] !== "\x04" ) { throw new CashAddressException ( "Invalid public key" ) ; } } else { throw new CashAddressException ( "Invalid public key" ) ; } return self :: pubKeyHash ( $ prefix , hash ( 'ripemd160' , hash ( 'sha256' , $ publicKey , true ) , true ) ) ; }
This function does not validate public keys beyond their
size and prefix. It will hash the data and produce the address,
even if it's invalid. You MUST validate them elsewhere.

@param $prefix
@param $publicKey
@return string
@throws Base32Exception
@throws CashAddressException
This function does not validate public keys beyond their size and prefix . It will hash the data and produce the address even if it s invalid . You MUST validate them elsewhere .