diff options
-rw-r--r-- | packages/taler-wallet-core/src/operations/exchanges.ts | 19 | ||||
-rw-r--r-- | packages/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 index 69f708364..bf7d4424a 100644 --- 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 index 94d55806e..86a80335e 100644 --- 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: { |