diff --git a/examples/create_public_key.py b/examples/create_public_key.py index 7ed15a28a9e24a40f6fcc548ff5611b025178591..cd4345b7bf41d78248f3e9901fbe798c38df8e92 100644 --- a/examples/create_public_key.py +++ b/examples/create_public_key.py @@ -20,6 +20,7 @@ from duniterpy.key import SigningKey ################################################ + def create_public_key(): # prompt hidden user entry salt = getpass.getpass("Enter your passphrase (salt): ") diff --git a/examples/load_binary_encrypted_message.py b/examples/load_binary_encrypted_message.py index 1853cafaf0ea2ee0e48daeea8e6cb75fc62d230f..e1072da0b96e97e720b822313a3dbc1450dad370 100644 --- a/examples/load_binary_encrypted_message.py +++ b/examples/load_binary_encrypted_message.py @@ -21,17 +21,14 @@ import sys from duniterpy.key import SigningKey -def load_binary_encrypted_message(): - if len(sys.argv) < 2: - print( - """ - Usage: - python decrypt_message.py ENCRYPTED_MESSAGE_FILEPATH - """ - ) - - # capture encrypted message filepath argument - signed_message_path = sys.argv[1] +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") + sys.exit(1) + + # capture encrypted message filepath argument + signed_message_path = sys.argv[1] # prompt hidden user entry salt = getpass.getpass("Enter your passphrase (salt): ") @@ -55,5 +52,6 @@ def load_binary_encrypted_message(): print(message) + if __name__ == "__main__": load_binary_encrypted_message() diff --git a/examples/load_binary_signed_message.py b/examples/load_binary_signed_message.py index 857390faed074807128d1fef3d9351a452571ece..e8fbf907cc0749d2a46ccdb4ed7a6af828d0727b 100644 --- a/examples/load_binary_signed_message.py +++ b/examples/load_binary_signed_message.py @@ -19,17 +19,15 @@ import sys from duniterpy.key import VerifyingKey -def load_binary_signed_message(): - if len(sys.argv) < 2: - print( - """ - Usage: - python verify_signed_message.py SIGNED_MESSAGE_FILEPATH - """ - ) - - # capture signed message filepath argument - signed_message_path = sys.argv[1] + +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") + sys.exit(1) + + # capture signed message filepath argument + signed_message_path = sys.argv[1] # ask public key of the signer pubkeyBase58 = input("Enter public key of the message issuer: ") diff --git a/examples/load_cleartext_ascii_armor_message.py b/examples/load_cleartext_ascii_armor_message.py index cd87bc03de31a013dc889c66a47676e663ea5684..4952c340e9c505dcd0c294000af1ec07e084fb5a 100644 --- a/examples/load_cleartext_ascii_armor_message.py +++ b/examples/load_cleartext_ascii_armor_message.py @@ -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: ") diff --git a/examples/load_credentials_file.py b/examples/load_credentials_file.py index 70e6a49f1310fd66bbb8c7facbb32d3573253008..311d316f790a342a95569ae38ccc2ebd80f58e14 100644 --- a/examples/load_credentials_file.py +++ b/examples/load_credentials_file.py @@ -19,13 +19,15 @@ import sys from duniterpy.key import SigningKey -def load_credentials_file(): - if len(sys.argv) < 2: - print("Usage: python load_credentials_file.py FILEPATH") - sys.exit(1) - # capture filepath argument - credentials_filepath = sys.argv[1] +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) + + # capture filepath argument + credentials_filepath = sys.argv[1] # create SigningKey instance from file signing_key_instance = SigningKey.from_credentials_file( diff --git a/examples/load_encrypted_ascii_armor_message.py b/examples/load_encrypted_ascii_armor_message.py index 44234bda6f365e67fb3c2a04c9c6913561beab3a..7c3600b4b2eb3be56ec222af7e7e373f30322c14 100644 --- a/examples/load_encrypted_ascii_armor_message.py +++ b/examples/load_encrypted_ascii_armor_message.py @@ -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: ") diff --git a/examples/load_local_blockchain.py b/examples/load_local_blockchain.py index 517b641660929f6491be1db56119d1a8d616c69e..212f72e8de14d905840e87b086743d6359a9b39a 100644 --- a/examples/load_local_blockchain.py +++ b/examples/load_local_blockchain.py @@ -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() diff --git a/examples/load_scuttlebutt_file.py b/examples/load_scuttlebutt_file.py index 48cff9a8ebea9250b71224f9d4f5a2db76fa2ff3..cf11c00652720285b537e31d6ea94eff125d131f 100644 --- a/examples/load_scuttlebutt_file.py +++ b/examples/load_scuttlebutt_file.py @@ -19,13 +19,15 @@ import sys from duniterpy.key import SigningKey -def load_scuttlebutt_file(): - if len(sys.argv) < 2: - print("Usage: python load_scuttlebutt_file.py FILEPATH") - sys.exit(1) - # capture filepath argument - scuttlebutt_filepath = sys.argv[1] +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) + + # capture filepath argument + scuttlebutt_filepath = sys.argv[1] # create SigningKey instance from file signing_key_instance = SigningKey.from_ssb_file( diff --git a/examples/save_and_load_private_key_file.py b/examples/save_and_load_private_key_file.py index d135f0e579227be06042fd832c18eb72a99258b3..8757e841f2377a90fa4db65c983b1021934a0b98 100644 --- a/examples/save_and_load_private_key_file.py +++ b/examples/save_and_load_private_key_file.py @@ -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() diff --git a/examples/save_and_load_private_key_file_ewif.py b/examples/save_and_load_private_key_file_ewif.py index 009c9172994dff8225a7371a8c18773b323daaba..c564b9688229b47c12b77e92a6490bc5faf7988d 100644 --- a/examples/save_and_load_private_key_file_ewif.py +++ b/examples/save_and_load_private_key_file_ewif.py @@ -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() diff --git a/examples/save_and_load_private_key_file_pubsec.py b/examples/save_and_load_private_key_file_pubsec.py index a42dd2ec07c22bbc603b6302fe65a22a0d9c6953..6b402a5903189320912549766768912ed697b9bb 100644 --- a/examples/save_and_load_private_key_file_pubsec.py +++ b/examples/save_and_load_private_key_file_pubsec.py @@ -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() diff --git a/examples/save_and_load_private_key_file_wif.py b/examples/save_and_load_private_key_file_wif.py index aa9e479b3f5b1adba18ec6df6b32025e3433eb89..cfa2f051f54cf91eb9f5ac25204e6850e87d2347 100644 --- a/examples/save_and_load_private_key_file_wif.py +++ b/examples/save_and_load_private_key_file_wif.py @@ -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() diff --git a/examples/save_binary_encrypted_message.py b/examples/save_binary_encrypted_message.py index 38c88d153fdddfc95c2cbadffe01b1aad68d8866..50188e5be5dc7e9f9cc15f6de30836bcc393758f 100644 --- a/examples/save_binary_encrypted_message.py +++ b/examples/save_binary_encrypted_message.py @@ -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() diff --git a/examples/save_binary_signed_message.py b/examples/save_binary_signed_message.py index 0b6aef70f8d5c37740ced3ea9207988e43976576..517c310dbde19e8cedbaba48431873a88309a059 100644 --- a/examples/save_binary_signed_message.py +++ b/examples/save_binary_signed_message.py @@ -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): ") diff --git a/examples/save_cleartext_ascii_armor_message.py b/examples/save_cleartext_ascii_armor_message.py index 6d26dfcb34157e4d492e25f138ac19d38ebeff6c..b402edd46f151b8a4e7112786183bbbe6e065dcf 100644 --- a/examples/save_cleartext_ascii_armor_message.py +++ b/examples/save_cleartext_ascii_armor_message.py @@ -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() diff --git a/examples/save_encrypted_ascii_armor_message.py b/examples/save_encrypted_ascii_armor_message.py index c45cd44e8913cb9a4c96d97f0e91325f5589f43f..b99be22963131499e44c38b54d3f615f7ce465d0 100644 --- a/examples/save_encrypted_ascii_armor_message.py +++ b/examples/save_encrypted_ascii_armor_message.py @@ -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()