You are not at risk of getting HIV from this kind of sexual contact. HIV needs to get directly from inside one body to inside another – the virus will die very quickly when it’s exposed to the air. So, you could not have gotten HIV from this woman’s vaginal fluids being on your hand and then masturbating.
There is a small chance you could get another kind of sexually transmitted infection from this kind of sex. It’s possible to get an infection like HPV, Herpes or Syphilis this way. It is possible in theory that you could get Gonorrhea or Chlamydia this way, but we do not see that happening in practice. You can look at the “Know your chances” charts to find out more about what can be pased from different kinds of sex.
If you want to be sure you did not get these infections, it’s easy to do a urine test for Gonorrhea and Chlamydia, and a blood test for syphilis at an STI clinic. HPV and herpes are diagnosed by having a nurse or doctor examine you when you have symptoms. If you develop any bumps, blisters or sores on your penis, go into a clinic for an exam.
I don’t think you need an HIV test if this is the only activity you are worried about, but you can do one if you want to for reassurance. Because HIV tests have a “window period“, the best time to get the an HIV test is 3 weeks to 3 months after a possible exposure.
I hope that helps, please let us know if you have other questions,