taler-typescript-core

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

commit 86af1d732d0fd1d929a7ea3a3f7aa5015e2083b7
parent d42d33e4f231f3a4a09a095539a10b4afde5b706
Author: Florian Dold <dold@taler.net>
Date:   Fri, 27 Nov 2026 17:37:53 +0100

wallet-core: report the selected coin's scope for payment choices

Use the same scope as the balance for the first selected coin, including
when a missing token prevents payment. This lets clients format the
amount for audited denominations and coins issued under a previous key.

Diffstat:
Mpackages/taler-harness/src/integrationtests/test-wallet-tokens.ts | 7+++++++
Mpackages/taler-util/src/types-taler-wallet.ts | 3+++
Mpackages/taler-wallet-core/src/observe-transaction.test.ts | 23+++++++++++++++++++++++
Mpackages/taler-wallet-core/src/pay-merchant.ts | 32++++++++++++++++----------------
4 files changed, 49 insertions(+), 16 deletions(-)

diff --git a/packages/taler-harness/src/integrationtests/test-wallet-tokens.ts b/packages/taler-harness/src/integrationtests/test-wallet-tokens.ts @@ -27,6 +27,7 @@ import { Order, OrderInputType, OrderOutputType, + ScopeType, succeedOrThrow, TalerMerchantInstanceHttpClient, TalerProtocolTimestamp, @@ -419,6 +420,11 @@ export async function runWalletTokensTest(t: GlobalTestState) { choicesRes.choices[choiceIndex].status === ChoiceSelectionDetailType.InsufficientBalance, ); + t.assertDeepEqual(choicesRes.choices[choiceIndex].scopeInfo, { + type: ScopeType.Exchange, + currency: "TESTKUDOS", + url: exchange.baseUrl, + }); const tokenDetails = choicesRes.choices[choiceIndex].tokenDetails; logger.info("tokenDetails:", tokenDetails); @@ -524,6 +530,7 @@ export async function runWalletTokensTest(t: GlobalTestState) { choicesRes.choices[choiceIndex].status === ChoiceSelectionDetailType.InsufficientBalance, ); + t.assertTrue(choicesRes.choices[choiceIndex].scopeInfo === undefined); const tokenDetails = choicesRes.choices[choiceIndex].tokenDetails; logger.info("tokenDetails:", tokenDetails); diff --git a/packages/taler-util/src/types-taler-wallet.ts b/packages/taler-util/src/types-taler-wallet.ts @@ -2965,6 +2965,7 @@ export interface ChoiceSelectionDetailPaymentPossible { status: ChoiceSelectionDetailType.PaymentPossible; amountRaw: AmountString; amountEffective: AmountString; + /** Scope of the first selected coin, if any. */ scopeInfo: ScopeInfo | undefined; tokenDetails?: PaymentTokenAvailabilityDetails; } @@ -2972,6 +2973,8 @@ export interface ChoiceSelectionDetailPaymentPossible { export interface ChoiceSelectionDetailInsufficientBalance { status: ChoiceSelectionDetailType.InsufficientBalance; amountRaw: AmountString; + /** Scope of the first selected coin when a required token is missing. */ + scopeInfo?: ScopeInfo; balanceDetails?: PaymentInsufficientBalanceDetails; tokenDetails?: PaymentTokenAvailabilityDetails; } diff --git a/packages/taler-wallet-core/src/observe-transaction.test.ts b/packages/taler-wallet-core/src/observe-transaction.test.ts @@ -1410,6 +1410,7 @@ for (const makeRunner of runnerFactories) { assert.deepEqual(expiredPayment.confirmation.unavailableReasons, [ "expired", ]); + const auditorUrl = "https://auditor.example/"; nextPayment = f.nextSnapshot("txn:payment:payment"); await f.wex.runWalletDbTx(async (tx) => { const ct = await tx.getContractTerms(master); @@ -1420,8 +1421,24 @@ for (const makeRunner of runnerFactories) { { url: exchangeUrl, master_pub: master, priority: 0 }, ]; await tx.upsertContractTerms(ct); + await tx.upsertGlobalCurrencyAuditor({ + currency: "TESTKUDOS", + auditorBaseUrl: auditorUrl, + auditorPub: oldMaster, + }); const details: WalletExchangeDetails = { ...f.details, + auditors: [ + { + auditor_url: auditorUrl, + auditor_pub: oldMaster, + auditor_name: "Auditor", + walletAuditorSignaturesVerified: true, + denomination_keys: [ + { denom_pub_h: master, auditor_sig: master }, + ], + }, + ], wireInfo: { accounts: [ { @@ -1454,6 +1471,7 @@ for (const makeRunner of runnerFactories) { unpaid.payment?.choices[0].status, U.ChoiceSelectionDetailType.InsufficientBalance, ); + assert.equal(unpaid.payment.choices[0].scopeInfo, undefined); const changeCutoff = Math.floor(Date.now() / 1000) + 3; nextPayment = f.nextSnapshot("txn:payment:payment"); await f.wex.runWalletDbTx(async (tx) => { @@ -1564,6 +1582,11 @@ for (const makeRunner of runnerFactories) { choice?.status === U.ChoiceSelectionDetailType.PaymentPossible, ); assert.equal(choice.amountEffective, "TESTKUDOS:4"); + assert.deepEqual(choice.scopeInfo, { + type: ScopeType.Auditor, + currency: "TESTKUDOS", + url: auditorUrl, + }); assert.equal(warmDeadlines.nextRefreshAt, changeCutoff * 1000); const repriced = f.nextSnapshot("warm-change", 2); await observeTransaction(f.wex, { diff --git a/packages/taler-wallet-core/src/pay-merchant.ts b/packages/taler-wallet-core/src/pay-merchant.ts @@ -176,8 +176,8 @@ import { import { refundReasonForPurchase } from "./transaction-amounts.js"; import { WalletDbTransaction } from "./db/transaction.js"; import { acceptDonauBlindSigs, generateDonauPlanchets } from "./donau.js"; +import { BalanceScopeResolver } from "./balance.js"; import { - getExchangeScopeInfoOrUndefined, getLegacyScopesForTransaction, getScopeForAllCoins, getScopeForAllExchanges, @@ -3184,6 +3184,7 @@ export async function getChoicesForPaymentInTx( assertUnreachable(contractTerms); } + let scopeResolver: BalanceScopeResolver | undefined; for (let i = 0; i < tokenSels.length; i++) { const choiceIndex = i; const tokenSelection = tokenSels[choiceIndex]; @@ -3225,20 +3226,28 @@ export async function getChoicesForPaymentInTx( logger.trace("coin selection result", selectCoinsResult); - const exchanges: Set<string> = new Set(); + let scopeInfo: ScopeInfo | undefined; switch (selectCoinsResult.type) { case "success": { + const { coins } = selectCoinsResult.coinSel; amountEffective = await getTotalPaymentCostInTx( wex, tx, currency, - selectCoinsResult.coinSel.coins, + coins, onEligibilityChange, ); - selectCoinsResult.coinSel.coins.forEach((x) => { - exchanges.add(x.exchangeBaseUrl); - }); + const firstCoin = coins[0]; + if (firstCoin) { + scopeResolver ??= await BalanceScopeResolver.load(tx); + scopeInfo = await scopeResolver.resolveScope( + firstCoin.exchangeBaseUrl, + currency, + firstCoin.exchangeMasterPub, + firstCoin.denomPubHash, + ); + } break; } case "failure": { @@ -3257,21 +3266,12 @@ export async function getChoicesForPaymentInTx( ) { choice = { status: ChoiceSelectionDetailType.InsufficientBalance, + scopeInfo, amountRaw: amountRaw, balanceDetails: balanceDetails, tokenDetails: tokenSelection.details, }; } else { - // We use the first known scope for the - // exchanges of the selected coins. - let scopeInfo: ScopeInfo | undefined = undefined; - for (const exch of exchanges) { - const s = await getExchangeScopeInfoOrUndefined(tx, exch); - if (s != null) { - scopeInfo = s; - break; - } - } choice = { status: ChoiceSelectionDetailType.PaymentPossible, scopeInfo,