By Jon Leyne
BBC News, Tehran
A week ago, Iran was condemned in the West for its ballistic missile tests
After last week's show of force by Iran, now there are growing signs that both Iran and the United States want to do some serious talking about the nuclear crisis. After the harsh rhetoric and the threats, it is a critical moment for diplomacy.
Washington has shown it means business by agreeing to send the Under-Secretary of State, William Burns, to Geneva to join talks between the European Union's foreign policy chief, Javier Solana, and Iranian negotiator Saeed Jalili on Saturday.
It is a major shift by the Bush administration, and the Iranians will understand that.
Earlier this week, President Mahmoud Ahmadinejad said he was interested in direct talks with the US.
He also said Iran was interested in an idea being floated in Washington - to open a US diplomatic mission in Tehran for the first time since the revolution.
In intriguing comments in a television interview on Monday night, Mr Ahmadinejad said he expected "something may happen soon" in US-Iranian relations.
I understand from a well placed Iranian source that Tehran may soon accept the Western proposal to freeze its nuclear programme at its current state for several weeks, in return for a deferral of new sanctions. The precise length of such a freeze is still at issue.
The issue of suspending uranium enrichment - the West's precondition for substantive talks - is more difficult, but is under active consideration. The problem for Iran is that it feels that last time it suspended the process, it received nothing in return.
For both sides, there is a lot of face-saving to be done. Iran cannot be seen to be caving in to the American demands.
For President Ahmadinejad in particular, any compromise is hard to accept, barely a year after he said the Iranian nuclear programme was an unstoppable train with no brakes.
But this time it seems he is being out-ranked by the Supreme Leader, Ayatollah Ali Khamenei.
Supreme Leader Ayatollah Ali Khamenei appears to have pulled rank
A clear signal of the supreme leader's change of position came when his foreign affairs adviser, former Foreign Minister Ali Akbar Velayati, said that Iran should accept the diplomatic package brought to Tehran recently by Mr Solana - or at least agree to negotiate on it.
It is a sign of Mr Ahmadinejad's desperation that he later claimed Mr Velayati was not speaking on behalf of the supreme leader, something he and most other people in Iran must know is not true.
Allowing a US diplomatic mission in Tehran might be one route to help Mr Ahmadinejad save face.
He can present it as a concession from Washington, and it is a move that would be hugely popular with the middle classes here.
At the moment, they have to make two separate trips to Dubai to secure their much-prized US visas.
The presence of Mr Burns in Geneva is another little diplomatic victory to sweeten the pill.
Until today, the supreme leader himself maintained a tactful silence over this latest diplomatic initiative.
Now Iranian state TV has quoted him as saying: "Iran has decided to take part in negotiations but it will not accept any threat. Iran's red lines are very clear."
Despite the tough language, the comments will probably seen as moderately encouraging by western negotiators - a sign that Iran is staking out its position before real negotiations begin.
Certainly, Ayatollah Khamenei's views are of central importance. And many influential people in Tehran believe he is now interested in serious negotiations on the nuclear issue.
"Iranians are very eager to solve the problems," one insider told me. "They are licking their lips in anticipation of a compromise."
Engagement or isolation
There is some climbing down for Washington to do as well.
The Bush administration had previously ruled out joining the nuclear talks until Iran suspended uranium enrichment, so sending an envoy to Geneva is a big turnaround.
It has always been clear that any realistic solution to the Iranian nuclear crisis would involve active US engagement.
While the Mr Solana is delegated to negotiate on the behalf of the five permanent members of the UN Security Council - the US, China, Russia, France, Britain - and Germany, there would always be doubts in Tehran about how much he speaks for the Bush administration.
On his last visit to Tehran, Mr Solana brought with him a letter signed for the first time by US Secretary of State Condoleezza Rice, as well as the foreign ministers of the five other countries he represents.
Apparently, the Iranians seized the letter and scrutinised it to make quite sure Ms Rice's signature was actually there!
These glimmers come just days after a major Iranian ballistic missile test was widely condemned, at least in the West.
Maybe the test was an attempt by hardliners to sabotage the process, maybe a show of strength before the opening of talks.
But why is the Islamic Republic suddenly open to compromise?
The government is under pressure, firstly from sanctions. And inflation in food prices here is approaching 50%. In Tehran, there are daily power cuts, water shortages, and huge queues at the petrol stations.
Even the ever-resilient Mr Ahmadinejad may be realising that not all his policies are working entirely.
Officials here would die rather than admit it, but Israel's recent military rehearsal for an attack on Iran was a wake-up call.
Just as significant, the fact that Israel is now talking with Syria, Hezbollah and the Palestinians, must also be worrying Tehran.
The government here faces the prospect of really serious isolation. Already Tehran has found that it cannot rely on Russia or China to block sanctions in the UN Security Council.
End of an administration
As for Washington, time is running out for President George W Bush. The presidential election is in less than four months away and Mr Bush will leave office before the end of January.
By opening the door to Tehran, he could do his successor an enormous favour. It is a political gamble he can take at relatively little cost, whereas the incoming president might find it a step too far or simply be too busy to engage on the issue.
But the US election presents dangers as well as possibilities.
Maybe Iran is just trying to talk out the remaining days of the Bush administration, in the hope of an easier ride, if Barack Obama is victorious.
It is not just that Mr Obama has promised to open unconditional talks with Tehran. Iranians are also encouraged by the fact that his middle name is Hussein - that of one of the most revered Shia Muslim imams. And bizarrely, Obama, in Persian, literally means "he - with - us".
Conversely, the prospect of a President Obama might provoke Israel into pre-emptive action. The dangers have been evident in the recent sabre-rattling from both sides in recent weeks.
Perhaps there is more danger of simple misunderstanding. Both sides have made it abundantly clear they want to talk, but neither is very good at listening. There are now a number of active back channels that might help.
In the past Washington and Tehran have been like two star-crossed lovers. Every time one makes an advance, the other turns away.
It appears there is another opening now. But there are also plenty of hardliners in the US and Iranian governing circles who are spoiling for a fight.
Some talk dangerously about the merits of a "limited war", others have even more ambitious military designs. Hopeful times, and dangerous times.