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

[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
parent 3e3f66cc
Branches
Tags
2 merge requests!110Merge dev into master for v0.58.0 release,!104Rework send membership and identity documents examples
Pipeline #9671 waiting for manual action
...@@ -18,15 +18,16 @@ BMAS_ENDPOINT = "BMAS g1-test.duniter.org 443" ...@@ -18,15 +18,16 @@ BMAS_ENDPOINT = "BMAS g1-test.duniter.org 443"
def get_identity_document( def get_identity_document(
current_block: dict, uid: str, salt: str, password: str current_block: dict,
uid: str,
key: SigningKey,
) -> Identity: ) -> Identity:
""" """
Get an Identity document Get an Identity document
:param current_block: Current block data :param current_block: Current block data
:param uid: Unique IDentifier :param uid: Unique IDentifier
:param salt: Passphrase of the account :param key: cryptographic key to sign documents
:param password: Password of the account
:rtype: Identity :rtype: Identity
""" """
...@@ -34,9 +35,6 @@ def get_identity_document( ...@@ -34,9 +35,6 @@ def get_identity_document(
# get current block BlockStamp # get current block BlockStamp
timestamp = BlockUID(current_block["number"], current_block["hash"]) timestamp = BlockUID(current_block["number"], current_block["hash"])
# create keys from credentials
key = SigningKey.from_credentials(salt, password)
# create identity document # create identity document
identity = Identity( identity = Identity(
version=10, version=10,
...@@ -76,10 +74,13 @@ async def main(): ...@@ -76,10 +74,13 @@ async def main():
# prompt hidden user entry # prompt hidden user entry
password = getpass.getpass("Enter your password: ") password = getpass.getpass("Enter your password: ")
# create keys from credentials
key = SigningKey.from_credentials(salt, password)
# create our signed identity document # 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()) response = await client(bma.wot.add, identity.signed_raw())
if response.status == 200: if response.status == 200:
print(await response.text()) print(await response.text())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment