I have a dart library which uses some fancy algorithms. I would like to share the library but hide (minimize or obfuscate) the algorithms themselves.
Is this possible?
I’m using Flutter/web.
Context: I’ve built an application for a customer; he paid for the development and owns the code; but I want to hide/minimize/obfuscate the algorithms (which are my IPR)
2
Answers
You can build with
--obfuscate
flag:If you want to really protect your algorithms, the best is to implement them on an API and call this API from dart code.
When building an app using
flutter build web
, the resulting JS code is already minified by default. This provides a pretty good level of obscurity by renaming symbols (including names of classes, variables, methods etc).If you want to obfuscate your code even more, you can apply any existing JS obfuscation tool to the compiled code. For example, using
javascript-obfuscator
:However, obfuscation can negatively impact your performance & code size ,
javascript-obfuscator
docs say 15-80%. I tested this approach on a big Flutter project and it resulted in a 3-fold increase in the size ofmain.dart.js
.A good way around this would be to separate the algorithms needing obfuscation into a separate file using Dart’s deferred loading and executing the obfuscator only on this file.
A simple example of this technique:
algorithm.dart:
main.dart:
Building:
As you can see, this approach obfuscates only the
main.dart.js_1.part.js
file which corresponds to thealgorithm.dart
source file.