Paul, explaining the gospel in Romans, gives Abraham as an example, who certainly wasn't baptized, nor did he have the law of Moses, which was given hundreds of years later.
and to be sure, Abraham did good works. but God counted Abraham righteous because he believed God, not because he did any...