summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/util
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2023-11-22 18:18:42 +0100
committerFlorian Dold <florian@dold.me>2023-11-22 18:18:54 +0100
commit5eec408d9fb5e8c2375937166997ef8267a4053c (patch)
tree221b45728ac42c72d6f24ebdc7ffb2b058e3d579 /packages/taler-wallet-core/src/util
parent4028baaa968d4ed6991a1bd50e68afb0a9565b44 (diff)
downloadwallet-core-5eec408d9fb5e8c2375937166997ef8267a4053c.tar.gz
wallet-core-5eec408d9fb5e8c2375937166997ef8267a4053c.tar.bz2
wallet-core-5eec408d9fb5e8c2375937166997ef8267a4053c.zip
wallet-core: check debit account restrictions for deposit
Diffstat (limited to 'packages/taler-wallet-core/src/util')
-rw-r--r--packages/taler-wallet-core/src/util/coinSelection.ts50
1 files changed, 50 insertions, 0 deletions
diff --git a/packages/taler-wallet-core/src/util/coinSelection.ts b/packages/taler-wallet-core/src/util/coinSelection.ts
index 8c90f26f1..9506fff19 100644
--- a/packages/taler-wallet-core/src/util/coinSelection.ts
+++ b/packages/taler-wallet-core/src/util/coinSelection.ts
@@ -26,6 +26,7 @@
import { GlobalIDB } from "@gnu-taler/idb-bridge";
import {
AbsoluteTime,
+ AccountRestriction,
AgeCommitmentProof,
AgeRestriction,
AllowedAuditorInfo,
@@ -42,6 +43,7 @@ import {
Duration,
ForcedCoinSel,
ForcedDenomSel,
+ InternationalizedString,
j2s,
Logger,
parsePaytoUri,
@@ -535,6 +537,30 @@ function selectForced(
return selectedDenom;
}
+export function checkAccountRestriction(
+ paytoUri: string,
+ restrictions: AccountRestriction[],
+): { ok: boolean; hint?: string; hintI18n?: InternationalizedString } {
+ for (const myRestriction of restrictions) {
+ switch (myRestriction.type) {
+ case "deny":
+ return { ok: false };
+ case "regex":
+ const regex = new RegExp(myRestriction.payto_regex);
+ if (!regex.test(paytoUri)) {
+ return {
+ ok: false,
+ hint: myRestriction.human_hint,
+ hintI18n: myRestriction.human_hint_i18n,
+ };
+ }
+ }
+ }
+ return {
+ ok: true,
+ };
+}
+
export interface SelectPayCoinRequestNg {
exchanges: AllowedExchangeInfo[];
auditors: AllowedAuditorInfo[];
@@ -546,6 +572,15 @@ export interface SelectPayCoinRequestNg {
prevPayCoins?: PreviousPayCoins;
requiredMinimumAge?: number;
forcedSelection?: ForcedCoinSel;
+
+ /**
+ * Deposit payto URI, in case we already know the account that
+ * will be deposited into.
+ *
+ * That is typically the case when the wallet does a deposit to
+ * return funds to the user's own bank account.
+ */
+ depositPaytoUri?: string;
}
export type AvailableDenom = DenominationInfo & {
@@ -593,6 +628,20 @@ async function selectPayMerchantCandidates(
AbsoluteTime.fromProtocolTimestamp(x.endStamp),
);
})?.wireFee;
+ let debitAccountCheckOk = false;
+ if (req.depositPaytoUri) {
+ // FIXME: We should somehow propagate the hint here!
+ const checkResult = checkAccountRestriction(
+ req.depositPaytoUri,
+ acc.debit_restrictions,
+ );
+ if (checkResult.ok) {
+ debitAccountCheckOk = true;
+ }
+ } else {
+ debitAccountCheckOk = true;
+ }
+
if (wireFeeStr) {
wireMethodFee = wireFeeStr;
}
@@ -602,6 +651,7 @@ async function selectPayMerchantCandidates(
break;
}
wfPerExchange[exchange.baseUrl] = Amounts.parseOrThrow(wireMethodFee);
+
// 3.- exchange is trusted in the exchange list or auditor list
let accepted = false;
for (const allowedExchange of req.exchanges) {