diff options
author | Florian Dold <florian@dold.me> | 2022-03-24 01:10:34 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2022-03-24 01:10:41 +0100 |
commit | 9d38cb56a6fa4c9a975df339cb0aa08f040368c1 (patch) | |
tree | cc2fac95abe164b9da325de34a256f14ece9d9c9 /packages/taler-wallet-core/src/crypto/workers | |
parent | cc18751e72435544297de4f5b5a6b318fbba9cd1 (diff) | |
download | wallet-core-9d38cb56a6fa4c9a975df339cb0aa08f040368c1.tar.xz |
wallet: crypto worker fixes, better taler-crypto-worker integration
Diffstat (limited to 'packages/taler-wallet-core/src/crypto/workers')
-rw-r--r-- | packages/taler-wallet-core/src/crypto/workers/cryptoDispatcher.ts | 8 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/crypto/workers/synchronousWorker.ts | 53 |
2 files changed, 49 insertions, 12 deletions
diff --git a/packages/taler-wallet-core/src/crypto/workers/cryptoDispatcher.ts b/packages/taler-wallet-core/src/crypto/workers/cryptoDispatcher.ts index 810273cca..f5782ab09 100644 --- a/packages/taler-wallet-core/src/crypto/workers/cryptoDispatcher.ts +++ b/packages/taler-wallet-core/src/crypto/workers/cryptoDispatcher.ts @@ -122,7 +122,7 @@ export class CryptoDispatcher { worker.idleTimeoutHandle = null; } if (worker.currentWorkItem) { - worker.currentWorkItem.reject(Error("explicitly terminated")); + worker.currentWorkItem.reject(new CryptoApiStoppedError()); worker.currentWorkItem = null; } if (worker.w) { @@ -143,7 +143,7 @@ export class CryptoDispatcher { */ wake(ws: WorkerState, work: WorkItem): void { if (this.stopped) { - throw new CryptoApiStoppedError(); + return; } if (ws.currentWorkItem !== null) { throw Error("assertion failed"); @@ -331,8 +331,8 @@ export class CryptoDispatcher { } timeout.clear(); resolve(x); - }); - p.catch((x) => { + }).catch((x) => { + logger.info(`crypto RPC call ${operation} threw`); if (timedOut) { return; } diff --git a/packages/taler-wallet-core/src/crypto/workers/synchronousWorker.ts b/packages/taler-wallet-core/src/crypto/workers/synchronousWorker.ts index 1d7539ed6..a5f154e92 100644 --- a/packages/taler-wallet-core/src/crypto/workers/synchronousWorker.ts +++ b/packages/taler-wallet-core/src/crypto/workers/synchronousWorker.ts @@ -47,14 +47,11 @@ export class SynchronousCryptoWorker { this.cryptoImplR = { ...nativeCryptoR }; - if ( - process.env["TALER_WALLET_RPC_CRYPRO"] || - // Old name - process.env["TALER_WALLET_PRIMITIVE_WORKER"] - ) { + if (process.env["TALER_WALLET_PRIMITIVE_WORKER"]) { + logger.info("using RPC for some crypto operations"); const rpc = (this.rpcClient = new CryptoRpcClient()); this.cryptoImplR.eddsaSign = async (_, req) => { - logger.trace("making RPC request"); + logger.info("calling RPC impl of eddsaSign"); return await rpc.queueRequest({ op: "eddsa_sign", args: { @@ -63,6 +60,46 @@ export class SynchronousCryptoWorker { }, }); }; + this.cryptoImplR.setupRefreshPlanchet = async (_, req) => { + const res = await rpc.queueRequest({ + op: "setup_refresh_planchet", + args: { + coin_index: req.coinNumber, + transfer_secret: req.transferSecret, + }, + }); + return { + bks: res.blinding_key, + coinPriv: res.coin_priv, + coinPub: res.coin_pub, + }; + }; + this.cryptoImplR.rsaBlind = async (_, req) => { + const res = await rpc.queueRequest({ + op: "rsa_blind", + args: { + bks: req.bks, + hm: req.hm, + pub: req.pub, + }, + }); + return { + blinded: res.blinded, + }; + }; + + this.cryptoImplR.keyExchangeEcdheEddsa = async (_, req) => { + const res = await rpc.queueRequest({ + op: "kx_ecdhe_eddsa", + args: { + ecdhe_priv: req.ecdhePriv, + eddsa_pub: req.eddsaPub, + }, + }); + return { + h: res.h, + }; + }; } } @@ -101,8 +138,8 @@ export class SynchronousCryptoWorker { let result: any; try { result = await (impl as any)[operation](impl, req); - } catch (e) { - logger.error("error during operation", e); + } catch (e: any) { + logger.error(`error during operation '${operation}': ${e}`); return; } |