My question is similar to this one, but the difference is that I already had a lot of code ready when I was first asked about the task. Not sure it makes any difference though.
At my work I was asked to find a solution for a problem, either free or paid. I looked at many options on the web and they were all suboptimal at best. Then I realized that during my college/pre-work years I wrote a small generic library that can be used for this task. It was about 80% usable already, but required some improvements.
Since it was mostly done, I didn't feel like I should simply give it off to my company. Also I felt this problem is very generic and not directly related to company business, so I didn't want it to be lost in proprietary code. Also, I wasn't sure it will actually work for production, since trying and testing it would take a lot of time too. Nevertheless, it was an interesting excercise, so I decided to do it on my own.
I spent weekends, nights and vacation days to improve it and posted it on the web as closed-code SDK. Then one day I "discovered" it at work and started testing. During testing I found a few small bugs, which I debugged at work (yes) and fixed within minutes. I suppose if that would be someone's else library I would had similar problems, but they would be harder and longer to fix (lame excuse?).
At the end the company loves it (it potentially saves a lot of money) and wants to buy a commercial license (which I don't mind giving for free, but that would be suspicious). A few other companies are also interested, but I feel this whole thing is awkward and unethical. I can't quit my job and concentrate on this SDK, since it won't pay enough.
I understand that I should've discussed it first with my manager or legal, but at that time it was too vague and not related to my direct work. Now it's too late and I'm not sure what the right thing is now. If I tell about it I think instead of a thank you I will be fired for cause and get sued. I can probably open source it, but is this the right action? What would you do?