Quantum theory of the nonlinear Hall effect