Skip to content
Snippets Groups Projects
Commit 330b7e8c authored by inso's avatar inso Committed by GitHub
Browse files

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
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")
################################################ ################################################
......
...@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment