From cb6c366b16ca2ecbead2c53b544a667caa10204c Mon Sep 17 00:00:00 2001 From: Moul <moul@moul.re> Date: Sat, 6 Jun 2020 12:22:56 +0200 Subject: [PATCH] [enh] Improve send_identity.py example Pass the key to get_identity_document() Rename the file to 'send_identity' for consistency with the other files --- ...and_publish_identity.py => send_identity.py} | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) rename examples/{create_and_publish_identity.py => send_identity.py} (90%) diff --git a/examples/create_and_publish_identity.py b/examples/send_identity.py similarity index 90% rename from examples/create_and_publish_identity.py rename to examples/send_identity.py index 7c388993..c024a50f 100644 --- a/examples/create_and_publish_identity.py +++ b/examples/send_identity.py @@ -18,15 +18,16 @@ BMAS_ENDPOINT = "BMAS g1-test.duniter.org 443" def get_identity_document( - current_block: dict, uid: str, salt: str, password: str + current_block: dict, + uid: str, + key: SigningKey, ) -> Identity: """ Get an Identity document :param current_block: Current block data :param uid: Unique IDentifier - :param salt: Passphrase of the account - :param password: Password of the account + :param key: cryptographic key to sign documents :rtype: Identity """ @@ -34,9 +35,6 @@ def get_identity_document( # get current block BlockStamp timestamp = BlockUID(current_block["number"], current_block["hash"]) - # create keys from credentials - key = SigningKey.from_credentials(salt, password) - # create identity document identity = Identity( version=10, @@ -76,10 +74,13 @@ async def main(): # prompt hidden user entry password = getpass.getpass("Enter your password: ") + # create keys from credentials + key = SigningKey.from_credentials(salt, password) + # create our signed identity document - identity = get_identity_document(current_block, uid, salt, password) + identity = get_identity_document(current_block, uid, key) - # send the identity document to the node + # send the identity signed raw document to the node response = await client(bma.wot.add, identity.signed_raw()) if response.status == 200: print(await response.text()) -- GitLab