taler-typescript-core

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

commit c24aaa1d422580fbe4481a1b2fdfa4c77c81013c
parent 9cac91b04e2c0b6e8136a67c3780ec89d210be75
Author: Sebastian <sebasjm@gmail.com>
Date:   Wed, 26 Mar 2025 18:21:43 -0300

add events and update the aml events spec

Diffstat:
Mpackages/taler-util/src/aml/aml-events.ts | 144+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
Mpackages/taler-util/src/http-client/exchange.ts | 2+-
Mpackages/taler-util/src/types-taler-exchange.ts | 6++++++
3 files changed, 92 insertions(+), 60 deletions(-)

diff --git a/packages/taler-util/src/aml/aml-events.ts b/packages/taler-util/src/aml/aml-events.ts @@ -1,4 +1,10 @@ -import { AccountProperties, LegitimizationRuleSet } from "../types-taler-kyc-aml.js"; +import { Amounts } from "../amounts.js"; +import { LimitOperationType } from "../types-taler-exchange.js"; +import { + AccountProperties, + KycRule, + LegitimizationRuleSet, +} from "../types-taler-kyc-aml.js"; /** * List of events triggered by TOPS @@ -41,143 +47,163 @@ export enum GLS_AmlEventsName { export type EventMapInfo<T> = { [name in keyof T]: { /** - * Based on the current properties and next properties, - * the current account limits and new attribues of the account + * Based on the current properties and next properties, + * the current account limits and new attribues of the account * calculate if the event should be triggered. - * + * * return false if there is no enough information to decide. - * - * @param prevState - * @param nextState - * @param newAttributes - * @returns + * + * @param prevLimits current active decision limits, undefined if this account has no active decision yet + * @param nextLimits limits of the decision to be made, undefined if not yet decided + * @param prevState current active decision properties, undefined if this account has no active decision yet + * @param nextState new properties of the account defined by the decision, undefined if not yet decided + * @param newAttributes new information added by this decision + * @returns */ shouldBeTriggered: ( - limits: LegitimizationRuleSet, - prevState: AccountProperties, - nextState: AccountProperties, + prevLimits: KycRule[] | undefined, + nextLimits: KycRule[] | undefined, + prevState: AccountProperties | undefined, + nextState: AccountProperties | undefined, newAttributes: Record<string, unknown>, ) => boolean; }; }; +function isAllowToMakeDeposits(limits: KycRule[]) { + const depositLimits = limits.filter( + (r) => r.operation_type === LimitOperationType.deposit, + ); + // no deposit limits + if (!depositLimits.length) return true; + const zero = depositLimits.find((d) => Amounts.isZero(d.threshold)); + // there is a rule that prohibit deposit + if (zero) return false; + // the cusomter can at least make some deposits + return true; +} + export const AML_EVENTS_INFO: EventMapInfo<typeof TOPS_AmlEventsName> = { ACCOUNT_OPENED: { - shouldBeTriggered(limits, prevState, nextState, attributes) { - return false + shouldBeTriggered(pL, nL, pS, nS, attr) { + //FIXME: implement the correct rule, this is for testing + if (!nL) return false; + return pL === undefined + ? !isAllowToMakeDeposits(nL) + : isAllowToMakeDeposits(pL) && !isAllowToMakeDeposits(nL); }, }, ACCOUNT_CLOSED: { - shouldBeTriggered(limits, prevState, nextState, attributes) { - return false + shouldBeTriggered(pL, nL, pS, nS, attr) { + return false; }, }, ACCOUNT_CLOSED_INT_ORG_PEP: { - shouldBeTriggered(limits, prevState, nextState, attributes) { - return false + shouldBeTriggered(pL, nL, pS, nS, attr) { + return false; }, }, ACCOUNT_OPENED_HIGH_RISK: { - shouldBeTriggered(limits, prevState, nextState, attributes) { - return false + shouldBeTriggered(pL, nL, pS, nS, attr) { + return false; }, }, ACCOUNT_CLOSED_HIGH_RISK: { - shouldBeTriggered(limits, prevState, nextState, attributes) { - return false + shouldBeTriggered(pL, nL, pS, nS, attr) { + return false; }, }, ACCOUNT_OPENED_DOMESTIC_PEP: { - shouldBeTriggered(limits, prevState, nextState, attributes) { - return false + shouldBeTriggered(pL, nL, pS, nS, attr) { + return false; }, }, ACCOUNT_CLOSED_DOMESTIC_PEP: { - shouldBeTriggered(limits, prevState, nextState, attributes) { - return false + shouldBeTriggered(pL, nL, pS, nS, attr) { + return false; }, }, ACCOUNT_OPENED_FOREIGN_PEP: { - shouldBeTriggered(limits, prevState, nextState, attributes) { - return false + shouldBeTriggered(pL, nL, pS, nS, attr) { + return false; }, }, ACCOUNT_CLOSED_FOREIGN_PEP: { - shouldBeTriggered(limits, prevState, nextState, attributes) { - return false + shouldBeTriggered(pL, nL, pS, nS, attr) { + return false; }, }, ACCOUNT_OPENED_HR_COUNTRY: { - shouldBeTriggered(limits, prevState, nextState, attributes) { - return false + shouldBeTriggered(pL, nL, pS, nS, attr) { + return false; }, }, ACCOUNT_CLOSED_HR_COUNTRY: { - shouldBeTriggered(limits, prevState, nextState, attributes) { - return false + shouldBeTriggered(pL, nL, pS, nS, attr) { + return false; }, }, ACCOUNT_INVESTIGATION_COMPLETED: { - shouldBeTriggered(limits, prevState, nextState, attributes) { - return false + shouldBeTriggered(pL, nL, pS, nS, attr) { + return false; }, }, ACCOUNT_INVESTIGATION_STARTED: { - shouldBeTriggered(limits, prevState, nextState, attributes) { - return false + shouldBeTriggered(pL, nL, pS, nS, attr) { + return false; }, }, ACCOUNT_MROS_REPORTED_SUSPICION_SIMPLE: { - shouldBeTriggered(limits, prevState, nextState, attributes) { - return false + shouldBeTriggered(pL, nL, pS, nS, attr) { + return false; }, }, ACCOUNT_MROS_REPORTED_SUSPICION_SUBSTANTIATED: { - shouldBeTriggered(limits, prevState, nextState, attributes) { - return false + shouldBeTriggered(pL, nL, pS, nS, attr) { + return false; }, }, ACCOUNT_OPENED_INT_ORG_PEP: { - shouldBeTriggered(limits, prevState, nextState, attributes) { - return false + shouldBeTriggered(pL, nL, pS, nS, attr) { + return false; }, }, TEST_EVENT_KEY_1: { - shouldBeTriggered(limits, prevState, nextState, attributes) { - return true; + shouldBeTriggered(pL, nL, pS, nS, attr) { + return false; }, }, TEST_EVENT_KEY_2: { - shouldBeTriggered(limits, prevState, nextState, attributes) { - return true; + shouldBeTriggered(pL, nL, pS, nS, attr) { + return false; }, }, TEST_EVENT_KEY_3: { - shouldBeTriggered(limits, prevState, nextState, attributes) { - return true; + shouldBeTriggered(pL, nL, pS, nS, attr) { + return false; }, }, TEST_EVENT_KEY_4: { - shouldBeTriggered(limits, prevState, nextState, attributes) { - return true; + shouldBeTriggered(pL, nL, pS, nS, attr) { + return false; }, }, TEST_EVENT_KEY_5: { - shouldBeTriggered(limits, prevState, nextState, attributes) { - return true; + shouldBeTriggered(pL, nL, pS, nS, attr) { + return false; }, }, }; export const GLS_AML_EVENTS: EventMapInfo<typeof GLS_AmlEventsName> = { ACCOUNT_OPENED: { - shouldBeTriggered(limits, prevState, nextState, attributes) { - return false + shouldBeTriggered(pL, nL, pS, nS, attr) { + return false; }, }, ACCOUNT_CLOSED: { - shouldBeTriggered(limits, prevState, nextState, attributes) { - return false + shouldBeTriggered(pL, nL, pS, nS, attr) { + return false; }, }, -} +}; diff --git a/packages/taler-util/src/http-client/exchange.ts b/packages/taler-util/src/http-client/exchange.ts @@ -992,7 +992,7 @@ export class TalerExchangeHttpClient { } /** - * https://docs.taler.net/core/api-exchange.html#get--aml-$OFFICER_PUB-attributes-$H_PAYTO + * https://docs.taler.net/core/api-exchange.html#post--aml-$OFFICER_PUB-decision * */ async makeAmlDesicion( diff --git a/packages/taler-util/src/types-taler-exchange.ts b/packages/taler-util/src/types-taler-exchange.ts @@ -1972,6 +1972,12 @@ export interface AmlDecisionRequest { // New since protocol **v20**. properties: AccountProperties; + // Array of AML/KYC events to trigger for statistics. + // Note that this information is not covered by the signature + // (which is OK as events are just for statistics). + // New since protocol **v24**. + events?: string[]; + // Space-separated list of measures to trigger // immediately on the account. // Prefixed with a "+" to indicate that the