aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/exchanges.ts
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2022-10-12 14:36:30 -0300
committerSebastian <sebasjm@gmail.com>2022-10-12 14:37:26 -0300
commitcb44202440313ea4405fbc74f4588144134a0821 (patch)
treed352c8ccd326bc2859c69ffa00d88068ddd10ccd /packages/taler-wallet-core/src/operations/exchanges.ts
parentef95914cfceebd60584dcb5afc55f980aff22c60 (diff)
downloadwallet-core-cb44202440313ea4405fbc74f4588144134a0821.tar.xz
adding global fee info from exchange
Diffstat (limited to 'packages/taler-wallet-core/src/operations/exchanges.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/exchanges.ts36
1 files changed, 36 insertions, 0 deletions
diff --git a/packages/taler-wallet-core/src/operations/exchanges.ts b/packages/taler-wallet-core/src/operations/exchanges.ts
index 9a6c72577..a26c14fcc 100644
--- a/packages/taler-wallet-core/src/operations/exchanges.ts
+++ b/packages/taler-wallet-core/src/operations/exchanges.ts
@@ -32,6 +32,7 @@ import {
ExchangeDenomination,
ExchangeSignKeyJson,
ExchangeWireJson,
+ GlobalFees,
hashDenomPub,
j2s,
LibtoolVersion,
@@ -269,6 +270,32 @@ async function validateWireInfo(
};
}
+async function validateGlobalFees(
+ ws: InternalWalletState,
+ fees: GlobalFees[],
+ masterPub: string,
+): Promise<GlobalFees[]> {
+ for (const gf of fees) {
+ logger.trace("validating exchange global fees");
+ let isValid = false;
+ if (ws.insecureTrustExchange) {
+ isValid = true;
+ } else {
+ const { valid: v } = await ws.cryptoApi.isValidGlobalFees({
+ masterPub,
+ gf,
+ });
+ isValid = v;
+ }
+
+ if (!isValid) {
+ throw Error("exchange global fees signature invalid: " + gf.master_sig);
+ }
+ }
+
+ return fees;
+}
+
export interface ExchangeInfo {
wire: ExchangeWireJson;
keys: ExchangeKeysDownloadResult;
@@ -359,6 +386,7 @@ interface ExchangeKeysDownloadResult {
expiry: TalerProtocolTimestamp;
recoup: Recoup[];
listIssueDate: TalerProtocolTimestamp;
+ globalFees: GlobalFees[];
}
/**
@@ -432,6 +460,7 @@ async function downloadExchangeKeysInfo(
),
recoup: exchangeKeysJsonUnchecked.recoup ?? [],
listIssueDate: exchangeKeysJsonUnchecked.list_issue_date,
+ globalFees: exchangeKeysJsonUnchecked.global_fees,
};
}
@@ -552,6 +581,12 @@ export async function updateExchangeFromUrlHandler(
keysInfo.masterPublicKey,
);
+ const globalFees = await validateGlobalFees(
+ ws,
+ keysInfo.globalFees,
+ keysInfo.masterPublicKey,
+ );
+
logger.info("finished validating exchange /wire info");
const tosDownload = await downloadTosFromAcceptedFormat(
@@ -594,6 +629,7 @@ export async function updateExchangeFromUrlHandler(
protocolVersion: keysInfo.protocolVersion,
signingKeys: keysInfo.signingKeys,
reserveClosingDelay: keysInfo.reserveClosingDelay,
+ globalFees,
exchangeBaseUrl: r.baseUrl,
wireInfo,
termsOfServiceText: tosDownload.tosText,