2

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.

I am using code like this:

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

but 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.

5
  • Minimising is very different from obfuscation; it seems you're asking about obfuscation (might want to edit). Obligatory q: why do you want to obfuscate code which interacts with the block chain? There are legitimate reasons to do it, but it's a little bit of a red flag, at least to me Commented Oct 8, 2021 at 9:48
  • @2e0byo I updated the question and added the reason at the end. Commented Oct 8, 2021 at 9:55
  • that makes sense. I confess the only places I've seen obfuscated JS which minted bitcoins were places JS shouldn't be at all, i.e. injection. But what about compiling to webasm in that case, and not releasing source at all? Commented Oct 8, 2021 at 10:05
  • @2e0byo I don't know webasm, can you suggest me an url to compile with it? Commented Oct 8, 2021 at 10:10
  • webasm is an assembly target optimised to run on mobile processors. wiki. Generally people write code in a standard compiling language (c, rust, etc), but a quick check confirms there's a TypeScript compiler, which is likely pretty close to what you already have in JS. Commented Oct 8, 2021 at 10:25

2 Answers 2

0

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.

Sign up to request clarification or add additional context in comments.

Comments

-1

Try this tool
https://javascriptobfuscator.com/Javascript-Obfuscator.aspx

balance = await provider.getBalance(accountSigner);

produces

var _0x74c0=["\x67\x65\x74\x42\x61\x6C\x61\x6E\x63\x65"];balance=  await provider[_0x74c0[0]](accountSigner)

1 Comment

I tried it but the most useful options are only available in the GUI for windows :(

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.