package meerkat.mixer.proofs;

import meerkat.crypto.concrete.Util;
import meerkat.protobuf.Crypto;

import java.math.BigInteger;

/**
 * A dummy proof that can be used for testing
 */
public class DummySigmaProof {
    public static class Prover implements SigmaProtocol.Prover<Crypto.BigInteger,BigInteger> {

        /**
         * The "statement" to be proved: x + y = z
         */

        final BigInteger x,y,z;
        final BigInteger r;

        public Prover(BigInteger x, BigInteger y, BigInteger z, BigInteger r) {
            this.x = x;
            this.y = y;
            this.z = z;
            this.r = r;
        }

        @Override
        public Crypto.BigInteger getFirstMessage() {
            return Util.encodeBigInteger(r);
        }

        @Override
        public BigInteger getFinalMessage(BigInteger challenge) {
            return challenge.add(r.multiply(x.add(y)));
        }
    }
    public static class Verifier implements SigmaProtocol.Verifier<Crypto.BigInteger,BigInteger> {

        final BigInteger x,y,z;

        public Verifier(BigInteger x, BigInteger y, BigInteger z) {
            this.x = x;
            this.y = y;
            this.z = z;
        }

        @Override
        public boolean verify(Crypto.BigInteger firstMessage, BigInteger challenge, BigInteger finalMessage) {
            BigInteger r = Util.decodeBigInteger(firstMessage);
            return finalMessage.equals(challenge.add(r.multiply(z)));
        }
    }

    public static class Simulator implements SigmaProtocol.Simulator<Crypto.BigInteger,BigInteger> {

        final BigInteger x,y,z;

        BigInteger resp;

        public Simulator(BigInteger x, BigInteger y, BigInteger z) {
            this.x = x;
            this.y = y;
            this.z = z;
        }


        @Override
        public Crypto.BigInteger getFirstMessage(BigInteger challenge) {
            BigInteger r = BigInteger.ONE;
            resp = challenge.add(z);
            return Util.encodeBigInteger(r);
        }

        @Override
        public BigInteger getFinalMessage() {
            return resp;
        }
    }
    
}
