summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-09-09 21:16:20 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-09-09 21:16:20 +0530
commitf32062ccf030d4a2059db26186476d3962c931e2 (patch)
tree8e927361af7a5c45252bd5298f1222bf5dd3cace /packages/taler-wallet-core
parenta602e6714e09b80599b5db7b340aefcce459c973 (diff)
downloadwallet-core-f32062ccf030d4a2059db26186476d3962c931e2.tar.gz
wallet-core-f32062ccf030d4a2059db26186476d3962c931e2.tar.bz2
wallet-core-f32062ccf030d4a2059db26186476d3962c931e2.zip
check bank's protocol version first, fix typo
Diffstat (limited to 'packages/taler-wallet-core')
-rw-r--r--packages/taler-wallet-core/src/TalerErrorCode.ts7
-rw-r--r--packages/taler-wallet-core/src/operations/versions.ts7
-rw-r--r--packages/taler-wallet-core/src/operations/withdraw.ts31
-rw-r--r--packages/taler-wallet-core/src/types/talerTypes.ts13
4 files changed, 56 insertions, 2 deletions
diff --git a/packages/taler-wallet-core/src/TalerErrorCode.ts b/packages/taler-wallet-core/src/TalerErrorCode.ts
index e1f777f25..e2f6324c6 100644
--- a/packages/taler-wallet-core/src/TalerErrorCode.ts
+++ b/packages/taler-wallet-core/src/TalerErrorCode.ts
@@ -3280,6 +3280,13 @@ export enum TalerErrorCode {
WALLET_TIPPING_COIN_SIGNATURE_INVALID = 7016,
/**
+ * The wallet does not implement a version of the bank integration API that is compatible with the version offered by the bank.
+ * Returned with an HTTP status code of #MHD_HTTP_UNINITIALIZED (0).
+ * (A value of 0 indicates that the error is generated client-side).
+ */
+ WALLET_BANK_INTEGRATION_PROTOCOL_VERSION_INCOMPATIBLE = 7017,
+
+ /**
* End of error code range.
* Returned with an HTTP status code of #MHD_HTTP_UNINITIALIZED (0).
* (A value of 0 indicates that the error is generated client-side).
diff --git a/packages/taler-wallet-core/src/operations/versions.ts b/packages/taler-wallet-core/src/operations/versions.ts
index 31c4921c6..11ff8f528 100644
--- a/packages/taler-wallet-core/src/operations/versions.ts
+++ b/packages/taler-wallet-core/src/operations/versions.ts
@@ -29,6 +29,13 @@ export const WALLET_EXCHANGE_PROTOCOL_VERSION = "8:0:0";
export const WALLET_MERCHANT_PROTOCOL_VERSION = "1:0:0";
/**
+ * Protocol version spoken with the merchant.
+ *
+ * Uses libtool's current:revision:age versioning.
+ */
+export const WALLET_BANK_INTEGRATION_PROTOCOL_VERSION = "0:0:0";
+
+/**
* Cache breaker that is appended to queries such as /keys and /wire
* to break through caching, if it has been accidentally/badly configured
* by the exchange.
diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts b/packages/taler-wallet-core/src/operations/withdraw.ts
index e44ac7cf2..b5670a82d 100644
--- a/packages/taler-wallet-core/src/operations/withdraw.ts
+++ b/packages/taler-wallet-core/src/operations/withdraw.ts
@@ -37,12 +37,13 @@ import {
codecForWithdrawResponse,
WithdrawUriInfoResponse,
WithdrawResponse,
+ codecForTalerConfigResponse,
} from "../types/talerTypes";
import { InternalWalletState } from "./state";
import { parseWithdrawUri } from "../util/taleruri";
import { Logger } from "../util/logging";
import { updateExchangeFromUrl, getExchangeTrust } from "./exchanges";
-import { WALLET_EXCHANGE_PROTOCOL_VERSION } from "./versions";
+import { WALLET_EXCHANGE_PROTOCOL_VERSION, WALLET_BANK_INTEGRATION_PROTOCOL_VERSION } from "./versions";
import * as LibtoolVersion from "../util/libtoolVersion";
import {
@@ -62,6 +63,7 @@ import { URL } from "../util/url";
import { TalerErrorCode } from "../TalerErrorCode";
import { encodeCrock } from "../crypto/talerCrypto";
import { updateRetryInfoTimeout, initRetryInfo } from "../util/retries";
+import { compare } from "../util/libtoolVersion";
const logger = new Logger("withdraw.ts");
@@ -152,8 +154,33 @@ export async function getBankWithdrawalInfo(
if (!uriResult) {
throw Error(`can't parse URL ${talerWithdrawUri}`);
}
+
+ const configReqUrl = new URL(
+ "config",
+ uriResult.bankIntegrationApiBaseUrl,
+ )
+
+ const configResp = await ws.http.get(configReqUrl.href);
+ const config = await readSuccessResponseJsonOrThrow(
+ configResp,
+ codecForTalerConfigResponse(),
+ );
+
+ const versionRes = compare(WALLET_BANK_INTEGRATION_PROTOCOL_VERSION, config.version);
+ if (versionRes?.compatible != true) {
+ const opErr = makeErrorDetails(
+ TalerErrorCode.WALLET_BANK_INTEGRATION_PROTOCOL_VERSION_INCOMPATIBLE,
+ "bank integration protocol version not compatible with wallet",
+ {
+ exchangeProtocolVersion: config.version,
+ walletProtocolVersion: WALLET_BANK_INTEGRATION_PROTOCOL_VERSION,
+ },
+ );
+ throw new OperationFailedError(opErr);
+ }
+
const reqUrl = new URL(
- `api/withdraw-operation/${uriResult.withdrawalOperationId}`,
+ `withdrawal-operation/${uriResult.withdrawalOperationId}`,
uriResult.bankIntegrationApiBaseUrl,
);
const resp = await ws.http.get(reqUrl.href);
diff --git a/packages/taler-wallet-core/src/types/talerTypes.ts b/packages/taler-wallet-core/src/types/talerTypes.ts
index ce83080cc..fe30fa8b9 100644
--- a/packages/taler-wallet-core/src/types/talerTypes.ts
+++ b/packages/taler-wallet-core/src/types/talerTypes.ts
@@ -1455,3 +1455,16 @@ export const codecForMerchantAbortPayRefundStatus = (): Codec<
.alternative("success", codecForMerchantAbortPayRefundSuccessStatus())
.alternative("failure", codecForMerchantAbortPayRefundFailureStatus())
.build("MerchantAbortPayRefundStatus");
+
+export interface TalerConfigResponse {
+ name: string;
+ version: string;
+ currency?: string;
+}
+
+export const codecForTalerConfigResponse = (): Codec<TalerConfigResponse> =>
+ buildCodecForObject<TalerConfigResponse>()
+ .property("name", codecForString())
+ .property("version", codecForString())
+ .property("currency", codecOptional(codecForString()))
+ .build("TalerConfigResponse");