#!/bin/bash


# create a challenge in read only mode
NONCE=$(curl -s 'http://challenger.taler.test:1180/setup/1'   -X 'POST'   -H 'Accept: application/json'   -H 'Accept-Language: en-US,en;q=0.9,es;q=0.8'   -H 'Authorization: Bearer secret-token:chal-secret'  -d '{"ADDRESS_LINES":"addr 123","CONTACT_NAME":"sebas","read_only":true}' | jq .nonce -r)

set -x

# user start the challenge
curl -s 'http://challenger.taler.test:1180/authorize/'$NONCE'?response_type=code&client_id=1&redirect_uri=http%3A%2F%2Fexchange.taler.test%3A1180%2Fkyc-proof%2FemailChallenger&state=yep' \
     -X 'POST'

# change the address, even if it fixed
curl 'http://challenger.taler.test:1180/challenge/'$NONCE \
  --data-raw 'CONTACT_NAME=sebas&ADDRESS_LINES=addr456' \

# no longer read_only
curl -s 'http://challenger.taler.test:1180/authorize/'$NONCE'?response_type=code&client_id=1&redirect_uri=http%3A%2F%2Fexchange.taler.test%3A1180%2Fkyc-proof%2FemailChallenger&state=yep' \
     -X 'POST'
