diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/crypto/cryptoApi.ts | 7 | ||||
-rw-r--r-- | src/crypto/cryptoWorker.ts | 83 | ||||
-rw-r--r-- | src/crypto/emscInterface.ts | 4 | ||||
-rw-r--r-- | src/i18n/de.po | 2 | ||||
-rw-r--r-- | src/i18n/en-US.po | 2 | ||||
-rw-r--r-- | src/i18n/fr.po | 2 | ||||
-rw-r--r-- | src/i18n/it.po | 2 | ||||
-rw-r--r-- | src/i18n/sv.po | 2 | ||||
-rw-r--r-- | src/i18n/taler-wallet-webex.pot | 2 | ||||
-rw-r--r-- | src/timer.ts | 2 | ||||
-rw-r--r-- | src/wallet.ts | 5 | ||||
-rw-r--r-- | src/walletTypes.ts | 5 | ||||
-rw-r--r-- | src/webex/messages.ts | 4 | ||||
-rw-r--r-- | src/webex/pages/confirm-contract.tsx | 6 | ||||
-rw-r--r-- | src/webex/pages/popup.tsx | 5 | ||||
-rw-r--r-- | src/webex/wxApi.ts | 9 | ||||
-rw-r--r-- | src/webex/wxBackend.ts | 8 |
17 files changed, 136 insertions, 14 deletions
diff --git a/src/crypto/cryptoApi.ts b/src/crypto/cryptoApi.ts index c1f3f4245..03c2a675b 100644 --- a/src/crypto/cryptoApi.ts +++ b/src/crypto/cryptoApi.ts @@ -41,6 +41,7 @@ import { } from "../talerTypes"; import { + BenchmarkResult, CoinWithDenom, PayCoinInfo, } from "../walletTypes"; @@ -323,4 +324,10 @@ export class CryptoApi { newCoinDenoms, meltFee); } + + benchmark(repetitions: number): Promise<BenchmarkResult> { + return this.doRpc<BenchmarkResult>("benchmark", + 1, + repetitions); + } } diff --git a/src/crypto/cryptoWorker.ts b/src/crypto/cryptoWorker.ts index 88e30e55b..7cec5f284 100644 --- a/src/crypto/cryptoWorker.ts +++ b/src/crypto/cryptoWorker.ts @@ -25,6 +25,8 @@ import * as Amounts from "../amounts"; import { AmountJson } from "../amounts"; +import * as timer from "../timer"; + import { CoinRecord, CoinStatus, @@ -44,6 +46,7 @@ import { } from "../talerTypes"; import { + BenchmarkResult, CoinWithDenom, PayCoinInfo, } from "../walletTypes"; @@ -437,7 +440,7 @@ namespace RpcFunctions { const confirmSig: string = native.eddsaSign(confirmData.toPurpose(), - native.EddsaPrivateKey.fromCrock( + native.EddsaPrivateKey.fromCrock( meltCoin.coinPriv)).toCrock(); let valueOutput = Amounts.getZero(newCoinDenoms[0].value.currency); @@ -478,6 +481,84 @@ namespace RpcFunctions { export function hashDenomPub(denomPub: string): string { return native.RsaPublicKey.fromCrock(denomPub).encode().hash().toCrock(); } + + export function benchmark(repetitions: number): BenchmarkResult { + let time_hash = 0; + for (let i = 0; i < repetitions; i++) { + const start = timer.performanceNow(); + hashString("hello world"); + time_hash += timer.performanceNow() - start; + } + + let time_hash_big = 0; + const ba = new native.ByteArray(4096); + for (let i = 0; i < repetitions; i++) { + ba.randomize(native.RandomQuality.WEAK); + const start = timer.performanceNow(); + ba.hash(); + time_hash_big += timer.performanceNow() - start; + } + + let time_eddsa_create = 0; + for (let i = 0; i < repetitions; i++) { + const start = timer.performanceNow(); + const priv: native.EddsaPrivateKey = native.EddsaPrivateKey.create(); + time_eddsa_create += timer.performanceNow() - start; + priv.destroy(); + } + + let time_eddsa_sign = 0; + const eddsaPriv: native.EddsaPrivateKey = native.EddsaPrivateKey.create(); + const eddsaPub: native.EddsaPublicKey = eddsaPriv.getPublicKey(); + const h: native.HashCode = new native.HashCode(); + h.alloc(); + h.random(native.RandomQuality.WEAK); + + const ps = new native.PaymentSignaturePS({ + contract_hash: h, + }); + + const p = ps.toPurpose(); + + for (let i = 0; i < repetitions; i++) { + const start = timer.performanceNow(); + native.eddsaSign(p, eddsaPriv); + time_eddsa_sign += timer.performanceNow() - start; + } + + const eddsaSig = native.eddsaSign(p, eddsaPriv); + + let time_ecdsa_create = 0; + for (let i = 0; i < repetitions; i++) { + const start = timer.performanceNow(); + const priv: native.EcdsaPrivateKey = native.EcdsaPrivateKey.create(); + time_ecdsa_create += timer.performanceNow() - start; + priv.destroy(); + } + + + let time_eddsa_verify = 0; + for (let i = 0; i < repetitions; i++) { + const start = timer.performanceNow(); + native.eddsaVerify(native.SignaturePurpose.MERCHANT_PAYMENT_OK, + p, + eddsaSig, + eddsaPub); + time_eddsa_verify += timer.performanceNow() - start; + } + + return { + repetitions, + time: { + hash_small: time_hash, + hash_big: time_hash_big, + eddsa_create: time_eddsa_create, + eddsa_sign: time_eddsa_sign, + eddsa_verify: time_eddsa_verify, + ecdsa_create: time_ecdsa_create, + } + }; + } } diff --git a/src/crypto/emscInterface.ts b/src/crypto/emscInterface.ts index ce52c88bd..0662f4a71 100644 --- a/src/crypto/emscInterface.ts +++ b/src/crypto/emscInterface.ts @@ -189,7 +189,7 @@ export class HashContext implements ArenaObject { /** - * Arena object that points to an allocaed block of memory. + * Arena object that points to an allocated block of memory. */ abstract class MallocArenaObject implements ArenaObject { protected _nativePtr: number | undefined = undefined; @@ -303,7 +303,7 @@ class SyncArena extends SimpleArena { } } -const arenaStack: Arena[] = []; +export const arenaStack: Arena[] = []; arenaStack.push(new SyncArena()); diff --git a/src/i18n/de.po b/src/i18n/de.po index 6264e7cd7..94ad58bb6 100644 --- a/src/i18n/de.po +++ b/src/i18n/de.po @@ -326,7 +326,7 @@ msgstr "" msgid "tip" msgstr "" -#: src/webex/pages/popup.tsx:414 +#: src/webex/pages/popup.tsx:415 #, fuzzy, c-format msgid "Merchant %1$s gave a %2$s of %3$s." msgstr "" diff --git a/src/i18n/en-US.po b/src/i18n/en-US.po index 90705c53f..b9625d921 100644 --- a/src/i18n/en-US.po +++ b/src/i18n/en-US.po @@ -320,7 +320,7 @@ msgstr "" msgid "tip" msgstr "" -#: src/webex/pages/popup.tsx:414 +#: src/webex/pages/popup.tsx:415 #, c-format msgid "Merchant %1$s gave a %2$s of %3$s." msgstr "" diff --git a/src/i18n/fr.po b/src/i18n/fr.po index 97fe0a3bc..7f9fc14cf 100644 --- a/src/i18n/fr.po +++ b/src/i18n/fr.po @@ -320,7 +320,7 @@ msgstr "" msgid "tip" msgstr "" -#: src/webex/pages/popup.tsx:414 +#: src/webex/pages/popup.tsx:415 #, c-format msgid "Merchant %1$s gave a %2$s of %3$s." msgstr "" diff --git a/src/i18n/it.po b/src/i18n/it.po index 97fe0a3bc..7f9fc14cf 100644 --- a/src/i18n/it.po +++ b/src/i18n/it.po @@ -320,7 +320,7 @@ msgstr "" msgid "tip" msgstr "" -#: src/webex/pages/popup.tsx:414 +#: src/webex/pages/popup.tsx:415 #, c-format msgid "Merchant %1$s gave a %2$s of %3$s." msgstr "" diff --git a/src/i18n/sv.po b/src/i18n/sv.po index 4ae8d95ce..cff28fd3c 100644 --- a/src/i18n/sv.po +++ b/src/i18n/sv.po @@ -326,7 +326,7 @@ msgstr "Säljaren %1$sgav en återbetalning på %2$s.\n" msgid "tip" msgstr "" -#: src/webex/pages/popup.tsx:414 +#: src/webex/pages/popup.tsx:415 #, fuzzy, c-format msgid "Merchant %1$s gave a %2$s of %3$s." msgstr "Säljaren %1$sgav en återbetalning på %2$s.\n" diff --git a/src/i18n/taler-wallet-webex.pot b/src/i18n/taler-wallet-webex.pot index 97fe0a3bc..7f9fc14cf 100644 --- a/src/i18n/taler-wallet-webex.pot +++ b/src/i18n/taler-wallet-webex.pot @@ -320,7 +320,7 @@ msgstr "" msgid "tip" msgstr "" -#: src/webex/pages/popup.tsx:414 +#: src/webex/pages/popup.tsx:415 #, c-format msgid "Merchant %1$s gave a %2$s of %3$s." msgstr "" diff --git a/src/timer.ts b/src/timer.ts index 9439b7199..ea7d34470 100644 --- a/src/timer.ts +++ b/src/timer.ts @@ -49,7 +49,7 @@ class TimeoutHandle { /** * Get a performance counter in milliseconds. */ -export let performanceNow = (() => { +export const performanceNow: () => number = (() => { if (typeof process !== "undefined" && process.hrtime) { return () => { const t = process.hrtime(); diff --git a/src/wallet.ts b/src/wallet.ts index 8655c59ca..434eb8b8c 100644 --- a/src/wallet.ts +++ b/src/wallet.ts @@ -91,6 +91,7 @@ import { } from "./talerTypes"; import { Badge, + BenchmarkResult, CheckPayResult, CoinSelectionResult, CoinWithDenom, @@ -3034,4 +3035,8 @@ export class Wallet { clearNotification(): void { this.badge.clearNotification(); } + + benchmarkCrypto(repetitions: number): Promise<BenchmarkResult> { + return this.cryptoApi.benchmark(repetitions); + } } diff --git a/src/walletTypes.ts b/src/walletTypes.ts index 562d12dfa..b6355db0d 100644 --- a/src/walletTypes.ts +++ b/src/walletTypes.ts @@ -470,6 +470,11 @@ export interface Badge { clearNotification(): void; } +export interface BenchmarkResult { + time: { [s: string]: number }; + repetitions: number; +} + /** * Cached next URL for a particular session id. diff --git a/src/webex/messages.ts b/src/webex/messages.ts index 45cac6a9f..8bb9cafe5 100644 --- a/src/webex/messages.ts +++ b/src/webex/messages.ts @@ -205,6 +205,10 @@ export interface MessageMap { request: { contractTermsHash: string } response: void; }; + "benchmark-crypto": { + request: { repetitions: number } + response: walletTypes.BenchmarkResult; + }; } /** diff --git a/src/webex/pages/confirm-contract.tsx b/src/webex/pages/confirm-contract.tsx index 41eebda8e..d24613794 100644 --- a/src/webex/pages/confirm-contract.tsx +++ b/src/webex/pages/confirm-contract.tsx @@ -25,6 +25,8 @@ */ import * as i18n from "../../i18n"; +import { runOnceWhenReady } from "./common"; + import { ExchangeRecord, ProposalDownloadRecord, @@ -372,7 +374,7 @@ class ContractPrompt extends React.Component<ContractPromptProps, ContractPrompt <i18n.Translate wrap="p"> The merchant{" "}<span>{merchantName}</span> offers you to purchase: </i18n.Translate> - <div style={{"text-align": "center"}}> + <div style={{"textAlign": "center"}}> <strong>{c.summary}</strong> </div> <strong></strong> @@ -395,7 +397,7 @@ class ContractPrompt extends React.Component<ContractPromptProps, ContractPrompt } -document.addEventListener("DOMContentLoaded", () => { +runOnceWhenReady(() => { const url = new URI(document.location.href); const query: any = URI.parseQuery(url.query()); diff --git a/src/webex/pages/popup.tsx b/src/webex/pages/popup.tsx index 6d0134b84..2224a662f 100644 --- a/src/webex/pages/popup.tsx +++ b/src/webex/pages/popup.tsx @@ -27,6 +27,8 @@ */ import * as i18n from "../../i18n"; +import { runOnceWhenReady } from "./common"; + import { AmountJson } from "../../amounts"; import * as Amounts from "../../amounts"; @@ -41,6 +43,7 @@ import * as wxApi from "../wxApi"; import * as React from "react"; import * as ReactDOM from "react-dom"; + import URI = require("urijs"); function onUpdateNotification(f: () => void): () => void { @@ -571,7 +574,7 @@ const el = ( </div> ); -document.addEventListener("DOMContentLoaded", () => { +runOnceWhenReady(() => { ReactDOM.render(el, document.getElementById("content")!); // Will be used by the backend to detect when the popup gets closed, // so we can clear notifications diff --git a/src/webex/wxApi.ts b/src/webex/wxApi.ts index e5da642f1..fde7b8c35 100644 --- a/src/webex/wxApi.ts +++ b/src/webex/wxApi.ts @@ -34,6 +34,7 @@ import { ReserveRecord, } from "../dbTypes"; import { + BenchmarkResult, CheckPayResult, ConfirmPayResult, ReserveCreationInfo, @@ -392,3 +393,11 @@ export function acceptRefund(refundUrl: string): Promise<string> { export function abortFailedPayment(contractTermsHash: string) { return callBackend("abort-failed-payment", { contractTermsHash }); } + + +/** + * Abort a failed payment and try to get a refund. + */ +export function benchmarkCrypto(repetitions: number): Promise<BenchmarkResult> { + return callBackend("benchmark-crypto", { repetitions }); +} diff --git a/src/webex/wxBackend.ts b/src/webex/wxBackend.ts index b1aecbbdd..f2dbd68be 100644 --- a/src/webex/wxBackend.ts +++ b/src/webex/wxBackend.ts @@ -335,6 +335,12 @@ function handleMessage(sender: MessageSender, talerPay(detail, senderUrl, tabId); return; } + case "benchmark-crypto": { + if (!detail.repetitions) { + throw Error("repetitions not given"); + } + return needsWallet().benchmarkCrypto(detail.repetitions); + } default: // Exhaustiveness check. // See https://www.typescriptlang.org/docs/handbook/advanced-types.html @@ -739,7 +745,7 @@ export async function wxMain() { }); window.onerror = (m, source, lineno, colno, error) => { - logging.record("error", m + error, undefined, source || "(unknown)", lineno || 0, colno || 0); + logging.record("error", "".concat(m as any, error as any), undefined, source || "(unknown)", lineno || 0, colno || 0); }; chrome.tabs.query({}, (tabs) => { |