Bitcoin exchange Coinbase has been ordered to surrender records on customers' trades in the virtual currency to the IRS as part of a tax-avoidance probe.

A federal judge in San Francisco on Wednesday granted the agency's request for a so-called "John Doe" summons to compel Coinbase to identify all users in the US who conducted transactions between 2012 and 2015. The "John Doe" summons allows the IRS to obtain information about a group of taxpayers, even when the agency doesn't know their identities.

The ruling is the latest in a series of ups and downs that have in recent years dogged Bitcoin, which made a name for itself by allowing for anonymous transactions. Its ever-skyrocketing valuation a few years back attracted investors, but some of that enthusiasm faded after Bitcoin exchange Mt. Gox declared bankruptcy in 2014 following the reported theft of almost 750,000 customer bitcoins.

The Justice Department said in its filing in mid-November that an IRS agent had identified three cases in which cryptocurrencies were used to avoid paying taxes. Two of those cases involved Coinbase customers with millions of dollars in annual revenues, the filing alleged.

In her ruling, Judge Jacqueline Scott Corley said she found "reasonable basis for believing that such group or class of persons has failed or may have failed to comply with any provision of any internal revenue laws."

Coinbase, the largest Bitcoin exchange in the US, had opposed the request, saying it was "extremely concerned with the indiscriminate breadth of the government's request." On Wednesday, it said it had expected the ruling and now plans to fight the actual summons in court.

"We look forward to opposing the DOJ's request in court after Coinbase is served with a subpoena," the San Francisco-based exchange said in a statement. "As we previously stated, we remain concerned with our US customers' legitimate privacy rights in the face of the government's sweeping request."

In a statement Wednesday, the Justice Department defended the use of the "John Doe" summons as a necessary tool for identifying tax scofflaws.

"Tools like the John Doe summons authorized today send the clear message to US taxpayers that whatever form of currency they use -- bitcoin or traditional dollars and cents -- we will work to ensure that they are fully reporting their income and paying their fair share of taxes," Principal Deputy Assistant Attorney General Caroline D. Ciraolo, head of the Justice Department's Tax Division, said in a statement.