Suppose that Person A is accused of a crime. Person B (unbeknownst to anybody but themselves) actually committed the crime. Suppose further that Person B is called as a witness in the case of Person A.
Would there be a way for Person B to make it apparent to the court that any conviction of Person A for the crime would be invalid, without simultaneously putting themselves on the hook for the crime?
I am asking this primarily in the context of the right to avoid self-incrimination. Could Person B say something along the lines of "I know for a fact that Person A is not guilty of this crime, but I refuse to explain why I know that, on grounds that it would incriminate me". Or, is there no way for the court to accept that Person A's conviction would be unsafe, whilst simultaneously respecting Person B's fifth amendment rights?