def _serialize(self, testnet=False):
    version = (self.TESTNET_VERSION if testnet else self.MAINNET_VERSION)
    key_bytes = (self._key.compressed_bytes if isinstance(self, HDPublicKey) else (b'\x00' + bytes(self._key)))
    return (((((version.to_bytes(length=4, byteorder='big') + bytes([self.depth])) + self.parent_fingerprint) + self.index.to_bytes(length=4, byteorder='big')) + self.chain_code) + key_bytes)
def _serialize(self, testnet=False):
    version = (self.TESTNET_VERSION if testnet else self.MAINNET_VERSION)
    key_bytes = (self._key.compressed_bytes if isinstance(self, HDPublicKey) else (b'\x00' + bytes(self._key)))
    return (((((version.to_bytes(length=4, byteorder='big') + bytes([self.depth])) + self.parent_fingerprint) + self.index.to_bytes(length=4, byteorder='big')) + self.chain_code) + key_bytes)