diff --git a/keyserver/src/responders/website-responders.js b/keyserver/src/responders/website-responders.js --- a/keyserver/src/responders/website-responders.js +++ b/keyserver/src/responders/website-responders.js @@ -70,6 +70,7 @@ +cssInclude: string, +olmFilename: string, +sqljsFilename: string, + +opaqueFilename: string, }; let assetInfo: ?AssetInfo = null; async function getAssetInfo() { @@ -84,6 +85,7 @@ cssInclude: '', olmFilename: '', sqljsFilename: '', + opaqueFilename: '', }; return assetInfo; } @@ -107,6 +109,7 @@ `, olmFilename: manifest['olm.wasm'], sqljsFilename: webworkersManifest['sql-wasm.wasm'], + opaqueFilename: manifest['comm_opaque2_wasm_bg.wasm'], }; return assetInfo; } catch { @@ -332,8 +335,14 @@ return pushConfig.publicKey; })(); - const { jsURL, fontsURL, cssInclude, olmFilename, sqljsFilename } = - await assetInfoPromise; + const { + jsURL, + fontsURL, + cssInclude, + olmFilename, + sqljsFilename, + opaqueFilename, + } = await assetInfoPromise; // prettier-ignore res.write(html` @@ -433,6 +442,7 @@ var baseURL = "${baseURL}"; var olmFilename = "${olmFilename}"; var sqljsFilename = "${sqljsFilename}"; + var opaqueFilename = "${opaqueFilename}"; diff --git a/web/app.react.js b/web/app.react.js --- a/web/app.react.js +++ b/web/app.react.js @@ -34,6 +34,7 @@ import Chat from './chat/chat.react.js'; import { TooltipProvider } from './chat/tooltip-provider.js'; import NavigationArrows from './components/navigation-arrows.react.js'; +import { initOpaque } from './crypto/opaque-utils.js'; import electron from './electron.js'; import InputStateContainer from './input/input-state-container.react.js'; import LoadingIndicator from './loading-indicator.react.js'; @@ -61,6 +62,8 @@ import { type NavInfo } from './types/nav-types.js'; import { canonicalURLFromReduxState, navInfoFromURL } from './url-utils.js'; +initOpaque(); + // We want Webpack's css-loader and style-loader to handle the Fontawesome CSS, // so we disable the autoAddCss logic and import the CSS file. Otherwise every // icon flashes huge for a second before the CSS is loaded. diff --git a/web/crypto/opaque-utils.js b/web/crypto/opaque-utils.js new file mode 100644 --- /dev/null +++ b/web/crypto/opaque-utils.js @@ -0,0 +1,17 @@ +// @flow + +import { __wbg_set_wasm } from '@commapp/opaque-ke-wasm/pkg/comm_opaque2_wasm_bg.js'; + +declare var opaqueFilename: string; + +const path = opaqueFilename + ? `compiled/${opaqueFilename}` + : 'http://localhost:8080/opaque-ke.wasm'; + +async function initOpaque() { + const response = await fetch(path); + const text = await response.text(); + __wbg_set_wasm(text); +} + +export { initOpaque }; diff --git a/web/opaque-ke-wasm/package.json b/web/opaque-ke-wasm/package.json --- a/web/opaque-ke-wasm/package.json +++ b/web/opaque-ke-wasm/package.json @@ -1,7 +1,7 @@ { "name": "@commapp/opaque-ke-wasm", "description": "WASM bindings for use of opaque-ke inside web browser", - "version": "0.0.1", + "version": "0.0.2", "main": "index.js", "files": [ "index.js", diff --git a/web/package.json b/web/package.json --- a/web/package.json +++ b/web/package.json @@ -35,6 +35,7 @@ }, "dependencies": { "@babel/runtime": "^7.13.10", + "@commapp/opaque-ke-wasm": "^0.0.2", "@emoji-mart/data": "^1.1.2", "@emoji-mart/react": "^1.1.1", "@fortawesome/fontawesome-svg-core": "1.2.25", diff --git a/web/webpack.config.cjs b/web/webpack.config.cjs --- a/web/webpack.config.cjs +++ b/web/webpack.config.cjs @@ -57,6 +57,16 @@ }, ], }), + new CopyPlugin({ + patterns: [ + { + from: + 'node_modules/@commapp/opaque-ke-wasm' + + '/pkg/comm_opaque2_wasm_bg.wasm', + to: path.join(__dirname, 'dist', 'opaque-ke.wasm'), + }, + ], + }), ], }; @@ -71,6 +81,16 @@ }, ], }), + new CopyPlugin({ + patterns: [ + { + from: + 'node_modules/@commapp/opaque-ke-wasm' + + '/pkg/comm_opaque2_wasm_bg.wasm', + to: path.join(__dirname, 'dist', 'opaque-ke.[contenthash:12].wasm'), + }, + ], + }), new WebpackManifestPlugin({ publicPath: '', }),