Using typescript and npm has two big advantages: there are many modules available, and it runs in many environments. Unfortunately this is also one of the biggest challenges. Because you can configure every aspect of the system, you can break it very easily.
At C4DT we often use the
crypto library, or the
crypto-browserify counterpart. This is a very difficult module to get right in all three environments. Node has native support. On the other hand, the browser offers an incompatible crypto environment. And finally, nativescript does something entirely different.
To test and understand what is the best way to do it, I created https://github.com/c4dt/crypto-ts. It states the problem and offers a solution. There are other solutions, but our engineering team thinks this is the easiest.
Comments are welcome in the issue section.