Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
silkaj
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
python
silkaj
Commits
fc0c33fd
Commit
fc0c33fd
authored
4 years ago
by
Moul
Browse files
Options
Downloads
Patches
Plain Diff
[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
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
silkaj/cert.py
+56
-41
56 additions, 41 deletions
silkaj/cert.py
with
56 additions
and
41 deletions
silkaj/cert.py
+
56
−
41
View file @
fc0c33fd
...
@@ -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
=
""
,
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment