Commit f71b09a3 authored by Moul's avatar Moul
Browse files

[enh] #7: cert: Use DuniterPy to retrieve information

parent 5f982f04
......@@ -18,18 +18,20 @@ along with Silkaj. If not, see <>.
import urllib
from time import time
from tabulate import tabulate
from duniterpy.api.bma import wot
from silkaj.auth import auth_method
from silkaj.crypto_tools import get_publickey_from_seed, sign_document_from_seed
from import convert_time, message_exit
from silkaj.network_tools import get_request, post_request, HeadBlock
from silkaj.network_tools import ClientInstance, post_request, HeadBlock
from silkaj.blockchain_tools import BlockchainParams
from silkaj.license import license_approval
from silkaj.wot import is_member, get_uid_from_pubkey, get_informations_for_identity
def send_certification(cli_args):
id_to_certify = get_informations_for_identity(cli_args.subsubcmd)
async def send_certification(cli_args):
client = ClientInstance().client
id_to_certify = await get_informations_for_identity(cli_args.subsubcmd)
main_id_to_certify = id_to_certify["uids"][0]
# Display license and ask for confirmation
......@@ -41,14 +43,15 @@ def send_certification(cli_args):
# Check whether current user is member
issuer_pubkey = get_publickey_from_seed(seed)
issuer_id = get_uid_from_pubkey(issuer_pubkey)
if not is_member(issuer_pubkey, issuer_id):
if not await is_member(issuer_pubkey, issuer_id):
message_exit("Current identity is not member.")
if issuer_pubkey == id_to_certify["pubkey"]:
message_exit("You can’t certify yourself!")
# Check if the certification can be renewed
req = get_request("wot/requirements/" + id_to_certify["pubkey"])["identities"][0]
req = await client(wot.requirements, id_to_certify["pubkey"])
req = req["identities"][0]
for cert in req["certifications"]:
if cert["from"] == issuer_pubkey:
params = BlockchainParams().params
......@@ -70,6 +73,7 @@ def send_certification(cli_args):
if not certification_confirmation(
issuer_id, issuer_pubkey, id_to_certify, main_id_to_certify
await client.close()
cert_doc = generate_certification_document(
issuer_pubkey, id_to_certify, main_id_to_certify
......@@ -78,6 +82,7 @@ def send_certification(cli_args):
# Send certification document
post_request("wot/certify", "cert=" + urllib.parse.quote_plus(cert_doc))
await client.close()
print("Certification successfully sent.")
......@@ -181,7 +181,7 @@ async def manage_cmd():
elif cli_args.subcmd == "cert":
await send_certification(cli_args)
elif cli_args.subcmd == "generate_auth_file":
......@@ -202,9 +202,10 @@ def get_informations_for_identities(identifier):
return results["results"]
def is_member(pubkey, uid):
members = get_request("wot/members")["results"]
for member in members:
async def is_member(pubkey, uid):
client = ClientInstance().client
members = await client(wot.members)
for member in members["results"]:
if pubkey in member["pubkey"] and uid in member["uid"]:
return True
return False
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