How do I convert camera coordinates to world coordinates?
Is a scripted version necessary to you? Because there is a very simple node setup to accomplish this:

In this image, I convert the vector 0 0 -1 from camera space into world space. If I look from the top, it will be blue, from the back it will be green, from the right (as here) it will be red. This way the color always corresponds to the orientation gizmo.