Page MenuHomePhabricator

[web][keyserver] Webpack config and client logic to access opaque-ke2 WASM bindings
ClosedPublic

Authored by ashoat on Mar 27 2023, 11:09 AM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Apr 8, 11:07 PM
Unknown Object (File)
Mon, Apr 8, 11:07 PM
Unknown Object (File)
Mon, Apr 8, 11:07 PM
Unknown Object (File)
Mon, Apr 8, 11:07 PM
Unknown Object (File)
Mon, Apr 8, 11:04 PM
Unknown Object (File)
Thu, Apr 4, 2:27 AM
Unknown Object (File)
Mar 8 2024, 6:58 PM
Unknown Object (File)
Mar 8 2024, 6:58 PM
Subscribers

Details

Summary

This diff makes it possible to call the WASM bindings from web!

Depends on D7197

Test Plan
  1. I tested on both dev and prod
  2. I made sure that in both, the Network tab of Chrome dev tools showed the WASM correctly downloaded
  3. I tested with this patch and made sure there were no errors in both dev and prod

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

web/crypto/opaque-utils.js
11–15 ↗(On Diff #24226)

Before landing, I'll make sure we don't execute this twice

Harbormaster returned this revision to the author for changes because remote builds failed.Mar 27 2023, 11:25 AM
Harbormaster failed remote builds in B17699: Diff 24226!
  1. Make sure we only download the WASM once
  2. Make sure of wasm-bindgen's --target web mode (updated in the parent diff) instead of implementing that ourselves
keyserver/src/responders/website-responders.js
88 ↗(On Diff #24234)

I modeled this after jsURL instead of olmFilename and sqljsFilename. The filename approach works well with Emscripten's locateFile utility, but not so well with wasm-bindgen (which has less tooling overall)

web/app.react.js
65 ↗(On Diff #24234)

We don't await here, which means that we'll execute initOpaque but ignore the result. This is good because it makes sure we start downloading the WASM as soon as possible. Note that we'll still need to call await initOpaque(); before executing any calls on the WASM

web/crypto/opaque-utils.js
14 ↗(On Diff #24234)

Now that we're using --target web, initOpaqueKe(opaqueURL) is all we really need. The rest of the code here makes sure we only ever call that once

web/flow-typed/npm/@commapp/opaque-ke-wasm_vx.x.x.js
6–19 ↗(On Diff #24234)

This is pulled from wasm-bindgen's TS output, with some slight modifications for Flow

23 ↗(On Diff #24234)

I typed this as mixed because it actually returns some sort of wasm object with a bunch of internal stuff. My impression is that we shouldn't use it directly, so I'm using mixed as a "opaque type" (basically telling the caller they can't really do anything with it)

web/package.json
38 ↗(On Diff #24234)

If we just say "@commapp/opaque-ke-wasm": "^0.0.3", yarn pulls it from our monorepo instead of using the published package. That's a problem because our monorepo doesn't have the built files, and we'd rather than affect the DevX by adding the build here to our build process. Instead we use this npm: alias to make sure the published package is used

web/flow-typed/npm/@commapp/opaque-ke-wasm_vx.x.x.js
6–19 ↗(On Diff #24234)

Nothing looks super surprising here, thanks!

Not going to accept as someone with more js experience should review before landing.

Thanks for annotating the changes with explanations

This revision is now accepted and ready to land.Mar 28 2023, 1:25 PM