From cb44202440313ea4405fbc74f4588144134a0821 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 12 Oct 2022 14:36:30 -0300 Subject: adding global fee info from exchange --- .../taler-wallet-core/src/operations/exchanges.ts | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'packages/taler-wallet-core/src/operations/exchanges.ts') 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 { + 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, -- cgit v1.2.3