From bf939be765bd84e283740fd51d542625ac525098 Mon Sep 17 00:00:00 2001 From: AaronDewes <aaron.dewes@protonmail.com> Date: Thu, 13 Oct 2022 16:41:37 +0000 Subject: [PATCH] Browser only --- Makefile | 2 +- javascript/olm_pre.js | 19 +------------------ 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index a1ea744..44020b8 100644 --- a/Makefile +++ b/Makefile @@ -94,7 +94,7 @@ LDFLAGS += -Wall -Werror CFLAGS_NATIVE = -fPIC CXXFLAGS_NATIVE = -fPIC -EMCCFLAGS = --closure 1 --memory-init-file 0 -s NO_FILESYSTEM=1 -s INVOKE_RUN=0 -s MODULARIZE=1 +EMCCFLAGS = --closure 1 --memory-init-file 0 -s NO_FILESYSTEM=1 -s INVOKE_RUN=0 -s MODULARIZE=1 -s ENVIRONMENT=web # Olm generally doesn't need a lot of memory to encrypt / decrypt its usual # payloads (ie. Matrix messages), but we do need about 128K of heap to encrypt diff --git a/javascript/olm_pre.js b/javascript/olm_pre.js index 314d7da..e3a0731 100644 --- a/javascript/olm_pre.js +++ b/javascript/olm_pre.js @@ -1,23 +1,6 @@ -var get_random_values; - -if (typeof(window) !== 'undefined') { - // We're in a browser (directly, via browserify, or via webpack). - get_random_values = function(buf) { +var get_random_values = function(buf) { window.crypto.getRandomValues(buf); }; -} else if (module["exports"]) { - // We're running in node. - var nodeCrypto = require("crypto"); - get_random_values = function(buf) { - // [''] syntax needed here rather than '.' to prevent - // closure compiler from mangling the import(!) - var bytes = nodeCrypto['randomBytes'](buf.length); - buf.set(bytes); - }; - process = global["process"]; -} else { - throw new Error("Cannot find global to attach library to"); -} /* applications should define OLM_OPTIONS in the environment to override * emscripten module settings -- GitLab