Text this: Optimal verification of the Bell state and Greenberger–Horne–Zeilinger states in untrusted quantum networks