netpyoung / unity.libsodium

🔑 libsodium made easy for Unity3d
MIT License
17 stars 4 forks source link

Add WebGL target #7

Open jasonboukheir opened 1 year ago

jasonboukheir commented 1 year ago

I've been struggling to get WebGL crypto functions to work in my Algorand SDK library. I have been using .jslib native plugins to handle them, but the APIs are not the same as libsodium.

Well I'm pleased to show off that I got source libsodium working in WebGL! Check this out: https://github.com/CareBoo/unity-algorand-sdk/tree/8c1b360d745cfcb1d621d355f56fa959c33a8957/Runtime/Algorand.Unity.Crypto/Plugins/WebGL

I have only tested ChaCha20Poly1305, Ed25519, and Sha512, however, I'm really surprised it worked!

So the steps to copy from the libsodium project were the following:

  1. Give each file a unique name.
  2. Replace all #includes with the new names.
  3. Flatten the folders.
  4. Remove all directories from #includes.
  5. Set explicit version and minimal in the version.h.in -> version.h file.

I recommend doing something similar to add this to WebGL. It should also just work for any platform using IL2CPP, so it opens this project up to loads of other platforms!

netpyoung commented 1 year ago

Thank you for reporting that. I'm not sure when I got a time, But I will looking what did you reported.