taler-exchange-helper-measure-tops-postal-check (4452B)
1 #!/bin/bash 2 # 3 # This file is part of TALER 4 # Copyright (C) 2024 Taler Systems SA 5 # 6 # TALER is free software; you can redistribute it and/or modify it under the 7 # terms of the GNU General Public License as published by the Free Software 8 # Foundation; either version 3, or (at your option) any later version. 9 # 10 # TALER is distributed in the hope that it will be useful, but WITHOUT ANY 11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details. 13 # 14 # You should have received a copy of the GNU General Public License along with 15 # TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/license> 16 # 17 18 # Hard error reporting on. 19 set -eu 20 21 22 # Exit, with error message (hard failure) 23 function exit_fail() { 24 echo " FAIL: " "$@" >&2 25 EXIT_STATUS=1 26 exit "$EXIT_STATUS" 27 } 28 29 CONF="$HOME/.config/taler-exchange.conf" 30 VERBOSE=0 31 32 while getopts 'ac:hirvV' OPTION; 33 do 34 case "$OPTION" in 35 a) 36 echo "CONTACT_NAME" 37 echo "ADDRESS_LINES" 38 echo "ADDRESS_COUNTRY" 39 exit 0 40 ;; 41 c) 42 # shellcheck disable=SC2034 43 CONF="$OPTARG" 44 ;; 45 h) 46 echo "This is a KYC measure program that lifts restrictions on withdraw and P2P transfers after a (domestic) postal address was confirmed via PIN/TAN letter. Expiration rules are set based on the context. It should not be confused with the taler-exchange-helper-measure-tops-address-check, which also validates a postal address but then triggers an investigation by AML staff to fully open an account." 47 echo 'Supported options:' 48 echo ' -a -- show required attributes' 49 # shellcheck disable=SC2016 50 echo ' -c $CONF -- set configuration' 51 echo ' -h -- print this help' 52 echo ' -i -- show required inputs' 53 echo ' -r -- show required context' 54 echo ' -v -- show version' 55 echo ' -V -- be verbose' 56 exit 0 57 ;; 58 i) 59 # Need attributes, context and current_rules. 60 echo "attributes" 61 echo "context" 62 echo "current_rules" 63 exit 0 64 ;; 65 r) 66 exit 0 67 ;; 68 v) 69 echo "$0 v0.0.3" 70 exit 0 71 ;; 72 V) 73 VERBOSE=1 74 ;; 75 ?) 76 exit_fail "Unrecognized command line option" 77 ;; 78 esac 79 done 80 81 if [ 1 = "$VERBOSE" ] 82 then 83 echo "Running $0" 1>&2 84 fi 85 86 # See https://docs.taler.net/taler-kyc-manual.html#tsref-type-AmlProgramInput 87 # for the full JSON with possible inputs. 88 89 # First, extract inputs we need 90 INPUTS=$(jq '{"current_rules":.current_rules,"attributes":.attributes,"context":.context}') 91 92 # Get country number. 93 COUNTRY=$(echo "$INPUTS" | jq -r '.attributes.ADDRESS_COUNTRY // null') 94 # Get current rules. 95 CURRENT_RULES=$(echo "$INPUTS" | jq '.current_rules // null') 96 # Get context values. 97 EXPIRATION_TIME=$(echo "$INPUTS" | jq '.context.expiration_time // .attributes.expires // .current_rules.expiration_time // null') 98 SUCCESSOR_MEASURE=$(echo "$INPUTS" | jq '.context.successor_measure // .current_rules.successor_measure // null') 99 CUSTOM_MEASURES=$(echo "$INPUTS" | jq '.context.custom_measures // null') 100 101 # Validate country 102 if eval echo "$COUNTRY" | grep -E -e "${EXCHANGE_AML_PROGRAM_TOPS_POSTAL_CHECK_COUNTRY_REGEX}" > /dev/null 103 then 104 # Valid country 105 # Remove limitation from current rules. 106 NEW_RULES=$(echo "$CURRENT_RULES" | jq 'del(.rules[] | select ((.rule_name=="p2p-domestic-identification-requirement") or (.rule_name=="withdraw-limit-low") ))') 107 TO_INVESTIGATE="false" 108 else 109 # Invalid country 110 echo "Country ${COUNTRY} invalid." 1>&2 111 NEW_RULES="$CURRENT_RULES" 112 TO_INVESTIGATE="true" 113 fi 114 115 # Finally, output the new rules. 116 # See https://docs.taler.net/taler-kyc-manual.html#tsref-type-AmlOutcome 117 # for the required output format. 118 exec jq -n \ 119 --argjson et "$EXPIRATION_TIME" \ 120 --argjson sm "$SUCCESSOR_MEASURE" \ 121 --argjson cm "$CUSTOM_MEASURES" \ 122 --argjson nr "$NEW_RULES" \ 123 --argjson inv "$TO_INVESTIGATE" \ 124 '{"new_rules":($nr+{"expiration_time":$et,"successor_measure":$sm,"custom_measures":({}+$nr.custom_measures+$cm)}),"to_investigate":$inv}|del(..|nulls)'