Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DuniterPy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
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
DuniterPy
Commits
2fd92deb
Commit
2fd92deb
authored
3 years ago
by
Vincent Texier
Browse files
Options
Downloads
Patches
Plain Diff
[enh]
#95
add Identity.from_lookup_response() to simplify examples
parent
ce59413b
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
duniterpy/documents/identity.py
+33
-0
33 additions, 0 deletions
duniterpy/documents/identity.py
examples/save_revoke_document.py
+5
-25
5 additions, 25 deletions
examples/save_revoke_document.py
examples/send_certification.py
+8
-25
8 additions, 25 deletions
examples/send_certification.py
with
46 additions
and
50 deletions
duniterpy/documents/identity.py
+
33
−
0
View file @
2fd92deb
...
@@ -257,3 +257,36 @@ Timestamp: {timestamp}
...
@@ -257,3 +257,36 @@ Timestamp: {timestamp}
identity
.
signatures
=
[
signature
]
identity
.
signatures
=
[
signature
]
return
identity
return
identity
@classmethod
def
from_lookup_response
(
cls
:
Type
[
IdentityType
],
version
:
int
,
currency
:
str
,
lookup_response
:
dict
)
->
IdentityType
:
"""
Return Identity instance from bma.lookup request response
:param version: Document version
:param currency: Currency codename
:param lookup_response: Lookup request response
:return:
"""
# parse results
pubkey
=
lookup_response
[
"
results
"
][
0
][
"
pubkey
"
]
uids
=
lookup_response
[
"
results
"
][
0
][
"
uids
"
]
uid_data
=
uids
[
0
]
# capture data
timestamp
=
BlockUID
.
from_str
(
uid_data
[
"
meta
"
][
"
timestamp
"
])
uid
=
uid_data
[
"
uid
"
]
# type: str
signature
=
uid_data
[
"
self
"
]
# type: str
# return self-certification document
identity
=
cls
(
version
=
version
,
currency
=
currency
,
pubkey
=
pubkey
,
uid
=
uid
,
timestamp
=
timestamp
,
)
identity
.
signatures
=
[
signature
]
return
identity
This diff is collapsed.
Click to expand it.
examples/save_revoke_document.py
+
5
−
25
View file @
2fd92deb
...
@@ -19,7 +19,7 @@ from typing import Optional
...
@@ -19,7 +19,7 @@ from typing import Optional
from
duniterpy.api
import
bma
from
duniterpy.api
import
bma
from
duniterpy.api.client
import
Client
from
duniterpy.api.client
import
Client
from
duniterpy.documents
import
BlockUID
,
Identity
,
Revocation
from
duniterpy.documents
import
Identity
,
Revocation
from
duniterpy.key
import
SigningKey
from
duniterpy.key
import
SigningKey
if
"
XDG_CONFIG_HOME
"
in
os
.
environ
:
if
"
XDG_CONFIG_HOME
"
in
os
.
environ
:
...
@@ -66,30 +66,10 @@ def get_identity_document(
...
@@ -66,30 +66,10 @@ def get_identity_document(
"""
"""
# Here we request for the path wot/lookup/pubkey
# Here we request for the path wot/lookup/pubkey
lookup_data
=
client
(
bma
.
wot
.
lookup
,
pubkey
)
lookup_data
=
client
(
bma
.
wot
.
lookup
,
pubkey
)
identity
=
None
# parse results
for
result
in
lookup_data
[
"
results
"
]:
if
result
[
"
pubkey
"
]
==
pubkey
:
uids
=
result
[
"
uids
"
]
uid_data
=
uids
[
0
]
# capture data
timestamp
=
BlockUID
.
from_str
(
uid_data
[
"
meta
"
][
"
timestamp
"
])
uid
=
uid_data
[
"
uid
"
]
# type: str
signature
=
uid_data
[
"
self
"
]
# type: str
# return self-certification document
identity
=
Identity
(
version
=
10
,
currency
=
current_block
[
"
currency
"
],
pubkey
=
pubkey
,
uid
=
uid
,
timestamp
=
timestamp
,
)
identity
.
signatures
=
[
signature
]
break
return
identity
return
Identity
.
from_lookup_response
(
PROTOCOL_VERSION
,
current_block
[
"
currency
"
],
lookup_data
)
def
get_signed_raw_revocation_document
(
def
get_signed_raw_revocation_document
(
...
...
This diff is collapsed.
Click to expand it.
examples/send_certification.py
+
8
−
25
View file @
2fd92deb
...
@@ -29,6 +29,9 @@ from duniterpy.key import SigningKey
...
@@ -29,6 +29,9 @@ from duniterpy.key import SigningKey
# Here we use the secure BASIC_MERKLED_API (BMAS)
# Here we use the secure BASIC_MERKLED_API (BMAS)
BMAS_ENDPOINT
=
"
BMAS g1-test.duniter.org 443
"
BMAS_ENDPOINT
=
"
BMAS g1-test.duniter.org 443
"
# Current protocol version
PROTOCOL_VERSION
=
10
################################################
################################################
...
@@ -47,30 +50,10 @@ def get_identity_document(
...
@@ -47,30 +50,10 @@ def get_identity_document(
"""
"""
# Here we request for the path wot/lookup/pubkey
# Here we request for the path wot/lookup/pubkey
lookup_data
=
client
(
bma
.
wot
.
lookup
,
pubkey
)
lookup_data
=
client
(
bma
.
wot
.
lookup
,
pubkey
)
identity
=
None
# parse results
for
result
in
lookup_data
[
"
results
"
]:
if
result
[
"
pubkey
"
]
==
pubkey
:
uids
=
result
[
"
uids
"
]
uid_data
=
uids
[
0
]
# capture data
timestamp
=
BlockUID
.
from_str
(
uid_data
[
"
meta
"
][
"
timestamp
"
])
uid
=
uid_data
[
"
uid
"
]
# type: str
signature
=
uid_data
[
"
self
"
]
# type: str
# return self-certification document
identity
=
Identity
(
version
=
10
,
currency
=
current_block
[
"
currency
"
],
pubkey
=
pubkey
,
uid
=
uid
,
timestamp
=
timestamp
,
)
identity
.
signatures
=
[
signature
]
break
return
identity
return
Identity
.
from_lookup_response
(
PROTOCOL_VERSION
,
current_block
[
"
currency
"
],
lookup_data
)
def
get_certification_document
(
def
get_certification_document
(
...
@@ -117,7 +100,7 @@ def send_certification():
...
@@ -117,7 +100,7 @@ def send_certification():
pubkey_from
=
key
.
pubkey
pubkey_from
=
key
.
pubkey
# prompt entry
# prompt entry
pubkey_to
=
input
(
"
Enter
certified pubke
y:
"
)
pubkey_to
=
input
(
"
Enter
pubkey to certif
y:
"
)
# capture current block to get version and currency and blockstamp
# capture current block to get version and currency and blockstamp
current_block
=
client
(
bma
.
blockchain
.
current
)
current_block
=
client
(
bma
.
blockchain
.
current
)
...
...
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