exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

commit 7e22616f7ccd18fc7b2e5aeb15f285317554b5d7
parent 6f1e7bd8414748bdbe69b6ffb81bc3f37d6ca3ba
Author: Christian Grothoff <christian@grothoff.org>
Date:   Fri,  2 May 2025 21:33:42 +0200

add new AML programs for address valdiations (for #9852)

Diffstat:
Msrc/kyclogic/Makefile.am | 3+++
Asrc/kyclogic/taler-exchange-helper-measure-challenger-email-context-check | 124+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/kyclogic/taler-exchange-helper-measure-challenger-postal-context-check | 130+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/kyclogic/taler-exchange-helper-measure-challenger-sms-context-check | 124+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/kyclogic/taler-exchange-helper-measure-tops-address-check | 2+-
5 files changed, 382 insertions(+), 1 deletion(-)

diff --git a/src/kyclogic/Makefile.am b/src/kyclogic/Makefile.am @@ -16,6 +16,9 @@ pkgcfg_DATA = \ bin_SCRIPTS = \ taler-exchange-helper-converter-oauth2-test-full_name \ + taler-exchange-helper-measure-challenger-email-context-check \ + taler-exchange-helper-measure-challenger-postal-context-check \ + taler-exchange-helper-measure-challenger-sms-context-check \ taler-exchange-helper-measure-defaults-but-investigate \ taler-exchange-helper-measure-enable-deposits \ taler-exchange-helper-measure-freeze \ diff --git a/src/kyclogic/taler-exchange-helper-measure-challenger-email-context-check b/src/kyclogic/taler-exchange-helper-measure-challenger-email-context-check @@ -0,0 +1,124 @@ +#!/bin/bash +# +# This file is part of TALER +# Copyright (C) 2025 Taler Systems SA +# +# TALER is free software; you can redistribute it and/or modify it under the +# terms of the GNU 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/license> +# + +# Hard error reporting on. +set -eu + + +# Exit, with error message (hard failure) +function exit_fail() { + echo " FAIL: " "$@" >&2 + EXIT_STATUS=1 + exit "$EXIT_STATUS" +} + +CONF="$HOME/.config/taler-exchange.conf" +VERBOSE=0 + +while getopts 'ac:hirvV' OPTION; +do + case "$OPTION" in + a) + exit 0 + ;; + c) + # shellcheck disable=SC2034 + CONF="$OPTARG" + ;; + h) + echo "This is an AML program that asks the customer to validate an email address given to the measure from the context. It is to be used when AML officers want a specific address to be validated via postal letter." + echo 'Supported options:' + echo ' -a -- show required attributes' + # shellcheck disable=SC2016 + echo ' -c $CONF -- set configuration' + echo ' -h -- print this help' + echo ' -i -- show required inputs' + echo ' -r -- show required context' + echo ' -v -- show version' + echo ' -V -- be verbose' + exit 0 + ;; + i) + # Need attributes, context and current_rules. + echo "context" + echo "current_rules" + exit 0 + ;; + r) + echo "CONTACT_EMAIL" + exit 0 + ;; + v) + echo "$0 v0.0.0" + exit 0 + ;; + V) + VERBOSE=1 + ;; + ?) + exit_fail "Unrecognized command line option" + ;; + esac +done + +if [ 1 = "$VERBOSE" ] +then + echo "Running $0" 1>&2 +fi + +# See https://docs.taler.net/taler-kyc-manual.html#tsref-type-AmlProgramInput +# for the full JSON with possible inputs. + +# First, extract inputs we need +INPUTS=$(jq '{"current_rules":.current_rules,"context":.context}') + +# Get address data +CONTACT_EMAIL=$(echo "$INPUTS" | jq -r '.context.CONTACT_EMAIL') + +# Convert address data to Challenger format as best we can. +ADDRESS=$(jq -n \ + --argjson contact_email \""$CONTACT_EMAIL"\" \ + '{"CONTACT_EMAIL":$contact_email,"read_only":true}') + +# Get current rules. +CURRENT_RULES=$(echo "$INPUTS" | jq '.current_rules // null') +# Get context values. +EXPIRATION_TIME=$(echo "$INPUTS" | jq '.context.expiration_time // .current_rules.expiration_time // null') +# Preserve successor measure. +SUCCESSOR_MEASURE=$(echo "$INPUTS" | jq '.current_rules.successor_measure // null') +# Preserve successor measure. +PROG_NAME=$(echo "$INPUTS" | jq '.context.prog_name // "inform-investigate"') + +# Define custom measure for address validation +CUSTOM_AMEASURES=$(jq -n \ + --argjson address "$ADDRESS" \ + --argjson prog "$PROG_NAME" \ + '{"custom-email-investigation":{"context":{"initial_address":$address},"check_name":"email-registration","prog_name":$prog}}') + +# Finally, output the new rules. +# See https://docs.taler.net/taler-kyc-manual.html#tsref-type-AmlOutcome +# for the required output format. + +jq -n \ + --argjson et "$EXPIRATION_TIME" \ + --argjson sm "$SUCCESSOR_MEASURE" \ + --argjson nm '"custom-email-investigation"' \ + --argjson cma "$CUSTOM_AMEASURES" \ + --argjson nr "$CURRENT_RULES" \ + '{"new_measures":$nm,"new_rules":($nr+{"expiration_time":$et,"successor_measure":$sm,"custom_measures":({}+$nr.custom_measures+$cma)})}|del(..|nulls)' + +exit 0 diff --git a/src/kyclogic/taler-exchange-helper-measure-challenger-postal-context-check b/src/kyclogic/taler-exchange-helper-measure-challenger-postal-context-check @@ -0,0 +1,130 @@ +#!/bin/bash +# +# This file is part of TALER +# Copyright (C) 2025 Taler Systems SA +# +# TALER is free software; you can redistribute it and/or modify it under the +# terms of the GNU 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/license> +# + +# Hard error reporting on. +set -eu + + +# Exit, with error message (hard failure) +function exit_fail() { + echo " FAIL: " "$@" >&2 + EXIT_STATUS=1 + exit "$EXIT_STATUS" +} + +CONF="$HOME/.config/taler-exchange.conf" +VERBOSE=0 + +while getopts 'ac:hirvV' OPTION; +do + case "$OPTION" in + a) + exit 0 + ;; + c) + # shellcheck disable=SC2034 + CONF="$OPTARG" + ;; + h) + echo "This is an AML program that asks the customer to validate an address it given to the measure from the context. It is to be used when AML officers want a specific address to be validated via postal letter." + echo 'Supported options:' + echo ' -a -- show required attributes' + # shellcheck disable=SC2016 + echo ' -c $CONF -- set configuration' + echo ' -h -- print this help' + echo ' -i -- show required inputs' + echo ' -r -- show required context' + echo ' -v -- show version' + echo ' -V -- be verbose' + exit 0 + ;; + i) + # Need attributes, context and current_rules. + echo "context" + echo "current_rules" + exit 0 + ;; + r) + echo "FULL_NAME" + echo "ADDRESS_LINES" + echo "ADDRESS_COUNTRY" + exit 0 + ;; + v) + echo "$0 v0.0.0" + exit 0 + ;; + V) + VERBOSE=1 + ;; + ?) + exit_fail "Unrecognized command line option" + ;; + esac +done + +if [ 1 = "$VERBOSE" ] +then + echo "Running $0" 1>&2 +fi + +# See https://docs.taler.net/taler-kyc-manual.html#tsref-type-AmlProgramInput +# for the full JSON with possible inputs. + +# First, extract inputs we need +INPUTS=$(jq '{"current_rules":.current_rules,"context":.context}') + +# Get address data +CONTACT_NAME=$(echo "$INPUTS" | jq -r '.context.FULL_NAME') +ADDRESS_LINES=$(echo "$INPUTS" | jq '.context.ADDRESS_LINES') +ADDRESS_COUNTRY=$(echo "$INPUTS" | jq -r '.context.ADDRESS_COUNTRY // null') + +# Convert address data to Challenger format as best we can. +ADDRESS=$(jq -n \ + --argjson contact_name \""$CONTACT_NAME"\" \ + --argjson address_lines "$ADDRESS_LINES" \ + --argjson address_country "$ADDRESS_COUNTRY" \ + '{"CONTACT_NAME":$contact_name,"ADDRESS_LINES":$address_lines,"ADDRESS_COUNTRY":$address_country,"read_only":true}') + +# Get current rules. +CURRENT_RULES=$(echo "$INPUTS" | jq '.current_rules // null') +# Get context values. +EXPIRATION_TIME=$(echo "$INPUTS" | jq '.context.expiration_time // .current_rules.expiration_time // null') +# Preserve successor measure. +SUCCESSOR_MEASURE=$(echo "$INPUTS" | jq '.current_rules.successor_measure // null') +# Preserve successor measure. +PROG_NAME=$(echo "$INPUTS" | jq '.context.prog_name // "inform-investigate"') + +# Define custom measure for address validation +CUSTOM_AMEASURES=$(jq -n \ + --argjson address "$ADDRESS" \ + --argjson prog "$PROG_NAME" \ + '{"custom-address-investigation":{"context":{"initial_address":$address},"check_name":"postal-registration","prog_name":$prog}}') + +# Finally, output the new rules. +# See https://docs.taler.net/taler-kyc-manual.html#tsref-type-AmlOutcome +# for the required output format. + +jq -n \ + --argjson et "$EXPIRATION_TIME" \ + --argjson sm "$SUCCESSOR_MEASURE" \ + --argjson nm '"custom-address-investigation"' \ + --argjson cma "$CUSTOM_AMEASURES" \ + --argjson nr "$CURRENT_RULES" \ + '{"new_measures":$nm,"new_rules":($nr+{"expiration_time":$et,"successor_measure":$sm,"custom_measures":({}+$nr.custom_measures+$cma)})}|del(..|nulls)' + +exit 0 diff --git a/src/kyclogic/taler-exchange-helper-measure-challenger-sms-context-check b/src/kyclogic/taler-exchange-helper-measure-challenger-sms-context-check @@ -0,0 +1,124 @@ +#!/bin/bash +# +# This file is part of TALER +# Copyright (C) 2025 Taler Systems SA +# +# TALER is free software; you can redistribute it and/or modify it under the +# terms of the GNU 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/license> +# + +# Hard error reporting on. +set -eu + + +# Exit, with error message (hard failure) +function exit_fail() { + echo " FAIL: " "$@" >&2 + EXIT_STATUS=1 + exit "$EXIT_STATUS" +} + +CONF="$HOME/.config/taler-exchange.conf" +VERBOSE=0 + +while getopts 'ac:hirvV' OPTION; +do + case "$OPTION" in + a) + exit 0 + ;; + c) + # shellcheck disable=SC2034 + CONF="$OPTARG" + ;; + h) + echo "This is an AML program that asks the customer to validate a phone number (via SMS) given to the measure from the context. It is to be used when AML officers want a specific address to be validated via postal letter." + echo 'Supported options:' + echo ' -a -- show required attributes' + # shellcheck disable=SC2016 + echo ' -c $CONF -- set configuration' + echo ' -h -- print this help' + echo ' -i -- show required inputs' + echo ' -r -- show required context' + echo ' -v -- show version' + echo ' -V -- be verbose' + exit 0 + ;; + i) + # Need attributes, context and current_rules. + echo "context" + echo "current_rules" + exit 0 + ;; + r) + echo "CONTACT_PHONE" + exit 0 + ;; + v) + echo "$0 v0.0.0" + exit 0 + ;; + V) + VERBOSE=1 + ;; + ?) + exit_fail "Unrecognized command line option" + ;; + esac +done + +if [ 1 = "$VERBOSE" ] +then + echo "Running $0" 1>&2 +fi + +# See https://docs.taler.net/taler-kyc-manual.html#tsref-type-AmlProgramInput +# for the full JSON with possible inputs. + +# First, extract inputs we need +INPUTS=$(jq '{"current_rules":.current_rules,"context":.context}') + +# Get address data +CONTACT_PHONE=$(echo "$INPUTS" | jq -r '.context.CONTACT_PHONE') + +# Convert address data to Challenger format as best we can. +ADDRESS=$(jq -n \ + --argjson contact_phone \""$CONTACT_PHONE"\" \ + '{"CONTACT_PHONE":$contact_phone,"read_only":true}') + +# Get current rules. +CURRENT_RULES=$(echo "$INPUTS" | jq '.current_rules // null') +# Get context values. +EXPIRATION_TIME=$(echo "$INPUTS" | jq '.context.expiration_time // .current_rules.expiration_time // null') +# Preserve successor measure. +SUCCESSOR_MEASURE=$(echo "$INPUTS" | jq '.current_rules.successor_measure // null') +# Preserve successor measure. +PROG_NAME=$(echo "$INPUTS" | jq '.context.prog_name // "inform-investigate"') + +# Define custom measure for address validation +CUSTOM_AMEASURES=$(jq -n \ + --argjson address "$ADDRESS" \ + --argjson prog "$PROG_NAME" \ + '{"custom-phone-investigation":{"context":{"initial_address":$address},"check_name":"sms-registration","prog_name":$prog}}') + +# Finally, output the new rules. +# See https://docs.taler.net/taler-kyc-manual.html#tsref-type-AmlOutcome +# for the required output format. + +jq -n \ + --argjson et "$EXPIRATION_TIME" \ + --argjson sm "$SUCCESSOR_MEASURE" \ + --argjson nm '"custom-phone-investigation"' \ + --argjson cma "$CUSTOM_AMEASURES" \ + --argjson nr "$CURRENT_RULES" \ + '{"new_measures":$nm,"new_rules":($nr+{"expiration_time":$et,"successor_measure":$sm,"custom_measures":({}+$nr.custom_measures+$cma)})}|del(..|nulls)' + +exit 0 diff --git a/src/kyclogic/taler-exchange-helper-measure-tops-address-check b/src/kyclogic/taler-exchange-helper-measure-tops-address-check @@ -149,7 +149,7 @@ jq -n \ --argjson et "$EXPIRATION_TIME" \ --argjson sm "$SUCCESSOR_MEASURE" \ --argjson nm '"custom-address-investigation"' \ - --argjson cm "$CUSTOM_AMEASURES" \ + --argjson cm "$CUSTOM_MEASURES" \ --argjson cma "$CUSTOM_AMEASURES" \ --argjson nr "$NEW_RULES" \ '{"new_measures":$nm,"new_rules":($nr+{"expiration_time":$et,"successor_measure":$sm,"custom_measures":({}+$nr.custom_measures+$cm+$cma)})}|del(..|nulls)'