Hmm. I think I'd be firmly telling my kid off if they were either A or B in this situation to be honest.
I teach my kids that they are allowed to physically defend themselves, as a last resort - and that threatening behaviour is one of the things they're allowed to defend themselves against. It doesn't matter if the other person is not physically hurting them at the time - if they believe they are about to, they can defend themselves.
So I guess part of the question is whether your daughter felt physically threatened by this boy. From your description I think she didn't, just annoyed. That's understandable but that's not something you need to physically defend yourself against.
The other issue is the last resort part - she missed out a whole bunch of steps before she went straight to the physical part. You need to teach her about anger management and de-escalation techniques designed for children - e.g. first step might be "I would like some space, please take a step back" etc, progressing to "back off, leave me alone" in a louder and more assertive voice etc.
At the same time, if I were B's mother, I'd be unimpressed about the baiting and not leaving her alone. It obviously depends what was said - e.g. did the boy actually know he was annoying her? It might seem obvious to adults but 7yos are not always great at reading the room. I'd be working on that with him, and also reiterating what I've always told my kids also about getting in someone's face - you're going to get a retaliation. I'm not saying that's always right or okay, but I tell my kids about the way things are, not just how I'd like it to be!
I'm on the fence about the pushing back. I was always taught that if someone hits you, you hit them back harder! I don't teach my kids that (I take the self defence approach as I said), but I understand parents who do. So I'm not sure I could claim the moral high ground if my kid was the one who got aggressive first.
So, fault on both sides, learning to be done on both sides 🤷🏻♀️ as you'd expect, with kids! Hope your daughter is okay now - and the keyring is fixed!