2022-08-01 18:09:06 +02:00
|
|
|
/*
|
|
|
|
This file is part of TALER
|
|
|
|
Copyright (C) 2022 Taler Systems SA
|
|
|
|
|
|
|
|
TALER is free software; you can redistribute it and/or modify it under the
|
|
|
|
terms of the GNU Affero General Public License as published by the Free Software
|
|
|
|
Foundation; either version 3, or (at your option) any later version.
|
|
|
|
|
|
|
|
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License along with
|
|
|
|
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
/**
|
2022-08-08 15:22:45 +02:00
|
|
|
* @file taler_kyclogic_lib.h
|
|
|
|
* @brief server-side KYC API
|
2022-08-01 18:09:06 +02:00
|
|
|
* @author Christian Grothoff
|
|
|
|
*/
|
2022-08-08 15:22:45 +02:00
|
|
|
#ifndef TALER_KYCLOGIC_LIB_H
|
|
|
|
#define TALER_KYCLOGIC_LIB_H
|
2022-08-01 18:09:06 +02:00
|
|
|
|
|
|
|
#include <microhttpd.h>
|
2022-08-08 15:22:45 +02:00
|
|
|
#include <taler_exchangedb_plugin.h>
|
|
|
|
#include <taler_kyclogic_plugin.h>
|
2022-08-01 18:09:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enumeration for our KYC user types.
|
|
|
|
*/
|
2022-08-08 15:22:45 +02:00
|
|
|
enum TALER_KYCLOGIC_KycUserType
|
2022-08-01 18:09:06 +02:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* KYC rule is for an individual.
|
|
|
|
*/
|
2022-08-08 15:22:45 +02:00
|
|
|
TALER_KYCLOGIC_KYC_UT_INDIVIDUAL = 0,
|
2022-08-01 18:09:06 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* KYC rule is for a business.
|
|
|
|
*/
|
2022-08-08 15:22:45 +02:00
|
|
|
TALER_KYCLOGIC_KYC_UT_BUSINESS = 1
|
2022-08-01 18:09:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enumeration of possible events that may trigger
|
|
|
|
* KYC requirements.
|
|
|
|
*/
|
2022-08-08 15:22:45 +02:00
|
|
|
enum TALER_KYCLOGIC_KycTriggerEvent
|
2022-08-01 18:09:06 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Customer withdraws coins.
|
|
|
|
*/
|
2022-08-08 15:22:45 +02:00
|
|
|
TALER_KYCLOGIC_KYC_TRIGGER_WITHDRAW = 0,
|
2022-08-01 18:09:06 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Merchant deposits coins.
|
|
|
|
*/
|
2022-08-08 15:22:45 +02:00
|
|
|
TALER_KYCLOGIC_KYC_TRIGGER_DEPOSIT = 1,
|
2022-08-01 18:09:06 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Wallet receives P2P payment.
|
|
|
|
*/
|
2022-08-08 15:22:45 +02:00
|
|
|
TALER_KYCLOGIC_KYC_TRIGGER_P2P_RECEIVE = 2,
|
2022-08-01 18:09:06 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Wallet balance exceeds threshold.
|
|
|
|
*/
|
2022-08-08 15:22:45 +02:00
|
|
|
TALER_KYCLOGIC_KYC_TRIGGER_WALLET_BALANCE = 3
|
2022-08-01 18:09:06 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse KYC trigger string value from a string
|
|
|
|
* into enumeration value.
|
|
|
|
*
|
|
|
|
* @param trigger_s string to parse
|
|
|
|
* @param[out] trigger set to the value found
|
|
|
|
* @return #GNUNET_OK on success, #GNUNET_NO if option
|
|
|
|
* does not exist, #GNUNET_SYSERR if option is
|
|
|
|
* malformed
|
|
|
|
*/
|
|
|
|
enum GNUNET_GenericReturnValue
|
2022-08-08 15:22:45 +02:00
|
|
|
TALER_KYCLOGIC_kyc_trigger_from_string (
|
|
|
|
const char *trigger_s,
|
|
|
|
enum TALER_KYCLOGIC_KycTriggerEvent *trigger);
|
2022-08-01 18:09:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert KYC trigger value to human-readable string.
|
|
|
|
*
|
|
|
|
* @param trigger value to convert
|
|
|
|
* @return human-readable representation of the @a trigger
|
|
|
|
*/
|
|
|
|
const char *
|
2022-08-08 15:22:45 +02:00
|
|
|
TALER_KYCLOGIC_kyc_trigger2s (enum TALER_KYCLOGIC_KycTriggerEvent trigger);
|
2022-08-01 18:09:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse user type string into enumeration value.
|
|
|
|
*
|
|
|
|
* @param ut_s string to parse
|
|
|
|
* @param[out] ut set to the value found
|
|
|
|
* @return #GNUNET_OK on success, #GNUNET_NO if option
|
|
|
|
* does not exist, #GNUNET_SYSERR if option is
|
|
|
|
* malformed
|
|
|
|
*/
|
|
|
|
enum GNUNET_GenericReturnValue
|
2022-08-08 15:22:45 +02:00
|
|
|
TALER_KYCLOGIC_kyc_user_type_from_string (const char *ut_s,
|
|
|
|
enum TALER_KYCLOGIC_KycUserType *ut);
|
2022-08-01 18:09:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert KYC user type to human-readable string.
|
|
|
|
*
|
|
|
|
* @param ut value to convert
|
|
|
|
* @return human-readable representation of the @a ut
|
|
|
|
*/
|
|
|
|
const char *
|
2022-08-08 15:22:45 +02:00
|
|
|
TALER_KYCLOGIC_kyc_user_type2s (enum TALER_KYCLOGIC_KycUserType ut);
|
2022-08-01 18:09:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2022-08-08 15:22:45 +02:00
|
|
|
* Initialize KYC subsystem. Loads the KYC configuration.
|
2022-08-01 18:09:06 +02:00
|
|
|
*
|
2022-08-08 15:22:45 +02:00
|
|
|
* @param cfg configuration to parse
|
2022-08-01 18:09:06 +02:00
|
|
|
* @return #GNUNET_OK on success
|
|
|
|
*/
|
|
|
|
enum GNUNET_GenericReturnValue
|
2022-08-08 15:22:45 +02:00
|
|
|
TALER_KYCLOGIC_kyc_init (const struct GNUNET_CONFIGURATION_Handle *cfg);
|
2022-08-01 18:09:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shut down the KYC subsystem.
|
|
|
|
*/
|
|
|
|
void
|
2022-08-08 15:22:45 +02:00
|
|
|
TALER_KYCLOGIC_kyc_done (void);
|
2022-08-01 18:09:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function called to iterate over KYC-relevant
|
|
|
|
* transaction amounts for a particular time range.
|
|
|
|
* Called within a database transaction, so must
|
|
|
|
* not start a new one.
|
|
|
|
*
|
|
|
|
* @param cls closure, identifies the event type and
|
|
|
|
* account to iterate over events for
|
|
|
|
* @param limit maximum time-range for which events
|
|
|
|
* should be fetched (timestamp in the past)
|
|
|
|
* @param cb function to call on each event found,
|
|
|
|
* events must be returned in reverse chronological
|
|
|
|
* order
|
|
|
|
* @param cb_cls closure for @a cb
|
|
|
|
*/
|
2022-08-04 12:52:30 +02:00
|
|
|
typedef void
|
2022-08-08 15:22:45 +02:00
|
|
|
(*TALER_KYCLOGIC_KycAmountIterator)(void *cls,
|
|
|
|
struct GNUNET_TIME_Absolute limit,
|
|
|
|
TALER_EXCHANGEDB_KycAmountCallback cb,
|
|
|
|
void *cb_cls);
|
|
|
|
|
|
|
|
|
2022-08-11 23:35:33 +02:00
|
|
|
/**
|
|
|
|
* Function called to iterate over KYC-relevant
|
|
|
|
* transaction thresholds amounts.
|
|
|
|
*
|
|
|
|
* @param cls closure, identifies the event type and
|
|
|
|
* account to iterate over events for
|
|
|
|
* @param threshold a relevant threshold amount
|
|
|
|
*/
|
|
|
|
typedef void
|
|
|
|
(*TALER_KYCLOGIC_KycThresholdIterator)(void *cls,
|
|
|
|
const struct TALER_Amount *threshold);
|
|
|
|
|
|
|
|
|
2022-08-08 15:22:45 +02:00
|
|
|
/**
|
|
|
|
* Call us on KYC processes satisfied for the given
|
|
|
|
* account. Must match the ``select_satisfied_kyc_processes`` of the exchange database plugin.
|
|
|
|
*
|
|
|
|
* @param cls the @e cls of this struct with the plugin-specific state
|
|
|
|
* @param h_payto account identifier
|
|
|
|
* @param spc function to call for each satisfied KYC process
|
|
|
|
* @param spc_cls closure for @a spc
|
|
|
|
* @return transaction status code
|
|
|
|
*/
|
|
|
|
typedef enum GNUNET_DB_QueryStatus
|
|
|
|
(*TALER_KYCLOGIC_KycSatisfiedIterator)(
|
|
|
|
void *cls,
|
|
|
|
const struct TALER_PaytoHashP *h_payto,
|
|
|
|
TALER_EXCHANGEDB_SatisfiedProviderCallback spc,
|
|
|
|
void *spc_cls);
|
2022-08-01 18:09:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if KYC is provided for a particular operation. Returns the best
|
|
|
|
* provider (configuration section name) that could perform the required
|
|
|
|
* check.
|
|
|
|
*
|
|
|
|
* Called within a database transaction, so must
|
|
|
|
* not start a new one.
|
|
|
|
*
|
|
|
|
* @param event what type of operation is triggering the
|
|
|
|
* test if KYC is required
|
|
|
|
* @param h_payto account the event is about
|
2022-08-08 15:22:45 +02:00
|
|
|
* @param ki callback that returns list of already
|
|
|
|
* satisfied KYC checks, implemented by ``select_satisfied_kyc_processes`` of the exchangedb
|
|
|
|
* @param ki_cls closure for @a ki
|
2022-08-01 18:09:06 +02:00
|
|
|
* @param ai callback offered to inquire about historic
|
|
|
|
* amounts involved in this type of operation
|
|
|
|
* at the given account
|
2022-08-04 12:52:30 +02:00
|
|
|
* @param ai_cls closure for @a ai
|
2022-08-01 18:09:06 +02:00
|
|
|
* @return NULL if no check is needed
|
|
|
|
*/
|
|
|
|
const char *
|
2022-08-08 15:22:45 +02:00
|
|
|
TALER_KYCLOGIC_kyc_test_required (enum TALER_KYCLOGIC_KycTriggerEvent event,
|
|
|
|
const struct TALER_PaytoHashP *h_payto,
|
|
|
|
TALER_KYCLOGIC_KycSatisfiedIterator ki,
|
|
|
|
void *ki_cls,
|
|
|
|
TALER_KYCLOGIC_KycAmountIterator ai,
|
|
|
|
void *ai_cls);
|
2022-08-01 18:09:06 +02:00
|
|
|
|
|
|
|
|
2022-08-11 23:35:33 +02:00
|
|
|
/**
|
|
|
|
* Iterate over all thresholds that are applicable
|
|
|
|
* to a particular type of @a event
|
|
|
|
*
|
|
|
|
* @param event tresholds to look up
|
|
|
|
* @param it function to call on each
|
|
|
|
* @param it_cls closure for @a it
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
TALER_KYCLOGIC_kyc_iterate_thresholds (
|
|
|
|
enum TALER_KYCLOGIC_KycTriggerEvent event,
|
|
|
|
TALER_KYCLOGIC_KycThresholdIterator it,
|
|
|
|
void *it_cls);
|
|
|
|
|
|
|
|
|
2022-08-01 18:09:06 +02:00
|
|
|
/**
|
2022-08-04 11:36:05 +02:00
|
|
|
* Obtain the provider logic for a given @a provider_section_name.
|
2022-08-01 18:09:06 +02:00
|
|
|
*
|
|
|
|
* @param provider_section_name identifies a KYC provider process
|
|
|
|
* @param[out] plugin set to the KYC logic API
|
|
|
|
* @param[out] pd set to the specific operation context
|
|
|
|
* @return #GNUNET_OK on success
|
|
|
|
*/
|
|
|
|
enum GNUNET_GenericReturnValue
|
2022-08-08 15:22:45 +02:00
|
|
|
TALER_KYCLOGIC_kyc_get_logic (const char *provider_section_name,
|
|
|
|
struct TALER_KYCLOGIC_Plugin **plugin,
|
|
|
|
struct TALER_KYCLOGIC_ProviderDetails **pd);
|
2022-08-01 18:09:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
#endif
|