import hashlib


def generatePermanentID(publicPermanentKey):
    """Generate a Hidden Service's ``permanent-id``.

    From `rend-spec.txt`_ §1.3::

         "permanent-id" is the permanent identifier of the hidden service,
         consisting of 80 bits. It can be calculated by computing the hash value
         of the public hidden service key and truncating after the first 80 bits:

           permanent-id = H(public-key)[:10]

         Note: If Bob's OP has "stealth" authorization enabled (see Section 2.2),
         it uses the client key in place of the public hidden service key.

    .. _rend-spec.txt: https://gitweb.torproject.org/torspec.git/tree/rend-spec.txt
    """
    permanentID = hashlib.sha1(publicPermanentKey).digest()[:10]
    return permanentID