def setParamsUser():
    try:
            
            secp = session.get('secp')
        
            if secp == 'secp256k1':
                params = blind_demo.choose_parameters_secp256k1()
            elif secp == 'secp192k1':
                params = blind_demo.choose_parameters_secp192k1()
            elif secp == 'secp160k1':
                params = blind_demo.choose_parameters_secp160k1()
           
            t1, t2, t3, t4, t5 = blind_demo.get_random_ZR(params.group),blind_demo.get_random_ZR(params.group),blind_demo.get_random_ZR(params.group),blind_demo.get_random_ZR(params.group),blind_demo.get_random_ZR(params.group)
            
            blind_demo.putBytesToSession('t1_bytes',t1, params.group)
            blind_demo.putBytesToSession('t2_bytes',t2, params.group)
            blind_demo.putBytesToSession('t3_bytes',t3, params.group)
            blind_demo.putBytesToSession('t4_bytes',t4, params.group)
            blind_demo.putBytesToSession('t5_bytes',t5, params.group)
            
            rjson = str(t1) + '#' + str(t2) + '#' + str(t3) + '#' + str(t4) + '#' + str(t5)
            
            return rjson
    except Exception as e:
        print(e)
        return "0"
def setParamsIssuer():
    try:
            
            secp = session.get('secp')
        
            if secp == 'secp256k1':
                params = blind_demo.choose_parameters_secp256k1()
            elif secp == 'secp192k1':
                params = blind_demo.choose_parameters_secp192k1()
            elif secp == 'secp160k1':
                params = blind_demo.choose_parameters_secp160k1()
           
            upsilon, mu, s1, s2, d = blind_demo.get_random_ZR(params.group),blind_demo.get_random_ZR(params.group),blind_demo.get_random_ZR(params.group),blind_demo.get_random_ZR(params.group),blind_demo.get_random_ZR(params.group)
            
            blind_demo.putBytesToSession('upsilon_bytes',upsilon, params.group)
            blind_demo.putBytesToSession('mu_bytes',mu, params.group)
            blind_demo.putBytesToSession('s1_bytes',s1, params.group)
            blind_demo.putBytesToSession('s2_bytes',s2, params.group)
            blind_demo.putBytesToSession('d_bytes',d, params.group)
            
            rjson = str(upsilon) + '#' + str(mu) + '#' + str(s1) + '#' + str(s2) + '#' + str(d)
            
            return rjson
    except Exception as e:
        print(e)
        return "0"
def userExecuteOne():
    try:
            user = getUserObj()
            zu = user.protocol_one()
            blind_demo.putBytesToSession('zu_bytes',zu, user.parameters.group)
            
            orig_z = blind_demo.getObjFromSession('z_bytes',user.parameters.group)
            rjson = str(user.UserKeypair.gamma) + '#' + str(user.UserKeypair.xi)+ '#' + str(orig_z) + '#' + str(zu)
            return rjson
    except Exception as e1:
        print(e1)
        return "0"
def issuerExecuteSix():
    try:
            issuer = getIssuerObj()
            orig_xi = blind_demo.getObjFromSession('xi_bytes',issuer.parameters.group)
            
            contractAddress = session.get('cas')
            xiupsilon = issuer.protocol_six(orig_xi)
            blind_demo.putBytesToSession('xiupsilon_bytes',xiupsilon, issuer.parameters.group)
            
            rjson  = str(orig_xi) + "," + str(xiupsilon) + "," + str(contractAddress)
            return rjson
        
    except Exception as e:
        print(e)
        return "0" 
def issuerExecuteFour():
    try:
            issuer = getIssuerObj()
            
            e = blind_demo.getObjFromSession('e_bytes',issuer.parameters.group)
            r,c,_,_,_  = issuer.protocol_four(e)
            
            blind_demo.putBytesToSession('r_bytes',r, issuer.parameters.group)
            blind_demo.putBytesToSession('c_bytes',c, issuer.parameters.group)
            
            rjson = str(r) + ',' + str(c)
            return rjson
    except Exception as e:
        print(e)
        return "0"    
