The nice folks over at project everest compiled a formally verified cryptographic library known as HACL* to web assembly. Unfortunately there are no examples of using the code defined here.
I tested the code with Version 71.0.3578.98 (Official Build) (64-bit) of Chrome.
Here is in essence what I attempted on the client in order to get a working example.
var module = HaclLoader().then(function(m) {
var state_buffer = new ArrayBuffer(32);
var state = new Uint32Array(state_buffer);
var message_buffer = new ArrayBuffer(32);
var message = new Uint8Array(message_buffer);
for (var i = 0; i < message.length; i++) {
message[i] = i;
}
var hash_buffer = new ArrayBuffer(32);
var hash = new Uint8Array(hash_buffer);
m._Hacl_SHA2_256_init(state);
m._Hacl_SHA2_256_update(state, message);
m._Hacl_SHA2_256_finish(state, hash);
console.log(hash);
});
The code referenced attempts to use the functions defined here. Unfortunately this sample code does not work, the hash ends up being a zero array.