commit 06d79e42b9612f994216928635dac5e3238c544a
parent c92834dd171ff89e8fc95de462fe3a12d9bfddc6
Author: Florian Dold <dold@taler.net>
Date: Tue, 10 Nov 2026 16:21:37 +0100
wallet-core: expose active KYC in peer-credit transactions
Diffstat:
2 files changed, 102 insertions(+), 19 deletions(-)
diff --git a/packages/taler-util/src/types-taler-wallet-transactions.ts b/packages/taler-util/src/types-taler-wallet-transactions.ts
@@ -359,6 +359,12 @@ export interface TransactionCommon {
*/
amountEffectiveFinal?: AmountString;
+ /** Exchange-reported review hint for the active KYC requirement only. */
+ kycAmlReview?: boolean;
+
+ /** Retry information for the task supplying error, when present. */
+ retryInfo?: TransactionRetryInfo;
+
error?: TalerErrorDetail;
abortReason?: TalerErrorDetail;
@@ -384,6 +390,11 @@ export interface TransactionCommon {
kycAuthTransferInfo?: KycAuthTransferInfo;
}
+export interface TransactionRetryInfo {
+ retryCounter: number;
+ nextRetry: TalerPreciseTimestamp;
+}
+
export interface KycAuthTransferInfo {
/**
* Payto URI of the account that must make the transfer.
diff --git a/packages/taler-wallet-core/src/pay-peer-push-credit.ts b/packages/taler-wallet-core/src/pay-peer-push-credit.ts
@@ -72,6 +72,7 @@ import {
} from "./common.js";
import {
PeerPushCreditStatus,
+ ReserveRecordStatus,
WithdrawalGroupStatus,
timestampPreciseFromDb,
timestampPreciseToDb,
@@ -214,20 +215,91 @@ export class PeerPushCreditTransactionContext implements TransactionContext {
const peerContractTerms = ct.contractTermsRaw;
- let kycUrl: string | undefined = undefined;
- let kycAccessToken: string | undefined = undefined;
- if (wg?.kycAccessToken && wg.exchangeBaseUrl) {
- // This should not really happen, as the p2p merge
- // should not count towards the withdrawal limit.
- kycUrl = new URL(`kyc-spa/${wg.kycAccessToken}`, wg.exchangeBaseUrl).href;
- kycAccessToken = wg.kycAccessToken;
- } else if (pushInc.kycAccessToken) {
- kycUrl = new URL(
- `kyc-spa/${pushInc.kycAccessToken}`,
- pushInc.exchangeBaseUrl,
- ).href;
- kycAccessToken = pushInc.kycAccessToken;
+ const txState = computePeerPushCreditTransactionState(pushInc);
+ let kycAccessToken: string | undefined;
+ let kycAmlReview: boolean | undefined;
+ let activeRetry = pushRetryRecord;
+ let balanceKyc = false;
+ const withdrawing =
+ pushInc.status === PeerPushCreditStatus.PendingWithdrawing ||
+ pushInc.status === PeerPushCreditStatus.SuspendedWithdrawing;
+ if (withdrawing && wg) {
+ activeRetry = wgRetryRecord;
+ switch (wg.status) {
+ case WithdrawalGroupStatus.PendingKyc:
+ case WithdrawalGroupStatus.SuspendedKyc:
+ kycAccessToken = wg.kycAccessToken;
+ kycAmlReview = wg.kycLastAmlReview;
+ txState.minor = kycAccessToken
+ ? TransactionMinorState.KycRequired
+ : TransactionMinorState.KycInit;
+ txState.working =
+ txState.major === TransactionMajorState.Pending && !kycAccessToken;
+ break;
+ case WithdrawalGroupStatus.PendingBalanceKyc:
+ case WithdrawalGroupStatus.SuspendedBalanceKyc:
+ balanceKyc = true;
+ txState.minor = TransactionMinorState.BalanceKycRequired;
+ txState.working = false;
+ break;
+ case WithdrawalGroupStatus.PendingBalanceKycInit:
+ case WithdrawalGroupStatus.SuspendedBalanceKycInit:
+ balanceKyc = true;
+ txState.minor = TransactionMinorState.KycInit;
+ txState.working = txState.major === TransactionMajorState.Pending;
+ break;
+ case WithdrawalGroupStatus.FinalizingKycHardLimit:
+ txState.minor = TransactionMinorState.KycHardLimit;
+ break;
+ }
+ } else {
+ switch (pushInc.status) {
+ case PeerPushCreditStatus.PendingMergeKycRequired:
+ case PeerPushCreditStatus.SuspendedMergeKycRequired:
+ kycAccessToken = pushInc.kycAccessToken;
+ kycAmlReview = pushInc.kycLastAmlReview;
+ break;
+ case PeerPushCreditStatus.PendingBalanceKycInit:
+ case PeerPushCreditStatus.PendingBalanceKycRequired:
+ case PeerPushCreditStatus.SuspendedBalanceKycInit:
+ case PeerPushCreditStatus.SuspendedBalanceKycRequired:
+ balanceKyc = true;
+ break;
+ }
+ }
+ if (balanceKyc) {
+ const exchange = await tx.getExchange(pushInc.exchangeBaseUrl);
+ const reserve =
+ exchange?.currentMergeReserveRowId == null
+ ? undefined
+ : await tx.getReserve(exchange.currentMergeReserveRowId);
+ // Initialization may retain credentials from a previous requirement.
+ if (
+ txState.minor === TransactionMinorState.BalanceKycRequired &&
+ (reserve?.status === ReserveRecordStatus.PendingLegi ||
+ reserve?.status === ReserveRecordStatus.SuspendedLegi)
+ ) {
+ kycAccessToken = reserve?.kycAccessToken;
+ kycAmlReview = reserve?.amlReview;
+ }
+ activeRetry = await tx.getOperationRetry(
+ constructTaskIdentifier({
+ tag: PendingTaskType.ExchangeWalletKyc,
+ exchangeBaseUrl: pushInc.exchangeBaseUrl,
+ }),
+ );
}
+ const kycUrl = kycAccessToken
+ ? new URL(`kyc-spa/${kycAccessToken}`, pushInc.exchangeBaseUrl).href
+ : undefined;
+ const error = activeRetry?.lastError;
+ const retryInfo =
+ error && activeRetry
+ ? {
+ retryCounter: activeRetry.retryInfo.retryCounter,
+ nextRetry: timestampPreciseFromDb(activeRetry.retryInfo.nextRetry),
+ }
+ : undefined;
if (wg) {
if (wg.wgInfo.withdrawalType !== WithdrawalRecordType.PeerPushCredit) {
@@ -237,7 +309,6 @@ export class PeerPushCreditTransactionContext implements TransactionContext {
checkDbInvariant(wg.denomsSel !== undefined, "wg uninitialized");
checkDbInvariant(wg.exchangeBaseUrl !== undefined, "wg uninitialized");
- const txState = computePeerPushCreditTransactionState(pushInc);
return {
type: TransactionType.PeerPushCredit,
txState,
@@ -259,12 +330,13 @@ export class PeerPushCreditTransactionContext implements TransactionContext {
abortReason: pushInc.abortReason,
failReason: pushInc.failReason,
kycUrl,
+ kycAmlReview,
+ error,
+ retryInfo,
kycPaytoHash: wg.kycPaytoHash,
- ...(wgRetryRecord?.lastError ? { error: wgRetryRecord.lastError } : {}),
};
}
- const txState = computePeerPushCreditTransactionState(pushInc);
return {
type: TransactionType.PeerPushCredit,
txState,
@@ -283,15 +355,15 @@ export class PeerPushCreditTransactionContext implements TransactionContext {
iconId: peerContractTerms.icon_id,
},
kycUrl,
+ kycAmlReview,
+ error,
+ retryInfo,
kycPaytoHash: pushInc.kycPaytoHash,
kycAccessToken,
timestamp: timestampPreciseFromDb(pushInc.timestamp),
transactionId: this.transactionId,
abortReason: pushInc.abortReason,
failReason: pushInc.failReason,
- ...(pushRetryRecord?.lastError
- ? { error: pushRetryRecord.lastError }
- : {}),
};
}