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

[mod] #160: examples: Allow to pass files path in f() prompt as arg

Reduce usage message
Add missing exits
parent b22c2320
No related branches found
No related tags found
No related merge requests found
Showing
with 72 additions and 41 deletions
......@@ -20,6 +20,7 @@ from duniterpy.key import SigningKey
################################################
def create_public_key():
# prompt hidden user entry
salt = getpass.getpass("Enter your passphrase (salt): ")
......
......@@ -21,14 +21,11 @@ import sys
from duniterpy.key import SigningKey
def load_binary_encrypted_message():
def load_binary_encrypted_message(signed_message_path=None):
if not signed_message_path:
if len(sys.argv) < 2:
print(
"""
Usage:
python decrypt_message.py ENCRYPTED_MESSAGE_FILEPATH
"""
)
print("Usage: python decrypt_message.py ENCRYPTED_MESSAGE_FILEPATH")
sys.exit(1)
# capture encrypted message filepath argument
signed_message_path = sys.argv[1]
......@@ -55,5 +52,6 @@ def load_binary_encrypted_message():
print(message)
if __name__ == "__main__":
load_binary_encrypted_message()
......@@ -19,14 +19,12 @@ import sys
from duniterpy.key import VerifyingKey
def load_binary_signed_message():
def load_binary_signed_message(signed_message_path=None):
if not signed_message_path:
if len(sys.argv) < 2:
print(
"""
Usage:
python verify_signed_message.py SIGNED_MESSAGE_FILEPATH
"""
)
print("Usage: python verify_signed_message.py SIGNED_MESSAGE_FILEPATH")
sys.exit(1)
# capture signed message filepath argument
signed_message_path = sys.argv[1]
......
......@@ -23,6 +23,7 @@ CLEARTEXT_AA_MESSAGE_PATH = "/tmp/duniter_cleartext_aa_message.txt"
################################################
def load_cleartext_ascii_armor_message():
# Ask public key of the issuer
pubkeyBase58 = input("Enter public key of the message issuer: ")
......
......@@ -19,7 +19,9 @@ import sys
from duniterpy.key import SigningKey
def load_credentials_file():
def load_credentials_file(credentials_filepath=None):
if not credentials_filepath:
if len(sys.argv) < 2:
print("Usage: python load_credentials_file.py FILEPATH")
sys.exit(1)
......
......@@ -25,6 +25,7 @@ ENCRYPTED_AA_MESSAGE_PATH = "/tmp/duniter_aa_encrypted_message.txt"
################################################
def load_encrypted_ascii_armor_message():
# Ask public key of the recipient
pubkeyBase58 = input("Enter public key of the message issuer: ")
......
......@@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
from duniterpy.helpers.blockchain import load
def load_local_blockchain():
bc = load() # gets blockchain iterator
b = next(bc) # gets block
......@@ -30,5 +31,6 @@ def load_local_blockchain():
print(f"third block number is: {next(bc).number}") # should return 2
# (and so on)
if __name__ == "__main__":
load_local_blockchain()
......@@ -19,7 +19,9 @@ import sys
from duniterpy.key import SigningKey
def load_scuttlebutt_file():
def load_scuttlebutt_file(scuttlebutt_filepath=None):
if not scuttlebutt_filepath:
if len(sys.argv) < 2:
print("Usage: python load_scuttlebutt_file.py FILEPATH")
sys.exit(1)
......
......@@ -38,6 +38,7 @@ PRIVATE_KEYS_FILE_PATH = os.path.join(home_path, ".duniter_account_private_keys.
################################################
def save_and_load_private_key_file():
# prompt hidden user entry
salt = getpass.getpass("Enter your passphrase (salt): ")
......@@ -60,13 +61,21 @@ def save_and_load_private_key_file():
signer.save_private_key(PRIVATE_KEYS_FILE_PATH)
# document saved
print("Private keys for public key %s saved in %s" % (pubkey, PRIVATE_KEYS_FILE_PATH))
print(
"Private keys for public key %s saved in %s" % (pubkey, PRIVATE_KEYS_FILE_PATH)
)
# load private keys from file
loaded_signer = SigningKey.from_private_key(PRIVATE_KEYS_FILE_PATH) # type: SigningKey
loaded_signer = SigningKey.from_private_key(
PRIVATE_KEYS_FILE_PATH
) # type: SigningKey
# check public key from file
print("Public key %s loaded from file %s" % (loaded_signer.pubkey, PRIVATE_KEYS_FILE_PATH))
print(
"Public key %s loaded from file %s"
% (loaded_signer.pubkey, PRIVATE_KEYS_FILE_PATH)
)
if __name__ == "__main__":
save_and_load_private_key_file()
......@@ -38,6 +38,7 @@ PRIVATE_KEY_FILE_PATH = os.path.join(home_path, ".duniter_account_ewif_v1.dunite
################################################
def save_and_load_private_key_file_ewif():
# prompt hidden user entry
salt = getpass.getpass("Enter your passphrase (salt): ")
......@@ -64,7 +65,8 @@ def save_and_load_private_key_file_ewif():
# document saved
print(
"Private key for public key %s saved in %s" % (signer.pubkey, PRIVATE_KEY_FILE_PATH)
"Private key for public key %s saved in %s"
% (signer.pubkey, PRIVATE_KEY_FILE_PATH)
)
try:
......@@ -83,5 +85,6 @@ def save_and_load_private_key_file_ewif():
print(error)
sys.exit(1)
if __name__ == "__main__":
save_and_load_private_key_file_ewif()
......@@ -62,7 +62,8 @@ def save_and_load_private_key_file_pubsec():
# document saved
print(
"Private key for public key %s saved in %s" % (signer.pubkey, PRIVATE_KEY_FILE_PATH)
"Private key for public key %s saved in %s"
% (signer.pubkey, PRIVATE_KEY_FILE_PATH)
)
try:
......@@ -79,5 +80,6 @@ def save_and_load_private_key_file_pubsec():
print(error)
sys.exit(1)
if __name__ == "__main__":
save_and_load_private_key_file_pubsec()
......@@ -38,6 +38,7 @@ PRIVATE_KEY_FILE_PATH = os.path.join(home_path, ".duniter_account_wif_v1.duniter
################################################
def save_and_load_private_key_file_wif():
# prompt hidden user entry
salt = getpass.getpass("Enter your passphrase (salt): ")
......@@ -61,12 +62,15 @@ def save_and_load_private_key_file_wif():
# document saved
print(
"Private key for public key %s saved in %s" % (signer.pubkey, PRIVATE_KEY_FILE_PATH)
"Private key for public key %s saved in %s"
% (signer.pubkey, PRIVATE_KEY_FILE_PATH)
)
try:
# load private keys from file
loaded_signer = SigningKey.from_wif_file(PRIVATE_KEY_FILE_PATH) # type: SigningKey
loaded_signer = SigningKey.from_wif_file(
PRIVATE_KEY_FILE_PATH
) # type: SigningKey
# check public key from file
print(
......@@ -78,5 +82,6 @@ def save_and_load_private_key_file_wif():
print(error)
sys.exit(1)
if __name__ == "__main__":
save_and_load_private_key_file_wif()
......@@ -23,6 +23,7 @@ ENCRYPTED_MESSAGE_FILENAME = "/tmp/duniter_encrypted_message.bin"
################################################
def save_binary_encrypted_message():
# Ask public key of the recipient
pubkeyBase58 = input("Enter public key of the message recipient: ")
......@@ -40,5 +41,6 @@ def save_binary_encrypted_message():
print("Encrypted message saved in file ./{0}".format(ENCRYPTED_MESSAGE_FILENAME))
if __name__ == "__main__":
save_binary_encrypted_message()
......@@ -27,6 +27,7 @@ SIGNED_MESSAGE_FILENAME = "/tmp/duniter_signed_message.bin"
################################################
def save_binary_signed_message():
# prompt hidden user entry
salt = getpass.getpass("Enter your passphrase (salt): ")
......
......@@ -28,6 +28,7 @@ CLEARTEXT_AA_MESSAGE_PATH = "/tmp/duniter_cleartext_aa_message.txt"
################################################
def save_cleartext_ascii_armor_message():
# prompt hidden user entry
salt = getpass.getpass("Enter your passphrase (salt): ")
......@@ -60,5 +61,6 @@ def save_cleartext_ascii_armor_message():
)
)
if __name__ == "__main__":
save_cleartext_ascii_armor_message()
......@@ -26,6 +26,7 @@ ENCRYPTED_AA_MESSAGE_PATH = "/tmp/duniter_aa_encrypted_message.txt"
################################################
def save_encrypted_ascii_armor_message():
# Ask public key of the recipient
pubkeyBase58 = input("Enter public key of the message recipient: ")
......@@ -64,5 +65,6 @@ def save_encrypted_ascii_armor_message():
)
)
if __name__ == "__main__":
save_encrypted_ascii_armor_message()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment