It is the kind of case that emboldens prosecutors and mesmerizes juries: a celebrity defendant authorizing a secret payoff to cover up a tryst with a porn star.

As the Manhattan district attorney’s office appears poised to seek an indictment of Donald J. Trump in just such a case, the former president is facing a daunting set of facts. His onetime fixer, Michael D. Cohen, will testify that Mr. Trump directed him to pay off the porn star, Stormy Daniels, and that the former president reimbursed Mr. Cohen and helped cover the whole thing up.

But salacious details alone do not make a case. Prosecutors must also work within the law. And the district attorney, Alvin L. Bragg, may have to pull off a difficult maneuver, connecting the hush-money cover-up — a potential violation of state law — to a federal election.

The details of any indictment that may be handed up as soon as this week are not yet known, and Mr. Bragg could charge any number of crimes. But there is a possibility that the case will rely on a legal theory that has never been evaluated by a judge.

A New York Times review and interviews with election law experts strongly suggest that New York state prosecutors have never before filed an election law case involving a federal campaign. Bringing an untested case against anyone, let alone a former president of the United States, carries the risk that a court could throw out or narrow the case.

The case could hinge on the way Mr. Trump and his company, the Trump Organization, handled reimbursing Mr. Cohen for the payment of $130,000 to Ms. Daniels. Internal Trump Organization records falsely classified the reimbursements as legal expenses, which helped conceal the purpose of the payments, according to Mr. Cohen, who said Mr. Trump knew about the misleading records. (Mr. Trump’s lawyers deny that.)

In New York, falsifying business records can be a crime, and Mr. Bragg’s office is likely to build the case around that charge, according to people with knowledge of the matter and outside legal experts. The false business records charge is the bread and butter of the district attorney’s office white-collar practice — since Mr. Bragg took office in 2022, prosecutors have filed 117 felony counts of the charge, against 29 individuals and companies, according to data kept by the office.

But for falsifying business records to be a felony, not a misdemeanor, Mr. Bragg’s prosecutors must show that Mr. Trump’s “intent to defraud” included an intent to commit or conceal a second crime. That crime could be a violation of election law, under the theory that the payout served as a donation to Mr. Trump’s campaign, because it silenced Ms. Daniels and shut down a potential sex scandal in the final stretch of the campaign.

Although the district attorney’s office need not obtain a conviction on the election law violation, or even include it in the indictment, that second crime might be the aspect of the legal theory that is most vulnerable to attack.

Mr. Trump’s lawyers have said that the theory that the money amounted to a campaign donation is fatally flawed. One of the lawyers recently argued in television interviews that Mr. Trump approved the payment to protect his family from false accusations, noting that Mr. Trump has long denied a sexual encounter with Ms. Daniels.

The lawyer, Joe Tacopina, portrayed the former president as a victim of her extortion.

“We are distorting laws to try and bag President Trump,” he said on “Good Morning America,” adding: “He had to pay money because there was going to be an allegation that was going to be publicly embarrassing to him, regardless of the campaign. There is no crime here.”

Whether hush money can amount to a campaign donation is not settled law. At the federal level, this issue arose with the prosecution of John Edwards, the former senator and presidential candidate, in a 2012 case that ended with jurors deadlocked over the majority of the charges, which prosecutors ultimately dropped.

Another case came in 2018, when Mr. Cohen pleaded guilty to federal charges involving the hush money. Because he pleaded guilty, the issue was never tested in the courts, but some campaign finance experts and conservative legal scholars have argued that the case was bogus.

“Michael Cohen Pled Guilty to Something That Is Not a Crime,” was the headline in a National Review article at the time.

Yet the text of New York election law suggests otherwise. It defines a campaign contribution, in part, as “any thing of value, made in connection” with an election.

If Mr. Bragg does pursue an election violation as the second crime, there are several unanswered questions.

For starters, it is unclear whether he would cite a federal or state election law violation, or even both. And with either choice, there could be pitfalls.

If his office uses a federal election violation as the second crime, Mr. Trump’s lawyers could argue that federal law has no place in state court. And if he uses a New York election law violation, the defense could claim that a violation of state law does not apply to a federal election — in this case, the 2016 presidential campaign.

“Generally, someone can’t be prosecuted for violating a contribution limit in a federal election in a state court,” said Richard L. Hasen, a law professor at the University of California, Los Angeles, who specializes in election law.

Mr. Bragg’s predecessor, Cyrus R. Vance Jr., grappled with the same issue. Mr. Vance’s prosecutors considered the hush-money case several times — it floated around the office so long that it became known as the “zombie case,” an idea that just wouldn’t die — and examined several secondary crimes Mr. Trump might have been seeking to conceal.

They never ruled out a hush money case, but had concerns that it might be too risky to use a federal election law violation as the second crime. Mr. Vance’s prosecutors feared a judge might find that falsifying business records could only be a felony if it aided or concealed a New York state crime, not a federal one.

Their apprehension stemmed partly from a lack of precedent — the only cases like this had ended in guilty pleas, meaning they were not tested in the courts — as well as from New York law, which suggests that federal crimes are out of bounds for New York prosecutors.

Against that backdrop, Mr. Bragg’s prosecutors appear to have taken a more favorable view of using a state election law violation, according to people with knowledge of their thinking. The laws governing elections in New York are unusual in that they explicitly apply to federal elections, not just state elections. And New York state prosecutors have secured at least one conviction in a case in which they combined falsifying business records charges with state election law crimes, though that case involved a state election, not a federal one.

Several state election law provisions appear to fit Mr. Cohen and Mr. Trump’s conduct, according to legal experts. One, state election law 14-126, makes it unlawful for someone (Mr. Trump, under this theory) to knowingly and willingly solicit another person (Mr. Cohen) to spend money in order to evade campaign contribution limits ($130,000 in hush money, well above the limits).

Another, state election law 17-152, proposed as an option by analysts at Just Security and the legal commentator Lisa Rubin, is even simpler: It makes it illegal to conspire to promote the election of any candidate “by unlawful means.”

Any state election law that the district attorney might pair with the falsifying business records charge may have to make it through a gantlet: Federal campaign finance law explicitly states that it overrides — pre-empts, in legal terminology — state election law when it comes to campaign donation limits.

That could rule out the possibility that Mr. Bragg might use 14-126, the New York law that makes it illegal to solicit campaign spending that violates contribution limits.

But there are exceptions to federal pre-emption contained in regulations from the Federal Election Commission, known as the F.E.C. And it is possible that the other law, 17-152, which makes it illegal to conspire to promote the election of any candidate “by unlawful means,” may be able to avoid triggering federal pre-emption. That law does not deal explicitly with contribution limits.

In short, it may be the strongest option for Mr. Bragg.

“It appears that this provision, which prohibits unlawfully promoting an election, could fit into one of the F.E.C. exceptions,” said Jerry H. Goldfeder, a special counsel at Stroock & Stroock & Lavan LLP and a recognized expert in New York state election law.

No matter what crimes Mr. Bragg charges, Mr. Trump’s lawyers are expected to raise a number of other legal challenges, including arguing that Mr. Bragg missed the legal deadline to file the case. Normally, the felony falsifying business records charge expires after five years.

But Mr. Bragg’s office has ways to extend that statute of limitations to cover the events stemming from the 2016 payment. New York law extends its statute of limitations to cover periods when a defendant was continuously out of state — Mr. Trump has spent much of his time since 2016 in Washington, D.C., and Florida — and former Gov. Andrew Cuomo of New York extended the state’s statute of limitations by more than a year during the pandemic.

And there are a few additional advantages for the district attorney: His case will play out in state court, with a state judge — possibly Juan M. Merchan, the even-keeled jurist who oversaw the conviction of Mr. Trump’s family business — and a jury in deep blue Manhattan.

Those factors helped to convince Mr. Goldfeder, the state election law expert, that the case could be viable.

“You know, it’s not a slam-dunk,” he said. “But I think that survives a motion to dismiss, and then let the jury decide.”