hashcloak / katzenpost_client_bindings_js

JS bindings for the Go Katzenpost client
0 stars 0 forks source link

Determine method to get from Go -> JS #1

Open Mikerah opened 4 years ago

Mikerah commented 4 years ago

There are a few ways to get js bindings for Go code. There are the following:

  1. Use some sort of Go transpiler. It simplifies the codebase quite a bit since whenever there's upstream update to katzenpost, I can just pull it and run whatever I need to run to get js bindings. However, upon further research, there's very little in the way of doing this. All the projects for Go -> JS are no longer in development
  2. Compile Go to some intermediate language and get js bindings from that language. Namely, it makes sense to compile Go to Rust or C/C++ and then from one of those languages, run JS. There's tooling for this already and might be the simplest approach. The main drawback is complexity of codebases.
  3. WebAssembly. The ecosystem for Go WebAssembly tools is still immature so I may have to deal with forever changing APIs.

I'm leaning towards option 2 as katzenpost already has c bindings.

Mikerah commented 4 years ago

Turns out 2) doesn't work as intended since Go only returns a shared library file. It opens up the ability to use node-ffi but there's better options than that.

The solution that I employed is to compile katzenpost/client to wasm and then use wasm support in js to get bindings. It works well so far at the expense of a relatively large .wasm file. I expect improvements in the short to mid term.

Mikerah commented 4 years ago

Reopening issue because the initial method failed. It turns out to compile to wasm using the provide Go tools, one needs to use a main package. As such, there is a potential bug in the Go provided wasm_exec.js file used to interact with the Go generated wasm file from nodejs.

Looking into other methods to see how to get around this while I wait for an answer.