aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-08-16 10:31:36 +0200
committerFlorian Dold <florian.dold@gmail.com>2019-08-16 10:31:36 +0200
commit8f5b6ffd7d02986176c95c8800a8292555e2702b (patch)
tree20eca85468ee6555744eb2ac6c11863d47d0b8cb /src
parent0049a240e73b4665e8ace6ae9171609460fe3954 (diff)
load wasm binary for akono
Diffstat (limited to 'src')
-rw-r--r--src/crypto/synchronousWorker.ts31
1 files changed, 24 insertions, 7 deletions
diff --git a/src/crypto/synchronousWorker.ts b/src/crypto/synchronousWorker.ts
index 1c98209aa..7d115f1dc 100644
--- a/src/crypto/synchronousWorker.ts
+++ b/src/crypto/synchronousWorker.ts
@@ -57,22 +57,39 @@ export class SynchronousCryptoWorker {
}
}
- private getEmscriptenEnvironment(): Promise<EmscEnvironment> {
+ private async getWasmBinary(): Promise<Uint8Array> {
+ // @ts-ignore
+ const akonoGetData = global.__akono_getData;
+ if (akonoGetData) {
+ // We're running embedded node on Android
+ console.log("reading wasm binary from akono");
+ const data = akonoGetData("taler-emscripten-lib.wasm");
+ // The data we get is base64-encoded binary data
+ let buf = new Buffer(data, 'base64');
+ return new Uint8Array(buf);
+
+ } else {
+ // We're in a normal node environment
+ const binaryPath = __dirname + "/../../../emscripten/taler-emscripten-lib.wasm";
+ console.log("reading from", binaryPath);
+ const wasmBinary = new Uint8Array(fs.readFileSync(binaryPath));
+ return wasmBinary;
+ }
+ }
+
+ private async getEmscriptenEnvironment(): Promise<EmscEnvironment> {
if (this.cachedEmscEnvironment) {
- return Promise.resolve(this.cachedEmscEnvironment);
+ return this.cachedEmscEnvironment;
}
if (this.cachedEmscEnvironmentPromise) {
return this.cachedEmscEnvironmentPromise;
}
- const binaryPath =
- __dirname + "/../../../emscripten/taler-emscripten-lib.wasm";
- console.log("reading from", binaryPath);
- const wasmBinary = new Uint8Array(fs.readFileSync(binaryPath));
-
let lib: any;
+ const wasmBinary = await this.getWasmBinary();
+
return new Promise((resolve, reject) => {
// Arguments passed to the emscripten prelude
const libArgs = {