diff --git a/silkaj/cert.py b/silkaj/cert.py index c581c5937bbb0c9f1845d11e4efcd22e9c2b8495..53cd5e8bade7b1fe39e729153b065dd282cf1dc0 100644 --- a/silkaj/cert.py +++ b/silkaj/cert.py @@ -51,32 +51,8 @@ async def send_certification(ctx, uid_pubkey_to_certify): # Authentication key = auth_method() - # Check whether current user is member issuer_pubkey = key.pubkey - issuer = await wot.is_member(issuer_pubkey) - if not issuer: - message_exit("Current identity is not member.") - - if issuer_pubkey == pubkey_to_certify: - message_exit("You can’t certify yourself!") - - # Check if the certification can be renewed - req = await client(bma.wot.requirements, pubkey_to_certify) - req = req["identities"][0] - for cert in req["certifications"]: - if cert["from"] == issuer_pubkey: - params = await BlockchainParams().params - # Ğ1: 0<–>2y - 2y + 2m - # ĞT: 0<–>4.8m - 4.8m + 12.5d - renewable = cert["expiresIn"] - params["sigValidity"] + params["sigReplay"] - if renewable > 0: - renewable_date = convert_time(time() + renewable, "date") - message_exit("Certification renewable the " + renewable_date) - - # Check if the certification is already in the pending certifications - for pending_cert in req["pendingCerts"]: - if pending_cert["from"] == issuer_pubkey: - message_exit("Certification is currently been processed") + issuer = await pre_checks(client, issuer_pubkey, pubkey_to_certify) # Display license and ask for confirmation head = await HeadBlock().head_block @@ -88,22 +64,12 @@ async def send_certification(ctx, uid_pubkey_to_certify): ctx, issuer, issuer_pubkey, pubkey_to_certify, idty_to_certify ) - identity = Identity( - version=10, - currency=currency, - pubkey=pubkey_to_certify, - uid=idty_to_certify["uid"], - ts=block_uid(idty_to_certify["meta"]["timestamp"]), - signature=idty_to_certify["self"], - ) - - certification = Certification( - version=10, - currency=currency, - pubkey_from=issuer_pubkey, - identity=identity, - timestamp=BlockUID(head["number"], head["hash"]), - signature="", + certification = docs_generation( + currency, + pubkey_to_certify, + idty_to_certify, + issuer_pubkey, + head, ) if ctx.obj["DISPLAY_DOCUMENT"]: @@ -124,6 +90,35 @@ async def send_certification(ctx, uid_pubkey_to_certify): await client.close() +async def pre_checks(client, issuer_pubkey, pubkey_to_certify): + # Check whether current user is member + issuer = await wot.is_member(issuer_pubkey) + if not issuer: + message_exit("Current identity is not member.") + + if issuer_pubkey == pubkey_to_certify: + message_exit("You can’t certify yourself!") + + # Check if the certification can be renewed + req = await client(bma.wot.requirements, pubkey_to_certify) + req = req["identities"][0] + for cert in req["certifications"]: + if cert["from"] == issuer_pubkey: + params = await BlockchainParams().params + # Ğ1: 0<–>2y - 2y + 2m + # ĞT: 0<–>4.8m - 4.8m + 12.5d + renewable = cert["expiresIn"] - params["sigValidity"] + params["sigReplay"] + if renewable > 0: + renewable_date = convert_time(time() + renewable, "date") + message_exit("Certification renewable the " + renewable_date) + + # Check if the certification is already in the pending certifications + for pending_cert in req["pendingCerts"]: + if pending_cert["from"] == issuer_pubkey: + message_exit("Certification is currently been processed") + return issuer + + async def certification_confirmation( ctx, issuer, issuer_pubkey, pubkey_to_certify, idty_to_certify ): @@ -159,3 +154,23 @@ async def confirmation(): client = ClientInstance().client await client.close() sys.exit(SUCCESS_EXIT_STATUS) + + +def docs_generation(currency, pubkey_to_certify, idty_to_certify, issuer_pubkey, head): + identity = Identity( + version=10, + currency=currency, + pubkey=pubkey_to_certify, + uid=idty_to_certify["uid"], + ts=block_uid(idty_to_certify["meta"]["timestamp"]), + signature=idty_to_certify["self"], + ) + + return Certification( + version=10, + currency=currency, + pubkey_from=issuer_pubkey, + identity=identity, + timestamp=BlockUID(head["number"], head["hash"]), + signature="", + )