From cfa1df734315efc8e24a1a846e4d694abe2249ea Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 26 Jun 2019 15:30:32 +0200 Subject: add link signature to /refresh/reveal --- src/crypto/cryptoApi.ts | 147 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 97 insertions(+), 50 deletions(-) (limited to 'src/crypto/cryptoApi.ts') diff --git a/src/crypto/cryptoApi.ts b/src/crypto/cryptoApi.ts index 03c2a675b..43a3bc228 100644 --- a/src/crypto/cryptoApi.ts +++ b/src/crypto/cryptoApi.ts @@ -14,7 +14,6 @@ TALER; see the file COPYING. If not, see */ - /** * API to access the Taler crypto worker thread. * @author Florian Dold @@ -35,22 +34,14 @@ import { WireFee, } from "../dbTypes"; -import { - ContractTerms, - PaybackRequest, -} from "../talerTypes"; +import { ContractTerms, PaybackRequest } from "../talerTypes"; -import { - BenchmarkResult, - CoinWithDenom, - PayCoinInfo, -} from "../walletTypes"; +import { BenchmarkResult, CoinWithDenom, PayCoinInfo } from "../walletTypes"; import * as timer from "../timer"; import { startWorker } from "./startWorker"; - /** * State of a crypto worker. */ @@ -58,17 +49,17 @@ interface WorkerState { /** * The actual worker thread. */ - w: Worker|null; + w: Worker | null; /** * Work we're currently executing or null if not busy. */ - currentWorkItem: WorkItem|null; + currentWorkItem: WorkItem | null; /** * Timer to terminate the worker if it's not busy enough. */ - terminationTimerHandle: timer.TimerHandle|null; + terminationTimerHandle: timer.TimerHandle | null; } interface WorkItem { @@ -88,7 +79,6 @@ interface WorkItem { startTime: number; } - /** * Number of different priorities. Each priority p * must be 0 <= p < NUM_PRIO. @@ -151,8 +141,10 @@ export class CryptoApi { handleWorkerError(ws: WorkerState, e: ErrorEvent) { if (ws.currentWorkItem) { - console.error(`error in worker during ${ws.currentWorkItem!.operation}`, - e); + console.error( + `error in worker during ${ws.currentWorkItem!.operation}`, + e, + ); } else { console.error("error in worker", e); } @@ -201,7 +193,10 @@ export class CryptoApi { console.error(`RPC with id ${id} has no registry entry`); return; } - console.log(`rpc ${currentWorkItem.operation} took ${timer.performanceNow() - currentWorkItem.startTime}ms`); + console.log( + `rpc ${currentWorkItem.operation} took ${timer.performanceNow() - + currentWorkItem.startTime}ms`, + ); currentWorkItem.resolve(msg.data.result); } @@ -230,12 +225,21 @@ export class CryptoApi { } } - private doRpc(operation: string, priority: number, - ...args: any[]): Promise { - + private doRpc( + operation: string, + priority: number, + ...args: any[] + ): Promise { const p: Promise = new Promise((resolve, reject) => { const rpcId = this.nextRpcId++; - const workItem: WorkItem = {operation, args, resolve, reject, rpcId, startTime: 0}; + const workItem: WorkItem = { + operation, + args, + resolve, + reject, + rpcId, + startTime: 0, + }; if (this.numBusy === this.workers.length) { const q = this.workQueues[priority]; @@ -263,8 +267,10 @@ export class CryptoApi { }); } - - createPreCoin(denom: DenominationRecord, reserve: ReserveRecord): Promise { + createPreCoin( + denom: DenominationRecord, + reserve: ReserveRecord, + ): Promise { return this.doRpc("createPreCoin", 1, denom, reserve); } @@ -280,27 +286,48 @@ export class CryptoApi { return this.doRpc("hashDenomPub", 1, denomPub); } - isValidDenom(denom: DenominationRecord, - masterPub: string): Promise { + isValidDenom(denom: DenominationRecord, masterPub: string): Promise { return this.doRpc("isValidDenom", 2, denom, masterPub); } - isValidWireFee(type: string, wf: WireFee, masterPub: string): Promise { + isValidWireFee( + type: string, + wf: WireFee, + masterPub: string, + ): Promise { return this.doRpc("isValidWireFee", 2, type, wf, masterPub); } - isValidPaymentSignature(sig: string, contractHash: string, merchantPub: string): Promise { - return this.doRpc("isValidPaymentSignature", 1, sig, contractHash, merchantPub); + isValidPaymentSignature( + sig: string, + contractHash: string, + merchantPub: string, + ): Promise { + return this.doRpc( + "isValidPaymentSignature", + 1, + sig, + contractHash, + merchantPub, + ); } - signDeposit(contractTerms: ContractTerms, - cds: CoinWithDenom[], - totalAmount: AmountJson): Promise { - return this.doRpc("signDeposit", 3, contractTerms, cds, totalAmount); + signDeposit( + contractTerms: ContractTerms, + cds: CoinWithDenom[], + totalAmount: AmountJson, + ): Promise { + return this.doRpc( + "signDeposit", + 3, + contractTerms, + cds, + totalAmount, + ); } - createEddsaKeypair(): Promise<{priv: string, pub: string}> { - return this.doRpc<{priv: string, pub: string}>("createEddsaKeypair", 1); + createEddsaKeypair(): Promise<{ priv: string; pub: string }> { + return this.doRpc<{ priv: string; pub: string }>("createEddsaKeypair", 1); } rsaUnblind(sig: string, bk: string, pk: string): Promise { @@ -311,23 +338,43 @@ export class CryptoApi { return this.doRpc("createPaybackRequest", 1, coin); } - createRefreshSession(exchangeBaseUrl: string, - kappa: number, - meltCoin: CoinRecord, - newCoinDenoms: DenominationRecord[], - meltFee: AmountJson): Promise { - return this.doRpc("createRefreshSession", - 4, - exchangeBaseUrl, - kappa, - meltCoin, - newCoinDenoms, - meltFee); + createRefreshSession( + exchangeBaseUrl: string, + kappa: number, + meltCoin: CoinRecord, + newCoinDenoms: DenominationRecord[], + meltFee: AmountJson, + ): Promise { + return this.doRpc( + "createRefreshSession", + 4, + exchangeBaseUrl, + kappa, + meltCoin, + newCoinDenoms, + meltFee, + ); + } + + signCoinLink( + oldCoinPriv: string, + newDenomHash: string, + oldCoinPub: string, + transferPub: string, + coinEv: string, + ): Promise { + return this.doRpc( + "signCoinLink", + 4, + oldCoinPriv, + newDenomHash, + oldCoinPub, + transferPub, + coinEv, + ); } benchmark(repetitions: number): Promise { - return this.doRpc("benchmark", - 1, - repetitions); + return this.doRpc("benchmark", 1, repetitions); } } -- cgit v1.2.3