Curse of Leeching: An enchantment with max level 5, drains your health to restore durability.
Here is a breakdown of how it should work
if ((LVL > 4) or (player_health > 1)) and (durability > 0) and (tool is in main hand, off hand, or worn as armor)
drains 1 health ignoring armor, every (800/LVL)-(28*LVL) ticks, to restore 1+floor(LVL/2) durability
or a more literary version
While the tool is held in either hand or worn as armor, it will periodically, but faster depending on the level (min level's is 774 ticks, max level is 20 ticks), drain 1 health (while ignoring armor) from the player to restore the tool's durability, more durability is restored depending on the level (min level's is 2, max level's is 4). This is unable to kill the player except at level 5, which is the maximum level for the enchantment.
death message "[player] was leeched to death by their tool"
1.12.2 preferred, and thanks for viewing my post!