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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
python
DuniterPy
Commits
330b7e8c
Commit
330b7e8c
authored
8 years ago
by
inso
Committed by
GitHub
8 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #34 from vtexier/dev
improve save examples
parents
4d7b1d6b
b69250aa
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/save_private_keys.py
+11
-1
11 additions, 1 deletion
examples/save_private_keys.py
examples/save_revoke_document.py
+30
-16
30 additions, 16 deletions
examples/save_revoke_document.py
with
41 additions
and
17 deletions
examples/save_private_keys.py
+
11
−
1
View file @
330b7e8c
from
duniterpy.key
import
SigningKey
from
duniterpy.key
import
SigningKey
import
getpass
import
getpass
import
os
if
"
XDG_CONFIG_HOME
"
in
os
.
environ
:
home_path
=
os
.
environ
[
"
XDG_CONFIG_HOME
"
]
elif
"
HOME
"
in
os
.
environ
:
home_path
=
os
.
environ
[
"
HOME
"
]
elif
"
APPDATA
"
in
os
.
environ
:
home_path
=
os
.
environ
[
"
APPDATA
"
]
else
:
home_path
=
os
.
path
.
dirname
(
__file__
)
# CONFIG #######################################
# CONFIG #######################################
# WARNING : Hide this file in a safe and secure place
# WARNING : Hide this file in a safe and secure place
# If one day you forget your credentials,
# If one day you forget your credentials,
# you'll have to use one of your private keys instead
# you'll have to use one of your private keys instead
PRIVATE_KEYS_FILE_PATH
=
"
/home/vit/
.duniter_account_private_keys.txt
"
PRIVATE_KEYS_FILE_PATH
=
os
.
path
.
join
(
home_path
,
"
.duniter_account_private_keys.txt
"
)
################################################
################################################
...
...
This diff is collapsed.
Click to expand it.
examples/save_revoke_document.py
+
30
−
16
View file @
330b7e8c
...
@@ -4,6 +4,17 @@ import duniterpy.api.bma as bma
...
@@ -4,6 +4,17 @@ import duniterpy.api.bma as bma
from
duniterpy.documents
import
BMAEndpoint
,
BlockUID
,
Identity
from
duniterpy.documents
import
BMAEndpoint
,
BlockUID
,
Identity
from
duniterpy.documents
import
Revocation
from
duniterpy.documents
import
Revocation
from
duniterpy.key
import
SigningKey
from
duniterpy.key
import
SigningKey
import
getpass
import
os
if
"
XDG_CONFIG_HOME
"
in
os
.
environ
:
home_path
=
os
.
environ
[
"
XDG_CONFIG_HOME
"
]
elif
"
HOME
"
in
os
.
environ
:
home_path
=
os
.
environ
[
"
HOME
"
]
elif
"
APPDATA
"
in
os
.
environ
:
home_path
=
os
.
environ
[
"
APPDATA
"
]
else
:
home_path
=
os
.
path
.
dirname
(
__file__
)
# CONFIG #######################################
# CONFIG #######################################
...
@@ -12,18 +23,10 @@ from duniterpy.key import SigningKey
...
@@ -12,18 +23,10 @@ from duniterpy.key import SigningKey
# Here we use the BASIC_MERKLED_API
# Here we use the BASIC_MERKLED_API
BMA_ENDPOINT
=
"
BASIC_MERKLED_API cgeek.fr 9330
"
BMA_ENDPOINT
=
"
BASIC_MERKLED_API cgeek.fr 9330
"
# Credentials should be prompted or kept in a separate secure file
# create a file with the salt on the first line and the password on the second line
# the script will load them from the file
CREDENTIALS_FILE_PATH
=
"
/home/username/.credentials.txt
"
# Public key of the revoked identity account
PUBKEY
=
"
XXXXXXXX
"
# WARNING : Hide this file in a safe and secure place
# WARNING : Hide this file in a safe and secure place
# If one day you forget your credentials,
# If one day you forget your credentials,
# you'll have to use your private key instead
# you'll have to use your private key instead
REVOKE_DOCUMENT_FILE_PATH
=
"
/home/username/
duniter_account_revoke_document.txt
"
REVOKE_DOCUMENT_FILE_PATH
=
os
.
path
.
join
(
home_path
,
"
duniter_account_revoke_document.txt
"
)
################################################
################################################
...
@@ -94,6 +97,23 @@ async def main():
...
@@ -94,6 +97,23 @@ async def main():
"""
"""
Main code
Main code
"""
"""
# prompt hidden user entry
salt
=
getpass
.
getpass
(
"
Enter your passphrase (salt):
"
)
# prompt hidden user entry
password
=
getpass
.
getpass
(
"
Enter your password:
"
)
# prompt public key
pubkey
=
input
(
"
Enter your public key:
"
)
# init signer instance
signer
=
SigningKey
(
salt
,
password
)
# check public key
if
signer
.
pubkey
!=
pubkey
:
print
(
"
Bad credentials !
"
)
exit
(
0
)
# connection handler from BMA endpoint
# connection handler from BMA endpoint
connection
=
BMAEndpoint
.
from_inline
(
BMA_ENDPOINT
).
conn_handler
()
connection
=
BMAEndpoint
.
from_inline
(
BMA_ENDPOINT
).
conn_handler
()
...
@@ -101,13 +121,7 @@ async def main():
...
@@ -101,13 +121,7 @@ async def main():
current_block
=
await
bma
.
blockchain
.
current
(
connection
)
current_block
=
await
bma
.
blockchain
.
current
(
connection
)
# create our SelfCertification document to sign the revoke document
# create our SelfCertification document to sign the revoke document
identity_document
=
await
get_identity_document
(
connection
,
current_block
[
'
currency
'
],
PUBKEY
)
identity_document
=
await
get_identity_document
(
connection
,
current_block
[
'
currency
'
],
pubkey
)
# load credentials from a text file
salt
,
password
=
open
(
CREDENTIALS_FILE_PATH
).
readlines
()
# cleanup newlines
salt
,
password
=
salt
.
strip
(),
password
.
strip
()
# get the revoke document
# get the revoke document
revoke_document
=
await
get_revoke_document
(
identity_document
,
salt
,
password
)
revoke_document
=
await
get_revoke_document
(
identity_document
,
salt
,
password
)
...
...
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