diff options
author | Florian Dold <florian@dold.me> | 2023-12-13 08:02:28 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-12-13 08:02:28 +0100 |
commit | 00b98cb79d1a99d42fbbf6a09eada615b45e8bf6 (patch) | |
tree | 2f1685dbd2e628a7698fc40cc63534dca12ba89d /packages | |
parent | 81878c8cb8484e60cd153af377d30f462b0a69e8 (diff) | |
download | wallet-core-00b98cb79d1a99d42fbbf6a09eada615b45e8bf6.tar.xz |
-actually check master pub in addExchange
Diffstat (limited to 'packages')
-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: { |