Hamas has agreed to a ceasefire deal, in which half the hostages being held in Gaza will be freed in return for Israel releasing some Palestinian prisoners, according to senior diplomats.