diff --git a/silkaj/wot.py b/silkaj/wot.py index efe87ddd7c80d3d7588f76beb19d15c1e906502d..d5f5ec7b9073d24fd6133106ed7a53bccaf561c9 100644 --- a/silkaj/wot.py +++ b/silkaj/wot.py @@ -26,7 +26,7 @@ from duniterpy.api.errors import DuniterError from silkaj.network_tools import ClientInstance from silkaj.crypto_tools import check_public_key from silkaj.tools import message_exit, coroutine -from silkaj.tui import convert_time +from silkaj.tui import convert_time, pubkey_with_checksum from silkaj.blockchain_tools import BlockchainParams from silkaj.constants import ASYNC_SLEEP @@ -159,12 +159,13 @@ def date_approximation(block_id, time_first_block, avgentime): @coroutine async def id_pubkey_correspondence(id_pubkey): client = ClientInstance().client - if check_public_key(id_pubkey, False): + pubkey = check_public_key(id_pubkey, False) + if pubkey: try: - idty = await identity_of(id_pubkey) + idty = await identity_of(pubkey) print( "{} public key corresponds to identity: {}".format( - id_pubkey, idty["uid"] + pubkey_with_checksum(pubkey), idty["uid"] ) ) except: @@ -173,7 +174,7 @@ async def id_pubkey_correspondence(id_pubkey): pubkeys = await wot_lookup(id_pubkey) print("Public keys found matching '{}':\n".format(id_pubkey)) for pubkey in pubkeys: - print("→", pubkey["pubkey"], end=" ") + print("→", pubkey_with_checksum(pubkey["pubkey"]), end=" ") try: corresponding_id = await client(wot.identity_of, pubkey["pubkey"]) print("↔ " + corresponding_id["uid"]) @@ -189,6 +190,11 @@ async def choose_identity(pubkey_uid): If there is one uid, returns it If there is multiple uids, prompt a selector """ + # check pubkey and checksum + pubkey = check_public_key(pubkey_uid, False) + if pubkey: + pubkey_uid = pubkey + lookups = await wot_lookup(pubkey_uid) # Generate table containing the choices @@ -196,7 +202,7 @@ async def choose_identity(pubkey_uid): for pubkey_index, lookup in enumerate(lookups): for uid_index, identity in enumerate(lookup["uids"]): identities_choices["id"].append(str(pubkey_index) + str(uid_index)) - identities_choices["pubkey"].append(lookup["pubkey"]) + identities_choices["pubkey"].append(pubkey_with_checksum(lookup["pubkey"])) identities_choices["uid"].append(identity["uid"]) identities_choices["timestamp"].append( identity["meta"]["timestamp"][:20] + "…" diff --git a/tests/test_wot.py b/tests/test_wot.py index a4789a38206d13710c911ed857d071478c685182..9f05df3f11555ee81f90621396ebc550b7625a8d 100644 --- a/tests/test_wot.py +++ b/tests/test_wot.py @@ -24,6 +24,8 @@ from silkaj import wot pubkey_titi_tata = "B4RoF48cTxzmsQDB3UjodKdZ2cVymKSKzgiPVRoMeA88" pubkey_toto_tutu = "totoF48cTxzmsQDB3UjodKdZ2cVymKSKzgiPVRoMeA88" +pubkey_titi_tata_checksum = "B4RoF48cTxzmsQDB3UjodKdZ2cVymKSKzgiPVRoMeA88:9iP" + def identity_card(uid, timestamp): return { @@ -135,6 +137,7 @@ def patched_prompt_tutu(message): "selected_uid, pubkey, patched_prompt, patched_lookup", [ ("titi", pubkey_titi_tata, patched_prompt_titi, patched_lookup_one), + ("titi", pubkey_titi_tata_checksum, patched_prompt_titi, patched_lookup_one), ("tata", pubkey_titi_tata, patched_prompt_tata, patched_lookup_two), ("toto", pubkey_toto_tutu, patched_prompt_toto, patched_lookup_three), ("tutu", pubkey_toto_tutu, patched_prompt_tutu, patched_lookup_four), @@ -148,7 +151,8 @@ async def test_choose_identity( monkeypatch.setattr(wot, "wot_lookup", patched_lookup) monkeypatch.setattr(click, "prompt", patched_prompt) identity_card, get_pubkey, signed = await wot.choose_identity(pubkey) - assert pubkey == get_pubkey + expected_pubkey = pubkey.split(":")[0] + assert expected_pubkey == get_pubkey assert selected_uid == identity_card["uid"] # Check whether the table is not displayed in case of one identity