The deal which will pave the way for hostilities to end is close to being finalised, the US, Iran and mediators Pakistan say.