summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/src/browserWorkerEntry.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-webextension/src/browserWorkerEntry.ts')
-rw-r--r--packages/taler-wallet-webextension/src/browserWorkerEntry.ts53
1 files changed, 33 insertions, 20 deletions
diff --git a/packages/taler-wallet-webextension/src/browserWorkerEntry.ts b/packages/taler-wallet-webextension/src/browserWorkerEntry.ts
index b5c26a7bb..bb1794e56 100644
--- a/packages/taler-wallet-webextension/src/browserWorkerEntry.ts
+++ b/packages/taler-wallet-webextension/src/browserWorkerEntry.ts
@@ -1,18 +1,18 @@
/*
- This file is part of TALER
- (C) 2016 GNUnet e.V.
+ This file is part of GNU Taler
+ (C) 2022 Taler Systems S.A.
- TALER is free software; you can redistribute it and/or modify it under the
+ GNU Taler is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.
- TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+ GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-*/
+ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
/**
* Web worker for crypto operations.
@@ -22,38 +22,51 @@
* Imports.
*/
-import { Logger } from "@gnu-taler/taler-util";
-import { CryptoImplementation } from "@gnu-taler/taler-wallet-core";
+import {
+ j2s,
+ Logger,
+ getErrorDetailFromException,
+} from "@gnu-taler/taler-util";
+import { nativeCrypto } from "@gnu-taler/taler-wallet-core";
const logger = new Logger("browserWorkerEntry.ts");
-const worker: Worker = (self as any) as Worker;
+const worker: Worker = self as any as Worker;
async function handleRequest(
operation: string,
id: number,
- args: string[],
+ req: unknown,
): Promise<void> {
- const impl = new CryptoImplementation();
+ const impl = nativeCrypto;
if (!(operation in impl)) {
console.error(`crypto operation '${operation}' not found`);
return;
}
+ logger.info(`browser worker crypto request: ${j2s(req)}`);
+
+ let responseMsg: any;
try {
- const result = (impl as any)[operation](...args);
- worker.postMessage({ result, id });
- } catch (e) {
- logger.error("error during operation", e);
- return;
+ const result = await (impl as any)[operation](impl, req);
+ responseMsg = { type: "success", result, id };
+ } catch (e: any) {
+ logger.error(`error during operation: ${e.stack ?? e.toString()}`);
+ responseMsg = {
+ type: "error",
+ id,
+ error: getErrorDetailFromException(e),
+ };
}
+
+ worker.postMessage(responseMsg);
}
worker.onmessage = (msg: MessageEvent) => {
- const args = msg.data.args;
- if (!Array.isArray(args)) {
- console.error("args must be array");
+ const req = msg.data.req;
+ if (typeof req !== "object") {
+ console.error("request must be an object");
return;
}
const id = msg.data.id;
@@ -67,7 +80,7 @@ worker.onmessage = (msg: MessageEvent) => {
return;
}
- handleRequest(operation, id, args).catch((e) => {
+ handleRequest(operation, id, req).catch((e) => {
console.error("error in browser worker", e);
});
};