Initial salvation comes through the encouragement of the Holy Spirit bringing us to faith and sanctification. This grace given by God is unmerited and certainly not earned. Catholic teaching is that all works are not the result of our own efforts but are produced by His grace. At judgment God will see our works produced by His grace as meritorious. Through God and His grace working in our lives we earn our salvation. Catholic teaching in regards to merit is very similar if not identical to the Protestant monergistic view, meaning that all is of God, approach rather than a synergistic approach, some of God and some of us, as Catholics get accused. The actual view of Catholics is that God does all the work and we do all the work. Catholics give all the credit to God but also understand that their response to grace is deserving of merit.
The way I see it is that we respond to God’s promises He is obligated to fulfill a debt He has incurred through His promise. We through His grace put faith and trust in those promises. Since God promises us eternal life by our faith then He has created an obligation for Himself. It is God’s promise that makes it a merit and not our work because God represents to us justice and truth and by us responding to His commands through the Spirit He has created a debt deserved by crediting us with merit even though it is through Christ and the Holy Spirit that we responded to His commands and will.