code: def serialize(self, private=True):
          
          if private and not self.private_key:
              raise ValueError("Cannot serialize a public key as private")
  
          if private:
              network_version = long_to_hex(
                  self.network.EXT_SECRET_KEY, 8)
          else:
              network_version = long_to_hex(
                  self.network.EXT_PUBLIC_KEY, 8)
          depth = long_to_hex(self.depth, 2)
          parent_fingerprint = self.parent_fingerprint[2:]  # strip leading 0x
          child_number = long_to_hex(self.child_number, 8)
          chain_code = self.chain_code
          ret = (network_version + depth + parent_fingerprint + child_number +
                 chain_code)
          # Private and public serializations are slightly different
          if private:
              ret += b'00' + self.private_key.get_key()
          else:
              ret += self.get_public_key_hex(compressed=True)
          return ensure_bytes(ret.lower())
docs: Serialize this key.
  
          :param private: Whether or not the serialized key should contain
              private information. Set to False for a public-only representation
              that cannot spend funds but can create children. You want
              private=False if you are, for example, running an e-commerce
              website and want to accept bitcoin payments. See the README
              for more information.
          :type private: bool, defaults to True
  
          See the spec in `deserialize` for more details.