obfuscate/compress/protect javascript code

Viewed 917

I am looking for a way to obfuscate / compress my javascript code.

I have already searched the OS and the web, but there are many outdated or broken tutorials and scripts. Also, honestly, I don't have the time to test them all to find the few that still work in 2021 with JS ES6.

My code uses ethers.js to interfacing with the blockchain, so using code like this:

balance = await provider.getBalance(accountSigner);
...
const networkWallet = await provider.getNetwork();

I see other websites having this code:

!function(e){function r(r){for(var n,a,i=r[0],c=r[1],f=r[2]...

I want to make it harder to copy and reuse my JS code, I know making it 100% irreversible is impossible but at least it will take enough time to do that it won't be worth it.

Some of my tries:

  • uglifyjs -c test.js -> it's always running for a 5 lines file, without using enough cpu - I don't hear almost anything working in the case, so I think that it doesn't work. Without -c it's immediate) (the same with sudo)
  • closure-compiler.appspot.com: it fails also for their suggested file, it's too slow and outdated
  • http://jsutility.pjoneil.net/ - it doesn't support provider.on("network", (newNetwork, oldNetwork) => {
  • https://jscompress.com/ - it seems to work but it only performs little compression/obfuscation with no options to obfuscate e.g. strings
  • https://javascriptobfuscator.com/Javascript-Obfuscator.aspx - the most useful options are only available in the GUI for windows

I'm using Ubuntu LTS.

I can also use PHP if it can help.

The reason is that my code will let users to mint a new NFT directly from my website, so since the smart contract's source code is published on etherscan everyone can copy my Javascript code and do their minting with a new smart contract. In other words: everyone can copy ALL my works easily!

2 Answers

I have been using JSDefender (https://www.preemptive.com/products/jsdefender/) for almost a year now. It has helped me obfuscate react, angular and javascript project. You can try the trial period to see if it is adapted for your project as well.

Related