diff options
author | Sebastian <sebasjm@gmail.com> | 2021-09-13 15:32:06 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2021-09-13 15:32:15 -0300 |
commit | 9f009873809d5b7e8d1d95d77f009862724c577b (patch) | |
tree | cd424abc49b290c684f9947daa759a9a6fb28150 /packages/taler-wallet-core/src | |
parent | 57b6cd42692584063819ccac3c2218f1283332a4 (diff) | |
download | wallet-core-9f009873809d5b7e8d1d95d77f009862724c577b.tar.xz |
added integration with the wallet-core to get info about the last tos approved
Diffstat (limited to 'packages/taler-wallet-core/src')
-rw-r--r-- | packages/taler-wallet-core/src/db.ts | 5 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/operations/backup/import.ts | 1 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/operations/exchanges.ts | 13 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/operations/withdraw.ts | 37 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/wallet.ts | 2 |
5 files changed, 53 insertions, 5 deletions
diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index 7ea8b9ead..902f749cf 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -450,6 +450,11 @@ export interface ExchangeDetailsRecord { termsOfServiceText: string | undefined; /** + * content-type of the last downloaded termsOfServiceText. + */ + termsOfServiceContentType: string | undefined; + + /** * ETag for last terms of service download. */ termsOfServiceLastEtag: string | undefined; diff --git a/packages/taler-wallet-core/src/operations/backup/import.ts b/packages/taler-wallet-core/src/operations/backup/import.ts index 9eee34cf0..7623ab189 100644 --- a/packages/taler-wallet-core/src/operations/backup/import.ts +++ b/packages/taler-wallet-core/src/operations/backup/import.ts @@ -306,6 +306,7 @@ export async function importBackup( termsOfServiceAcceptedEtag: backupExchangeDetails.tos_accepted_etag, termsOfServiceText: undefined, termsOfServiceLastEtag: undefined, + termsOfServiceContentType: undefined, termsOfServiceAcceptedTimestamp: backupExchangeDetails.tos_accepted_timestamp, wireInfo, diff --git a/packages/taler-wallet-core/src/operations/exchanges.ts b/packages/taler-wallet-core/src/operations/exchanges.ts index cf52e00b6..9cd20c673 100644 --- a/packages/taler-wallet-core/src/operations/exchanges.ts +++ b/packages/taler-wallet-core/src/operations/exchanges.ts @@ -127,20 +127,22 @@ function getExchangeRequestTimeout(e: ExchangeRecord): Duration { return { d_ms: 5000 }; } -interface ExchangeTosDownloadResult { +export interface ExchangeTosDownloadResult { tosText: string; tosEtag: string; + tosContentType: string; } -async function downloadExchangeWithTermsOfService( +export async function downloadExchangeWithTermsOfService( exchangeBaseUrl: string, http: HttpRequestLibrary, timeout: Duration, + contentType: string, ): Promise<ExchangeTosDownloadResult> { const reqUrl = new URL("terms", exchangeBaseUrl); reqUrl.searchParams.set("cacheBreaker", WALLET_CACHE_BREAKER_CLIENT_VERSION); const headers = { - Accept: "text/plain", + Accept: contentType, }; const resp = await http.get(reqUrl.href, { @@ -149,8 +151,9 @@ async function downloadExchangeWithTermsOfService( }); const tosText = await readSuccessResponseTextOrThrow(resp); const tosEtag = resp.headers.get("etag") || "unknown"; + const tosContentType = resp.headers.get("content-type") || "text/plain"; - return { tosText, tosEtag }; + return { tosText, tosEtag, tosContentType }; } /** @@ -469,6 +472,7 @@ async function updateExchangeFromUrlImpl( baseUrl, ws.http, timeout, + "text/plain" ); let recoupGroupId: string | undefined = undefined; @@ -506,6 +510,7 @@ async function updateExchangeFromUrlImpl( wireInfo, termsOfServiceText: tosDownload.tosText, termsOfServiceAcceptedEtag: undefined, + termsOfServiceContentType: tosDownload.tosContentType, termsOfServiceLastEtag: tosDownload.tosEtag, termsOfServiceAcceptedTimestamp: getTimestampNow(), }; diff --git a/packages/taler-wallet-core/src/operations/withdraw.ts b/packages/taler-wallet-core/src/operations/withdraw.ts index 620ad88be..f63723535 100644 --- a/packages/taler-wallet-core/src/operations/withdraw.ts +++ b/packages/taler-wallet-core/src/operations/withdraw.ts @@ -66,6 +66,8 @@ import { WALLET_BANK_INTEGRATION_PROTOCOL_VERSION, WALLET_EXCHANGE_PROTOCOL_VERSION, } from "../versions.js"; +import { stringify } from "querystring"; +import { downloadExchangeWithTermsOfService, ExchangeTosDownloadResult } from "./exchanges"; /** * Logger for this file. @@ -132,6 +134,11 @@ export interface ExchangeWithdrawDetails { termsOfServiceAccepted: boolean; /** + * Tos + */ + tosRequested: ExchangeTosDownloadResult | undefined + + /** * The exchange is trusted directly. */ isTrusted: boolean; @@ -930,6 +937,7 @@ export async function getExchangeWithdrawalInfo( ws: InternalWalletState, baseUrl: string, amount: AmountJson, + tosAcceptedFormat?: string[], ): Promise<ExchangeWithdrawDetails> { const { exchange, @@ -996,6 +1004,34 @@ export async function getExchangeWithdrawalInfo( } } + const noTosDownloaded = + exchangeDetails.termsOfServiceContentType === undefined || + exchangeDetails.termsOfServiceAcceptedEtag === undefined || + exchangeDetails.termsOfServiceText === undefined; + + let tosFound: ExchangeTosDownloadResult | undefined = noTosDownloaded ? undefined : { + tosContentType: exchangeDetails.termsOfServiceContentType!, + tosEtag: exchangeDetails.termsOfServiceAcceptedEtag!, + tosText: exchangeDetails.termsOfServiceText!, + }; + + try { + if (tosAcceptedFormat) for (const format of tosAcceptedFormat) { + const resp = await downloadExchangeWithTermsOfService( + exchangeDetails.exchangeBaseUrl, + ws.http, + { d_ms: 1000 }, + format + ); + if (resp.tosContentType === format) { + tosFound = resp + break + } + } + } catch (e) { + tosFound = undefined + } + const withdrawFee = Amounts.sub( selectedDenoms.totalWithdrawCost, selectedDenoms.totalCoinValue, @@ -1018,6 +1054,7 @@ export async function getExchangeWithdrawalInfo( walletVersion: WALLET_EXCHANGE_PROTOCOL_VERSION, withdrawFee, termsOfServiceAccepted: tosAccepted, + tosRequested: tosFound }; return ret; } diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index cbaf03c3b..a0da3d356 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -696,7 +696,7 @@ async function dispatchRequestInternal( } case "getExchangeWithdrawalInfo": { const req = codecForGetExchangeWithdrawalInfo().decode(payload); - return await getExchangeWithdrawalInfo(ws, req.exchangeBaseUrl, req.amount); + return await getExchangeWithdrawalInfo(ws, req.exchangeBaseUrl, req.amount, req.tosAcceptedFormat); } case "acceptManualWithdrawal": { const req = codecForAcceptManualWithdrawalRequet().decode(payload); |