Skip to content
Snippets Groups Projects
Commit fc0c33fd authored by Moul's avatar Moul
Browse files

[mod] cert: Split pre-checks and docs gen into f()

parent e1bd8824
No related branches found
No related tags found
No related merge requests found
...@@ -51,32 +51,8 @@ async def send_certification(ctx, uid_pubkey_to_certify): ...@@ -51,32 +51,8 @@ async def send_certification(ctx, uid_pubkey_to_certify):
# Authentication # Authentication
key = auth_method() key = auth_method()
# Check whether current user is member
issuer_pubkey = key.pubkey issuer_pubkey = key.pubkey
issuer = await wot.is_member(issuer_pubkey) issuer = await pre_checks(client, issuer_pubkey, pubkey_to_certify)
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")
# Display license and ask for confirmation # Display license and ask for confirmation
head = await HeadBlock().head_block head = await HeadBlock().head_block
...@@ -88,22 +64,12 @@ async def send_certification(ctx, uid_pubkey_to_certify): ...@@ -88,22 +64,12 @@ async def send_certification(ctx, uid_pubkey_to_certify):
ctx, issuer, issuer_pubkey, pubkey_to_certify, idty_to_certify ctx, issuer, issuer_pubkey, pubkey_to_certify, idty_to_certify
) )
identity = Identity( certification = docs_generation(
version=10, currency,
currency=currency, pubkey_to_certify,
pubkey=pubkey_to_certify, idty_to_certify,
uid=idty_to_certify["uid"], issuer_pubkey,
ts=block_uid(idty_to_certify["meta"]["timestamp"]), head,
signature=idty_to_certify["self"],
)
certification = Certification(
version=10,
currency=currency,
pubkey_from=issuer_pubkey,
identity=identity,
timestamp=BlockUID(head["number"], head["hash"]),
signature="",
) )
if ctx.obj["DISPLAY_DOCUMENT"]: if ctx.obj["DISPLAY_DOCUMENT"]:
...@@ -124,6 +90,35 @@ async def send_certification(ctx, uid_pubkey_to_certify): ...@@ -124,6 +90,35 @@ async def send_certification(ctx, uid_pubkey_to_certify):
await client.close() 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( async def certification_confirmation(
ctx, issuer, issuer_pubkey, pubkey_to_certify, idty_to_certify ctx, issuer, issuer_pubkey, pubkey_to_certify, idty_to_certify
): ):
...@@ -159,3 +154,23 @@ async def confirmation(): ...@@ -159,3 +154,23 @@ async def confirmation():
client = ClientInstance().client client = ClientInstance().client
await client.close() await client.close()
sys.exit(SUCCESS_EXIT_STATUS) 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="",
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment