Mesoscopic Hamiltonian for Josephson traveling-wave parametric amplifiers