There are plenty of solutions to this problem. See eg the Zerocash paper and the Zcash chain, both decade+ old now