from gmerkle import g_merkle_GSS as GSS
import test_scenarios as ts
import argparse


parser = argparse.ArgumentParser(description="G-Merkle Group Signature Scheme Proof of Concept")
parser.add_argument("-s","--scenario", help="Choose a scenario to by carried out (1-6)", type=int, default=0)

args = parser.parse_args()
config = vars(args)
scenario_type = config['scenario']

# static number of group members
# member ids go from 1 to number of members
members = 10

# number of signatures per each member
signatures = 5

# scheme instantiation
gmerkle_gs = GSS(members, signatures)

# Merkle root = group public key
gpk = gmerkle_gs.gpk

# message to be signed
message = "Hello world!"

# signing member id
id = 8

def main():
    print(f"Scheme was instantiated by default with {members} members and {signatures} signatures per member.")
    print(f"Default message length is {len(message)} B and default signing member id is {id}.\n")
    print(
'''Scenarios:
1   A member of the group signs a message and signature verified and opened.
2   A wrong signature is verified and opened.
3   An id that does not belong to any member in the group is invoked on sign message.
4   A member of the group signs a message, but runs verify and open over wrong message.
5   A member of the group signs a message, but verify is ran over wrong public key.
6   A member of the group tries to sign too many times - runs out of keys.
7   Exit program
''')

    scenario(int(scenario_type))

    
def scenario(scenario_type: int):
    if 0 < scenario_type < 8:
        if scenario_type==1:
            print("A member of the group signs a message and signature verified and opened.\n")
            ts.scenario_A(gmerkle_gs,id,message,gpk)
        elif scenario_type==2:
            print("A wrong signature is verified and opened.\n")
            ts.scenario_D(gmerkle_gs,message,gpk),
        elif scenario_type==3:
            print("An id that does not belong to any member in the group is invoked on sign message.\n")
            ts.scenario_A(gmerkle_gs,members+1,message,gpk)
        elif scenario_type==4:
            print("A member of the group signs a message, but runs verify and open over wrong message.\n")
            ts.scenario_C(gmerkle_gs,id,message,gpk)
        elif scenario_type==5:
            print("A member of the group signs a message, but verify is ran over wrong public key. Signature can still be opened, because it was created with authority and correctly.\n")
            ts.scenario_A(gmerkle_gs,id,message,ts.wrong_gpk)
        elif scenario_type==6:
            print("A member of the group tries to sign too many times - runs out of keys.\n")
            ts.scenario_B(gmerkle_gs,id,message,signatures+1)
        elif scenario_type==7:
            return
    else:
        print("No valid scenario was chosen.")
        scenario_type = input(f"\nRun scenario: ")
        try:
            scenario(int(scenario_type))
        except ValueError:
            print("Wrong input, exiting program.")

            return


if __name__ == '__main__':
    main()