<commit_before>#This script takes an argument which is either Node name or client name
# and returns the public key & verification key

print("\n=======================================================================================================================")
print("\nThis is a script to get the public key and verification key &")
print("Takes either node name or client name to get the keys\n")

import glob
import json
import os
import sys
from raet.nacling import Signer, Privateer

EMPTY_STRING = ''
NODE_OR_CLIENT_NAME = sys.argv.pop(1)
CURRENT_LOGGED_IN_USER = os.getlogin()

path = '/home/'+ CURRENT_LOGGED_IN_USER +'/.plenum/'  + NODE_OR_CLIENT_NAME +'/role/local/role.json'

if(os.path.exists(path)):

    files=glob.glob(path)
    for file in files:
        f = open(file, 'r')
        keyString = EMPTY_STRING.join(f.readlines())
        d = json.loads(keyString)
        prihex = d['prihex']
        sighex = d['sighex']
        f.close()

    privateer = Privateer(prihex)
    pubkey = privateer.pubhex.decode()

    signer = Signer(sighex)
    verifkey = signer.verhex.decode()

    print("\nPublic key is : " + pubkey)
    print("\nVerification key is : " + verifkey)

else:
    print("Sorry, please check the client or node name you've entered")

print("\n\nThank you !\n")
print("\n=======================================================================================================================")
<commit_msg>[#128831433] script created to check the publick key and verification key - refactoring after review - some other modifications revisited-plenum<commit_after>#This script takes an argument which is either Node name or client name
# and returns the public key & verification key

import json
import os
import sys
from raet.nacling import Signer, Privateer

EMPTY_STRING = ''

if(len(sys.argv) > 2):
    raise Exception('provide only one parameter which specifies node or client name')
if(len(sys.argv) < 2):
    raise Exception('provide the parameter which specifies node or client name')

NODE_OR_CLIENT_NAME = sys.argv.pop(1)
CURRENT_LOGGED_IN_USER = "sovrin"

path = '/home/'+ CURRENT_LOGGED_IN_USER +'/.plenum/'  + NODE_OR_CLIENT_NAME +'/role/local/role.json'

if not os.path.exists(path):
    raise Exception("Sorry, please check the client or node name you've entered")
with open(path, "r") as f:
    keyString = f.read().strip()
try:
    d = json.loads(keyString)
except json.decoder.JSONDecodeError:
    raise Exception("non json content exception message here")
if 'prihex' not in d:
    raise ValueError("key not defined in given data")
if 'sighex' not in d:
    raise ValueError("key not defined in given data")


prihex = d['prihex']
sighex = d['sighex']
privateer = Privateer(prihex)
pubkey = privateer.pubhex.decode()
signer = Signer(sighex)
verifkey = signer.verhex.decode()

print("\nPublic key is : " + pubkey)
print("\nVerification key is : " + verifkey)




{'fraction_non_alphanumeric': 0.18615015426808365, 'fraction_numerical': 0.004456633527596846, 'mean_word_length': 4.474671669793621, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3056249', 'n_tokens_mistral': 909, 'n_tokens_neox': 871, 'n_words': 278}