def userExecuteFive():
    try:
            user = getUserObj()
           
            r = blind_demo.getObjFromSession('r_bytes',user.parameters.group)
            c = blind_demo.getObjFromSession('c_bytes',user.parameters.group)
            s1 = blind_demo.getObjFromSession('s1_bytes',user.parameters.group)
            s2 = blind_demo.getObjFromSession('s2_bytes',user.parameters.group)
            d = blind_demo.getObjFromSession('d_bytes',user.parameters.group)
            
            rho, omega, sigma1, sigma2, delta = user.protocol_five(r, c, s1,s2, d)
            
            blind_demo.putBytesToSession('rho_bytes',rho, user.parameters.group)
            blind_demo.putBytesToSession('omega_bytes',omega, user.parameters.group)
            blind_demo.putBytesToSession('sigma1_bytes',sigma1, user.parameters.group)
            blind_demo.putBytesToSession('sigma2_bytes',sigma2, user.parameters.group)
            blind_demo.putBytesToSession('delta_bytes',delta, user.parameters.group)
            
            rjson = str(rho) + ',' + str(omega) + ',' + str(sigma1) + ',' + str(sigma2) + ',' + str(delta)
            
            return rjson
    except Exception as e1:
        print(e1)
        return "0"
def userExecuteThree():
    try:
            user = getUserObj()
            
            orig_z1 = blind_demo.getObjFromSession('z1_bytes',user.parameters.group)
            orig_a = blind_demo.getObjFromSession('a_bytes',user.parameters.group)
            orig_b1 = blind_demo.getObjFromSession('b1_bytes',user.parameters.group)
            orig_b2 = blind_demo.getObjFromSession('b2_bytes',user.parameters.group)
            
            
            m = str(request.form['m'])
            
            m = bytes(m,'utf-8')
            session['m'] = m
            
            user.protocol_three(orig_z1, orig_a, orig_b1, orig_b2, m)
            
            blind_demo.putBytesToSession('zeta1_bytes',user.zeta1, user.parameters.group)
            blind_demo.putBytesToSession('zeta2_bytes',user.zeta2, user.parameters.group)
            blind_demo.putBytesToSession('alpha_bytes',user.alpha, user.parameters.group)
            blind_demo.putBytesToSession('beta1_bytes',user.beta1, user.parameters.group)
            blind_demo.putBytesToSession('beta2_bytes',user.beta2, user.parameters.group)
            blind_demo.putBytesToSession('epsilon_bytes',user.epsilon, user.parameters.group)
            blind_demo.putBytesToSession('e_bytes',user.e, user.parameters.group)
            
            rjson = str(user.zeta1) + ',' + str(user.zeta2) + ',' + str(user.alpha)+ ',' + str(user.beta1)+ ',' + str(user.beta2)+ ',' + str(user.epsilon)+ ',' + str(user.e)
            
            return rjson
    except Exception as e1:
        print(e1)
        return "0"
def issuerExecuteTwo():
    try:
            issuer = getIssuerObj()
            orig_zu = blind_demo.getObjFromSession('zu_bytes',issuer.parameters.group)
            
            tracerparams = blind_demo.tracer_choose_keypair(issuer.parameters.group,issuer.g)
            xt = tracerparams.yt
            yt = tracerparams.yt
            
            blind_demo.putBytesToSession('xt_bytes', xt, issuer.parameters.group)
            blind_demo.putBytesToSession('yt_bytes', yt, issuer.parameters.group)
            issuer.tkey = yt
            
            issuer.protocol_two(orig_zu)
            
            blind_demo.putBytesToSession('z1_bytes', issuer.z1, issuer.parameters.group)
            blind_demo.putBytesToSession('z2_bytes', issuer.z2, issuer.parameters.group)
            blind_demo.putBytesToSession('a_bytes', issuer.a, issuer.parameters.group)
            blind_demo.putBytesToSession('b1_bytes', issuer.b1, issuer.parameters.group)
            blind_demo.putBytesToSession('b2_bytes', issuer.b2, issuer.parameters.group)
            
            rjson = str(issuer.z1) + '#' + str(issuer.z2) + '#' + str(issuer.a) + '#' + str(issuer.b1)+ '#' + str(issuer.b2)
            
            
            
            return rjson
    except Exception as e:
        print(e)
        return "0"