exchange

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

taler-exchange-helper-measure-challenger-sms-context-check (4680B)


      1 #!/bin/bash
      2 #
      3 #  This file is part of TALER
      4 #  Copyright (C) 2025 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             exit 0
     37             ;;
     38         c)
     39             # shellcheck disable=SC2034
     40             CONF="$OPTARG"
     41             ;;
     42         h)
     43             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."
     44             echo 'Supported options:'
     45             echo '  -a           -- show required attributes'
     46             # shellcheck disable=SC2016
     47             echo '  -c $CONF     -- set configuration'
     48             echo '  -h           -- print this help'
     49             echo '  -i           -- show required inputs'
     50             echo '  -r           -- show required context'
     51             echo '  -v           -- show version'
     52             echo '  -V           -- be verbose'
     53             exit 0
     54             ;;
     55         i)
     56             # Need attributes, context and current_rules.
     57             echo "context"
     58             echo "current_rules"
     59             exit 0
     60             ;;
     61         r)
     62             echo "CONTACT_PHONE"
     63             exit 0
     64             ;;
     65         v)
     66             echo "$0 v0.0.1"
     67             exit 0
     68             ;;
     69         V)
     70             VERBOSE=1
     71             ;;
     72         ?)
     73         exit_fail "Unrecognized command line option"
     74         ;;
     75     esac
     76 done
     77 
     78 if [ 1 = "$VERBOSE" ]
     79 then
     80     echo "Running $0" 1>&2
     81 fi
     82 
     83 # See https://docs.taler.net/taler-kyc-manual.html#tsref-type-AmlProgramInput
     84 # for the full JSON with possible inputs.
     85 
     86 # First, extract inputs we need
     87 INPUTS=$(jq '{"current_rules":.current_rules,"context":.context}')
     88 
     89 # Get address data
     90 CONTACT_PHONE=$(echo "$INPUTS" | jq -r '.context.CONTACT_PHONE')
     91 
     92 # Convert address data to Challenger format as best we can.
     93 ADDRESS=$(jq -n \
     94     --argjson contact_phone \""$CONTACT_PHONE"\" \
     95     '{"CONTACT_PHONE":$contact_phone,"read_only":true}')
     96 
     97 # Get current rules.
     98 CURRENT_RULES=$(echo "$INPUTS" | jq '.current_rules // null')
     99 
    100 # Get context values.
    101 EXPIRATION_TIME=$(echo "$INPUTS" | jq '.context.expiration_time // .current_rules.expiration_time // null')
    102 
    103 # Get successor measure from current rules, if any (still applies if this new measure expires)
    104 CSUCCESSOR_MEASURE=$(echo "$INPUTS" | jq '.current_rules.successor_measure // null')
    105 # Context for AML program EXEC_NAME, if any.
    106 NEXT_CONTEXT=$(echo "$INPUTS" | jq '.context.next_context // {}')
    107 # Get successor program from context
    108 EXEC_NAME=$(echo "$INPUTS" | jq '.context.exec_name // "taler-exchange-helper-measure-inform-investigate"')
    109 
    110 
    111 # Define custom measure for SMS/phone validation.
    112 # We always first run a program to clear the address validation measure,
    113 # and then run whatever program we were given from the context (if any).
    114 # If none was given in the context, we run 'inform-investigate'.
    115 CUSTOM_AMEASURES=$(jq -n \
    116     --argjson address "$ADDRESS" \
    117     --argjson en "$EXEC_NAME" \
    118     --argjson nc "$NEXT_CONTEXT" \
    119     '{"custom-phone-investigation":{"context":{"initial_address":$address,"exec_name":$en,"next_context":$nc,"clear_measure":"custom-phone-investigation"},"check_name":"sms-registration","prog_name":"clear-measure-and-continue"}}')
    120 
    121 # Finally, output the new rules.
    122 # See https://docs.taler.net/taler-kyc-manual.html#tsref-type-AmlOutcome
    123 # for the required output format.
    124 
    125 jq -n \
    126     --argjson et "$EXPIRATION_TIME" \
    127     --argjson sm "$CSUCCESSOR_MEASURE" \
    128     --argjson nm '"custom-phone-investigation"' \
    129     --argjson cma "$CUSTOM_AMEASURES" \
    130     --argjson nr "$CURRENT_RULES" \
    131     '{"new_measures":$nm,"new_rules":($nr+{"expiration_time":$et,"successor_measure":$sm,"custom_measures":({}+$nr.custom_measures+$cma)})}|del(..|nulls)'
    132 
    133 exit 0