docstr: See [1] for the specification of how this conversion should happen.
  
  [1] https://github.com/libp2p/specs/blob/master/peer-ids/peer-ids.md#peer-ids
docstr_tok: ["See","[","1","]","for","the","specification","of","how","this","conversion","should","happen",".","[","1","]","https",":","\/\/github.com\/libp2p\/specs\/blob\/master\/peer-ids\/peer-ids.md","#","peer-ids"]
code: def from_identity(cls, data: bytes) -> "PeerID":
      """
      See [1] for the specification of how this conversion should happen.
  
      [1] https://github.com/libp2p/specs/blob/master/peer-ids/peer-ids.md#peer-ids
      """
      key_data = crypto_pb2.PrivateKey.FromString(data).data
      private_key = serialization.load_der_private_key(
          key_data, password=None
      )
  
      encoded_public_key = private_key.public_key().public_bytes(
          encoding=serialization.Encoding.DER,
          format=serialization.PublicFormat.SubjectPublicKeyInfo,
      )
      encoded_public_key = crypto_pb2.PublicKey(
          key_type=crypto_pb2.RSA,
          data=encoded_public_key,
      ).SerializeToString()
  
      encoded_digest = multihash.encode(
          hashlib.sha256(encoded_public_key).digest(),
          multihash.coerce_code("sha2-256"),
      )
      return cls(encoded_digest)
  
imports: import hashlib
  from typing import Any, Sequence, Union
  import base58
  import multihash
  from cryptography.hazmat.primitives import serialization
  from multiaddr import Multiaddr, protocols
  from hivemind.proto import crypto_pb2, p2pd_pb2
label_desc: Use image node_id 13 for calling the PeerID obj's underlying member method code with example usage: obj.from_identity(cls, data) and returns: cls