commit 61c8480180a97c2af1701fe26078084eedf9527e
parent 1f8a17b3dc1d7ae0fe17cd3bc47687e014ac459a
Author: Florian Dold <dold@taler.net>
Date: Wed, 22 Jul 2026 10:58:39 +0200
wallet: honour the expected master public key in fetchFreshExchange
The function documents that a mismatch throws, but it neither accepted the
option nor forwarded it, and its fast path returned a cached summary without
consulting it.
Diffstat:
1 file changed, 18 insertions(+), 7 deletions(-)
diff --git a/packages/taler-wallet-core/src/exchanges.ts b/packages/taler-wallet-core/src/exchanges.ts
@@ -1245,6 +1245,7 @@ export async function fetchFreshExchange(
baseUrl: string,
options: {
forceUpdate?: boolean;
+ expectedMasterPub?: string;
noBail?: boolean;
} = {},
): Promise<ReadyExchangeSummary> {
@@ -1264,6 +1265,7 @@ export async function fetchFreshExchange(
if (startRes.readySummary) {
// Fast path: Ready exchange is already available!
+ checkExpectedMasterPub(startRes.readySummary, options.expectedMasterPub);
return startRes.readySummary;
}
@@ -1271,6 +1273,21 @@ export async function fetchFreshExchange(
}
/**
+ * Reject a summary that belongs to a different exchange than the caller
+ * expected.
+ */
+function checkExpectedMasterPub(
+ summary: ReadyExchangeSummary,
+ expectedMasterPub: string | undefined,
+): void {
+ if (expectedMasterPub && summary.masterPub !== expectedMasterPub) {
+ throw Error(
+ "public key of the exchange does not match expected public key",
+ );
+ }
+}
+
+/**
* Wait until an exchange is in a ready state.
*
* If options.noBail is set, do not stop waiting when
@@ -1457,13 +1474,7 @@ export async function waitReadyExchange(
scopeInfo,
);
- if (options.expectedMasterPub) {
- if (mySummary.masterPub !== options.expectedMasterPub) {
- throw Error(
- "public key of the exchange does not match expected public key",
- );
- }
- }
+ checkExpectedMasterPub(mySummary, options.expectedMasterPub);
res = mySummary;
return true;
},