taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 00b98cb79d1a99d42fbbf6a09eada615b45e8bf6
parent 81878c8cb8484e60cd153af377d30f462b0a69e8
Author: Florian Dold <florian@dold.me>
Date:   Wed, 13 Dec 2023 08:02:28 +0100

-actually check master pub in addExchange

Diffstat:
Mpackages/taler-wallet-core/src/operations/exchanges.ts | 19++++++++++++++++++-
Mpackages/taler-wallet-core/src/wallet.ts | 4+++-
2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/packages/taler-wallet-core/src/operations/exchanges.ts b/packages/taler-wallet-core/src/operations/exchanges.ts @@ -821,6 +821,10 @@ export async function waitExchangeEntryUpdated( * * If an exchange entry for the database doesn't exist in the * DB, it will be added ephemerally. + * + * If the expectedMasterPub is given and does not match the actual + * master pub, an exception will be thrown. However, the exchange + * will still have been added as an ephemeral exchange entry. */ export async function fetchFreshExchange( ws: InternalWalletState, @@ -828,6 +832,7 @@ export async function fetchFreshExchange( options: { cancellationToken?: CancellationToken; forceUpdate?: boolean; + expectedMasterPub?: string; } = {}, ): Promise<{ exchange: ExchangeEntryRecord; @@ -837,7 +842,19 @@ export async function fetchFreshExchange( await startUpdateExchangeEntry(ws, canonUrl, { forceUpdate: options.forceUpdate, }); - return waitExchangeEntryUpdated(ws, canonUrl, options.cancellationToken); + const res = await waitExchangeEntryUpdated( + ws, + canonUrl, + options.cancellationToken, + ); + if (options.expectedMasterPub) { + if (res.exchangeDetails.masterPublicKey !== options.expectedMasterPub) { + throw Error( + "public key of the exchange does not match expected public key", + ); + } + } + return res; } /** diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts @@ -948,7 +948,9 @@ async function dispatchRequestInternal<Op extends WalletApiOperation>( } case WalletApiOperation.AddExchange: { const req = codecForAddExchangeRequest().decode(payload); - await fetchFreshExchange(ws, req.exchangeBaseUrl); + await fetchFreshExchange(ws, req.exchangeBaseUrl, { + expectedMasterPub: req.masterPub, + }); return {}; } case WalletApiOperation.UpdateExchangeEntry: {