That is why “it was credited to him as righteousness.”
Abram put his faith in the Lord, who attributed it to him as an act of righteousness.
For what does the scripture say? “Abraham believed God, and it was credited to him as righteousness.”
So also David declares the blessedness of the person to whom God credits righteousness apart from works: