Commit 4b13c23e authored by Moul's avatar Moul

[wip] #61: add certification script.

parent 9d106d4b
import sys
import webbrowser
import urllib
from auth import auth_method
from tools import get_publickey_from_seed, message_exit, get_current_block, sign_document_from_seed
from network_tools import get_request, get_current_block, post_request
from constants import NO_MATCHING_ID
from wot import is_member, get_pubkey_from_id, get_pubkeys_from_id, get_uid_from_pubkey
from tabulate import tabulate
def send_certification(ep, c):
current_blk = get_current_block(ep)
certified_uid = c.subsubcmd
certified_pubkey = get_pubkey_from_id(ep, certified_uid)
# Check that the id is present on the network
if (certified_pubkey is NO_MATCHING_ID):
# Display license in webbrowser and ask for confirmation
# if current_blk["currency"] is "g1":
# license_approval()
# Authentication
seed = auth_method(c)
# Check if this certification has already been sent (in the sandbox), written into the blockchain
# Check current user is a member
issuer_pubkey = get_publickey_from_seed(seed)
issuer_id = get_uid_from_pubkey(ep, issuer_pubkey)
# if not is_member(ep, issuer_pubkey, issuer_id):
# message_exit("You can not certify an identity as current identity is not member")
# Certification confirmation
if certification_confirmation(issuer_id, issuer_pubkey, certified_uid, certified_pubkey):
cert_doc = generate_certification_document(ep, current_blk, issuer_id, issuer_pubkey, certified_uid)
cert_doc += sign_document_from_seed(cert_doc, seed)
# Send certification document
retour = post_request(ep, "wot/certify", "cert=" + urllib.parse.quote_plus(cert_doc))
print("Certification successfully sent.")
def license_approval():
if (input("In which language would you like to display Ğ1 license [en/fr]? ") is "en"):"")
if (input("Do you approve Ğ1 license [y/n]? ") is not "y"):
def certification_confirmation(issuer_id, issuer_pubkey, certified_uid, certified_pubkey):
cert = list()
cert.append(["Cert", "From", "–>", "To"])
cert.append(["ID", issuer_id, "–>", certified_uid])
cert.append(["Pubkey", issuer_pubkey, "–>", certified_pubkey])
if input(tabulate(cert, tablefmt="fancy_grid") +
"\nDo you confirm sending this certification? [yes/no]: ") == "yes":
def generate_certification_document(ep, current_blk, issuer_id, issuer_pubkey, certified_uid):
id_lookup = get_pubkeys_from_id(ep, certified_uid)[0]
return "Version: 10\n\
Type: Certification\n\
Currency: " + current_blk["currency"] + "\n\
Issuer: " + issuer_pubkey + "\n\
IdtyIssuer: " + id_lookup["pubkey"] + "\n\
IdtyUniqueID: " + certified_uid + "\n\
IdtyTimestamp: " + id_lookup["uids"][0]["meta"]["timestamp"] + "\n\
IdtySignature: " + id_lookup["uids"][0]["self"] + "\n\
CertTimestamp: " + str(current_blk["number"]) + "-" + current_blk["hash"] + "\n"
......@@ -79,3 +79,19 @@ def get_pubkeys_from_id(ep, uid):
return results["results"]
def is_member(ep, pubkey, uid):
members = get_request(ep, "wot/members")["results"]
for member in members:
if (pubkey in member["pubkey"] and uid in member["uid"]):
def get_pubkey_from_id(ep, uid):
members = get_request(ep, "wot/members")["results"]
for member in members:
if (uid in member["uid"]):
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment