From a8e342213955de80ebf48972abadbd12e0e7b02a Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 24 Mar 2020 16:34:15 +0530 Subject: [PATCH] fix recoup response schema / add run-until-done --- src/crypto/workers/cryptoApi.ts | 17 ---------- src/crypto/workers/cryptoImplementation.ts | 38 ---------------------- src/headless/taler-wallet-cli.ts | 10 ++++++ src/operations/recoup.ts | 20 ------------ src/types/talerTypes.ts | 32 ------------------ 5 files changed, 10 insertions(+), 107 deletions(-) diff --git a/src/crypto/workers/cryptoApi.ts b/src/crypto/workers/cryptoApi.ts index 31ab4dd7e..0b7c2e233 100644 --- a/src/crypto/workers/cryptoApi.ts +++ b/src/crypto/workers/cryptoApi.ts @@ -388,23 +388,6 @@ export class CryptoApi { ); } - /** - * Validate the signature in a recoup confirmation. - */ - isValidRecoupConfirmation( - recoupCoinPub: EddsaPublicKeyString, - recoupConfirmation: RecoupConfirmation, - exchangeSigningKeys: ExchangeSignKeyJson[], - ): Promise { - return this.doRpc( - "isValidRecoupConfirmation", - 1, - recoupCoinPub, - recoupConfirmation, - exchangeSigningKeys, - ); - } - signDepositPermission( depositInfo: DepositInfo, ): Promise { diff --git a/src/crypto/workers/cryptoImplementation.ts b/src/crypto/workers/cryptoImplementation.ts index 4d03e70f5..55caecb43 100644 --- a/src/crypto/workers/cryptoImplementation.ts +++ b/src/crypto/workers/cryptoImplementation.ts @@ -518,44 +518,6 @@ export class CryptoImplementation { return encodeCrock(sig); } - /** - * Validate the signature in a recoup confirmation. - */ - isValidRecoupConfirmation( - recoupCoinPub: EddsaPublicKeyString, - recoupConfirmation: RecoupConfirmation, - exchangeSigningKeys: ExchangeSignKeyJson[], - ): boolean { - const pubEnc = recoupConfirmation.exchange_pub; - if (!checkSignKeyOkay(pubEnc, exchangeSigningKeys)) { - return false; - } - - const sig = decodeCrock(recoupConfirmation.exchange_sig); - const pub = decodeCrock(pubEnc); - - if (recoupConfirmation.old_coin_pub) { - // We're dealing with a refresh recoup - const p = buildSigPS( - SignaturePurpose.EXCHANGE_CONFIRM_RECOUP_REFRESH, - ).put(timestampToBuffer(recoupConfirmation.timestamp)) - .put(amountToBuffer(Amounts.parseOrThrow(recoupConfirmation.amount))) - .put(decodeCrock(recoupCoinPub)) - .put(decodeCrock(recoupConfirmation.old_coin_pub)).build(); - return eddsaVerify(p, sig, pub) - } else if (recoupConfirmation.reserve_pub) { - const p = buildSigPS( - SignaturePurpose.EXCHANGE_CONFIRM_RECOUP_REFRESH, - ).put(timestampToBuffer(recoupConfirmation.timestamp)) - .put(amountToBuffer(Amounts.parseOrThrow(recoupConfirmation.amount))) - .put(decodeCrock(recoupCoinPub)) - .put(decodeCrock(recoupConfirmation.reserve_pub)).build(); - return eddsaVerify(p, sig, pub) - } else { - throw Error("invalid recoup confirmation"); - } - } - benchmark(repetitions: number): BenchmarkResult { let time_hash = 0; for (let i = 0; i < repetitions; i++) { diff --git a/src/headless/taler-wallet-cli.ts b/src/headless/taler-wallet-cli.ts index 174953919..b88023808 100644 --- a/src/headless/taler-wallet-cli.ts +++ b/src/headless/taler-wallet-cli.ts @@ -241,6 +241,16 @@ walletCli }); }); +walletCli + .subcommand("finishPendingOpt", "run-until-done", { + help: "Run until no more work is left.", + }) + .action(async (args) => { + await withWallet(args, async (wallet) => { + await wallet.runUntilDoneAndStop(); + }); + }); + walletCli .subcommand("handleUri", "handle-uri", { help: "Handle a taler:// URI.", diff --git a/src/operations/recoup.ts b/src/operations/recoup.ts index 163f77591..3c3d0f453 100644 --- a/src/operations/recoup.ts +++ b/src/operations/recoup.ts @@ -153,16 +153,6 @@ async function recoupWithdrawCoin( return; } - const isValid = ws.cryptoApi.isValidRecoupConfirmation( - coin.coinPub, - recoupConfirmation, - exchangeDetails.signingKeys, - ); - - if (!isValid) { - throw Error("invalid recoup confirmation signature"); - } - // FIXME: verify that our expectations about the amount match await ws.db.runWithWriteTransaction( @@ -237,16 +227,6 @@ async function recoupRefreshCoin( return; } - const isValid = ws.cryptoApi.isValidRecoupConfirmation( - coin.coinPub, - recoupConfirmation, - exchangeDetails.signingKeys, - ); - - if (!isValid) { - throw Error("invalid recoup confirmation signature"); - } - const refreshGroupId = await ws.db.runWithWriteTransaction( [Stores.coins, Stores.reserves], async tx => { diff --git a/src/types/talerTypes.ts b/src/types/talerTypes.ts index e5be32abe..90751940d 100644 --- a/src/types/talerTypes.ts +++ b/src/types/talerTypes.ts @@ -194,34 +194,6 @@ export class RecoupConfirmation { * provided if refreshed was true. */ old_coin_pub?: string; - - /** - * How much will the exchange pay back (needed by wallet in - * case coin was partially spent and wallet got restored from backup) - */ - amount: string; - - /** - * Time by which the exchange received the /payback request. - */ - timestamp: Timestamp; - - /** - * the EdDSA signature of TALER_PaybackConfirmationPS using a current - * signing key of the exchange affirming the successful - * payback request, and that the exchange promises to transfer the funds - * by the date specified (this allows the exchange delaying the transfer - * a bit to aggregate additional payback requests into a larger one). - */ - exchange_sig: string; - - /** - * Public EdDSA key of the exchange that was used to generate the signature. - * Should match one of the exchange's signing keys from /keys. It is given - * explicitly as the client might otherwise be confused by clock skew as to - * which signing key was used. - */ - exchange_pub: string; } /** @@ -1010,10 +982,6 @@ export const codecForRecoupConfirmation = () => makeCodecForObject() .property("reserve_pub", makeCodecOptional(codecForString)) .property("old_coin_pub", makeCodecOptional(codecForString)) - .property("amount", codecForString) - .property("timestamp", codecForTimestamp) - .property("exchange_sig", codecForString) - .property("exchange_pub", codecForString) .build("RecoupConfirmation"), );