-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Providing js_of_ocaml stubs relying on the wasm target. #496
Comments
If I understand correctly what you're suggesting, you ended up with the same conclusion I came to. The code is not public yet, but essentially here's what I did locally for a piece of code that requires some crypto primitives... Primitives.mli, the list of crypto primitives I need
primitives-native/Primitives.ml, calling hacl-star(ocaml) --> hacl-star-raw(ocaml) --ctypes--> hacl-star(C)
primitives-js/Primitives.ml, declaring the existence of primitives that take Uint8Arrays
primitives.js, which re-routes this to a global object called MyCrypto
main.js, which picks implementations for the crypto using the hacl-wasm node.js package
Does this match what you have in mind? If so, I agree that it's a good way to go. I have a couple local patches to api.js that make it work by default both in a browser and in a node context, if you're interested. |
What I had in mind was to not touch the ml files at all and generate the Js stubs automatically (like it's done for c). All this would be easier if I had access to the wasm api directly instead of what api.js provides |
Oh so you don't want to use what is in |
I'm not sure. I don't want to provide an "identical" API, I want the current API to just work with jsoo. The generated jsoo stubs would indeed implement the calling convention required to call wasm. |
So you would basically like to add some branching somewhere in the ocaml bindings code that either calls to ctypes or to wasm directly with a minimal amount of glue? This is definitely feasible and I can dig up the documentation on the kremlin calling-convention if it's not obvious from the api.js file. |
No. I want to use ctypes and compile it with jsoo. I want to use the ocaml code as it is now. |
I see. Then in that case I'd be quite curious to see how you implement it. If you have a proof of concept I'd be quite keen to see it. I tried to do what you describe but I ended up with a lot of ctypes-related cruft being generated by js_of_ocaml and it just felt easier to "cut" higher up in the logic and just ditch ctypes altogether. The calling convention is simple: arrays are addresses in memory. Call |
cc @protz
I've been experimenting with providing js_of_ocaml stubs for hacl-star.
Theses stubs can (mostly) be automatically generated from the ctypes bindings and
api.json
.Using the hacl-wasm is not very convenient in this case, because it simplifies the api too much and I find myself trying to reverse this simplification.
As an example,
The raw ocaml binding defines
api.js will expose it as
for the jsoo stubs, I would have to make sure
message
is of lengthmessage_len
and take a substring if not.It would result in the following pseudo js code
Overall, it would be much simpler to be able to call the wasm funcitons directly. Is it possible ? If not, would you be ok to allow it (as a separate package maybe) ?
The text was updated successfully, but these errors were encountered: