sandcastle-amp-form (5426B)
1 #!/bin/bash 2 # 3 # This file is part of TALER 4 # Copyright (C) 2014-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 'aic:hrvV' OPTION; 33 do 34 case "$OPTION" in 35 i) 36 echo attributes 37 exit 0 38 ;; 39 a) 40 # This AML program expects as inputs a full_name 41 # and a birthdate. 42 echo "full_name" 43 echo "birthdate" 44 exit 0 45 ;; 46 c) 47 # shellcheck disable=SC2034 48 CONF="$OPTARG" 49 ;; 50 h) 51 echo "This is a KYC measure program that checks the output of a simple FORM submission, and if it passed, increases all limits to EUR:1000. (and does not impose any other limits)" 52 echo 'Supported options:' 53 echo ' -a -- show required attributes' 54 # shellcheck disable=SC2016 55 echo ' -c $CONF -- set configuration' 56 echo ' -h -- print this help' 57 echo ' -r -- show required context' 58 echo ' -v -- show version' 59 echo ' -V -- be verbose' 60 ;; 61 r) 62 # No context is required. 63 exit 0 64 ;; 65 v) 66 echo "$0 v0.0.0" 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 # First, check everything we expect is in stdin. 84 A=$(jq -r .attributes) 85 J=$(echo "$A" | jq -r 'def get($k): 86 if has($k) 87 then .[$k] 88 else error("attribute missing") 89 end; 90 {"full_name":get("full_name"), 91 "birthdate":get("birthdate")}') 92 93 94 # Raise investigation if Name contains mallory 95 # (Very very crude check for demo purposes) 96 TO_INVESTIGATE=false 97 if grep -q "Mallory" <<< "$J"; then 98 TO_INVESTIGATE=true 99 fi 100 101 # See https://docs.taler.net/taler-exchange-manual.html#tsref-type-AmlProgramInput 102 # for the full JSON with possible inputs. 103 104 # New rules apply for 30 days. 105 EXPIRATION=$((3600 * 30 + $(date +%s))) 106 107 # Read currency from the config 108 CURRENCY=$(taler-exchange-config -c $CONF -s exchange -o currency) 109 110 # Finally, output the new rules. 111 # See https://docs.taler.net/taler-exchange-manual.html#tsref-type-AmlOutcome 112 # for the required output format. 113 114 jq -n \ 115 --argjson expiration "$EXPIRATION" \ 116 --argjson to_investigate "$TO_INVESTIGATE" \ 117 --arg currency "$CURRENCY" \ 118 '{ "to_investigate": $to_investigate, 119 "new_rules" : { 120 "custom_measures" : {}, 121 "expiration_time" : { "t_s": $expiration }, 122 "rules" : [ 123 { 124 "operation_type": "WITHDRAW", 125 "threshold" : "\($currency):1000", 126 "timeframe" : { "d_us" : 3600000000 }, 127 "measures" : [ "verboten" ], 128 "display_priority" : 1, 129 "exposed" : true, 130 "is_and_combinator" : true 131 }, 132 { 133 "operation_type": "DEPOSIT", 134 "threshold" : "\($currency):1000", 135 "timeframe" : { "d_us" : 3600000000 }, 136 "measures" : [ "verboten" ], 137 "display_priority" : 1, 138 "exposed" : true, 139 "is_and_combinator" : true 140 }, 141 { 142 "operation_type": "AGGREGATE", 143 "threshold" : "\($currency):1000", 144 "timeframe" : { "d_us" : 3600000000 }, 145 "measures" : [ "verboten" ], 146 "display_priority" : 1, 147 "exposed" : true, 148 "is_and_combinator" : true 149 }, 150 { 151 "operation_type": "MERGE", 152 "threshold" : "\($currency):1000", 153 "timeframe" : { "d_us" : 3600000000 }, 154 "measures" : [ "verboten" ], 155 "display_priority" : 1, 156 "exposed" : true, 157 "is_and_combinator" : true 158 }, 159 { 160 "operation_type": "BALANCE", 161 "threshold" : "\($currency):1000", 162 "timeframe" : { "d_us" : 3600000000 }, 163 "measures" : [ "verboten" ], 164 "display_priority" : 1, 165 "exposed" : true, 166 "is_and_combinator" : true 167 }, 168 { 169 "operation_type": "CLOSE", 170 "threshold" : "\($currency):1000", 171 "timeframe" : { "d_us" : 3600000000 }, 172 "measures" : [ "verboten" ], 173 "display_priority" : 1, 174 "exposed" : true, 175 "is_and_combinator" : true 176 } 177 ] 178 } 179 }' < /dev/null 180 181 exit 0