diff --git a/silkaj/auth.py b/silkaj/auth.py index 52b936fc5ab8d511240d0676fa6a261c52359392..b9470d9b523ee722ab7070eb36e318c4e1149aab 100644 --- a/silkaj/auth.py +++ b/silkaj/auth.py @@ -23,7 +23,7 @@ from duniterpy.key import SigningKey from duniterpy.key.scrypt_params import ScryptParams from silkaj.constants import PUBKEY_PATTERN -from silkaj.tui import display_pubkey_and_checksum +from silkaj.tui import gen_pubkey_checksum SEED_HEX_PATTERN = "^[0-9a-fA-F]{64}$" PUBSEC_PUBKEY_PATTERN = f"pub: ({PUBKEY_PATTERN})" @@ -57,7 +57,7 @@ def has_auth_method(ctx): def generate_auth_file(file): key = auth_method() authfile = Path(file) - pubkey_cksum = display_pubkey_and_checksum(key.pubkey) + pubkey_cksum = gen_pubkey_checksum(key.pubkey) if authfile.is_file(): message = f"Would you like to erase {file} by an authfile corresponding \n\ to following pubkey `{pubkey_cksum}`?" diff --git a/silkaj/cert.py b/silkaj/cert.py index 82b5185974a2618f11c0c5d34b0877a5b8a2e794..876c2fc787115ece3338c684c481719948dbb024 100644 --- a/silkaj/cert.py +++ b/silkaj/cert.py @@ -123,9 +123,9 @@ def certification_confirmation( cert.append( [ "Pubkey", - tui.display_pubkey_and_checksum(issuer_pubkey), + tui.gen_pubkey_checksum(issuer_pubkey), "–>", - tui.display_pubkey_and_checksum(pubkey_to_certify), + tui.gen_pubkey_checksum(pubkey_to_certify), ] ) params = get_blockchain_parameters() diff --git a/silkaj/checksum.py b/silkaj/checksum.py index f74cdd8e294f86bf1d8751ea49e8dafcc51a999c..d095e5986d7e9bf9755e2b55b51e392a01f366ec 100644 --- a/silkaj/checksum.py +++ b/silkaj/checksum.py @@ -24,7 +24,7 @@ from silkaj.crypto_tools import ( PUBKEY_DELIMITED_PATTERN, gen_checksum, ) -from silkaj.tui import display_pubkey_and_checksum +from silkaj.tui import gen_pubkey_checksum MESSAGE = "You should specify a pubkey or an authentication method" @@ -38,12 +38,12 @@ MESSAGE = "You should specify a pubkey or an authentication method" def checksum_command(pubkey_checksum): if has_auth_method(): key = auth_method() - click.echo(display_pubkey_and_checksum(key.pubkey)) + click.echo(gen_pubkey_checksum(key.pubkey)) else: if not pubkey_checksum: sys.exit(MESSAGE) elif re.search(re.compile(PUBKEY_DELIMITED_PATTERN), pubkey_checksum[0]): - click.echo(display_pubkey_and_checksum(pubkey_checksum[0])) + click.echo(gen_pubkey_checksum(pubkey_checksum[0])) elif re.search(re.compile(PUBKEY_CHECKSUM_PATTERN), pubkey_checksum[0]): pubkey, checksum = pubkey_checksum[0].split(":") if checksum == gen_checksum(pubkey): diff --git a/silkaj/idty_tools.py b/silkaj/idty_tools.py index dcd2d31d9f0ea487419944ae4f736b3fb1a6217b..42c7934c95e20f89ce63e8ceaba95ff4c689847b 100644 --- a/silkaj/idty_tools.py +++ b/silkaj/idty_tools.py @@ -27,7 +27,7 @@ from texttable import Texttable from silkaj import wot_tools as wt from silkaj.constants import ALL from silkaj.network_tools import client_instance -from silkaj.tui import display_pubkey_and_checksum +from silkaj.tui import gen_pubkey_checksum def display_identity(idty: Identity): @@ -36,7 +36,7 @@ def display_identity(idty: Identity): """ client = client_instance() id_table = list() - id_table.append(["Public key", display_pubkey_and_checksum(idty.pubkey)]) + id_table.append(["Public key", gen_pubkey_checksum(idty.pubkey)]) id_table.append(["User ID", idty.uid]) id_table.append(["Blockstamp", str(idty.block_id)]) creation_block = client(bma.blockchain.block, idty.block_id.number) @@ -65,7 +65,7 @@ def check_many_identities(document: Union[Identity, Revocation]): except urllib.error.HTTPError: sys.exit( f"{error_no_identical_id}\nuid: {idty.uid}\npubkey: \ -{display_pubkey_and_checksum(idty.pubkey)}" +{gen_pubkey_checksum(idty.pubkey)}" ) # get all matching identities @@ -91,9 +91,7 @@ def display_alternate_ids(ids_list: list): table = Texttable(max_width=shutil.get_terminal_size().columns) table.header(labels) for id in ids_list: - table.add_row( - [id.uid, display_pubkey_and_checksum(id.pubkey), str(id.block_id)[:12]] - ) + table.add_row([id.uid, gen_pubkey_checksum(id.pubkey), str(id.block_id)[:12]]) return table diff --git a/silkaj/membership.py b/silkaj/membership.py index fab1f72309fe0eec035110f39318ad497130e696..c7101a1e05272873d78f2fb2d03c60f123bca436 100644 --- a/silkaj/membership.py +++ b/silkaj/membership.py @@ -117,7 +117,7 @@ def display_confirmation_table(identity_uid, pubkey, identity_block_id): table.append(["Pending membership documents will expire", expiration]) table.append(["User Identifier (UID)", identity_uid]) - table.append(["Public Key", tui.display_pubkey_and_checksum(pubkey)]) + table.append(["Public Key", tui.gen_pubkey_checksum(pubkey)]) table.append(["Block Identity", str(identity_block_id)[:45] + "…"]) diff --git a/silkaj/money.py b/silkaj/money.py index 0f0d3f64eb77f1fa3eda0473883e6404989b581e..6e307125b6cd36d1cf891f254a05bdf0312ab4dd 100644 --- a/silkaj/money.py +++ b/silkaj/money.py @@ -27,7 +27,7 @@ from silkaj.blockchain_tools import get_head_block from silkaj.crypto_tools import is_pubkey_and_check from silkaj.network_tools import client_instance from silkaj.tools import get_currency_symbol -from silkaj.tui import display_amount, display_pubkey_and_checksum +from silkaj.tui import display_amount, gen_pubkey_checksum @command("balance", help="Get wallet balance") @@ -48,7 +48,7 @@ def cmd_amount(ctx, pubkeys): print(f"ERROR: pubkey {inputPubkey} has a wrong format") elif pubkey in pubkeys_list: sys.exit( - f"ERROR: pubkey {display_pubkey_and_checksum(pubkey)} was specified many times" + f"ERROR: pubkey {gen_pubkey_checksum(pubkey)} was specified many times" ) pubkeys_list.append(pubkey) if wrong_pubkeys: @@ -83,7 +83,7 @@ def show_amount_from_pubkey(label, inputs_balance): # if `pubkey` is a pubkey, get pubkey:checksum and uid if label != "Total": member = wt.is_member(label) - label = display_pubkey_and_checksum(label) + label = gen_pubkey_checksum(label) # display balance table display = list() display.append(["Balance of pubkey", label]) diff --git a/silkaj/revocation.py b/silkaj/revocation.py index eb11ee56d1400203f65c61715ff2823391fd8cb2..9ec1fe3db4c8e5e5c374eaf698dd7d852e534d91 100644 --- a/silkaj/revocation.py +++ b/silkaj/revocation.py @@ -46,7 +46,7 @@ def save(ctx: click.core.Context, file: str): currency = get_currency() key = auth.auth_method() - tui.display_pubkey_and_checksum(key.pubkey) + tui.gen_pubkey_checksum(key.pubkey) id = (wot.choose_identity(key.pubkey))[0] rev_doc = create_revocation_doc(id, key.pubkey, currency) rev_doc.sign(key) @@ -79,7 +79,7 @@ def revoke_now(ctx: click.core.Context): warn_before_dry_run_or_display(ctx) key = auth.auth_method() - tui.display_pubkey_and_checksum(key.pubkey) + tui.gen_pubkey_checksum(key.pubkey) id = (wot.choose_identity(key.pubkey))[0] rev_doc = create_revocation_doc(id, key.pubkey, currency) rev_doc.sign(key) @@ -184,7 +184,7 @@ def create_revocation_doc(id, pubkey: str, currency: str): def save_doc(path: str, content: str, pubkey: str): - pubkey_cksum = tui.display_pubkey_and_checksum(pubkey) + pubkey_cksum = tui.gen_pubkey_checksum(pubkey) rev_path = Path(path) # Ask confirmation if the file exists if rev_path.is_file(): diff --git a/silkaj/tui.py b/silkaj/tui.py index c35582510d5f9140bb0ca2197f0a6329b2205ad0..9afc551dfefeedb6795d043aea992ff727d1d9d7 100644 --- a/silkaj/tui.py +++ b/silkaj/tui.py @@ -40,15 +40,13 @@ def display_pubkey(tx, message, pubkey): """ Displays a pubkey and the eventually associated id. """ - tx.append([f"{message} (pubkey:checksum)", display_pubkey_and_checksum(pubkey)]) + tx.append([f"{message} (pubkey:checksum)", gen_pubkey_checksum(pubkey)]) id = wot_tools.is_member(pubkey) if id: tx.append([f"{message} (id)", id["uid"]]) -def display_pubkey_and_checksum( - pubkey, short=False, length=constants.SHORT_PUBKEY_SIZE -): +def gen_pubkey_checksum(pubkey, short=False, length=constants.SHORT_PUBKEY_SIZE): """ Returns "<pubkey>:<checksum>" in full form. returns `length` first chars of pubkey and checksum in short form. diff --git a/silkaj/tx.py b/silkaj/tx.py index d7dd05885ed1b0642a807f471e582ff160b0d8a1..00f6d8135a04bc644a8d1b061e53d3175d501cae 100644 --- a/silkaj/tx.py +++ b/silkaj/tx.py @@ -145,7 +145,7 @@ def send_transaction( if allsources: if pubkey_amount[0] <= 0: tools.message_exit( - f"Error: Issuer pubkey {tui.display_pubkey_and_checksum(issuer_pubkey)} is empty. \ + f"Error: Issuer pubkey {tui.gen_pubkey_checksum(issuer_pubkey)} is empty. \ No transaction sent." ) @@ -296,7 +296,7 @@ def check_transaction_values( if ct.check_pubkey_format(outputBackChange): outputBackChange = ct.validate_checksum(outputBackChange) if enough_source: - pubkey = tui.display_pubkey_and_checksum(issuer_pubkey) + pubkey = tui.gen_pubkey_checksum(issuer_pubkey) tools.message_exit( f"{pubkey} pubkey doesn’t have enough money for this transaction." ) @@ -452,7 +452,7 @@ def generate_and_send_transaction( print("Generate Change Transaction") else: print("Generate Transaction:") - print(" - From: " + tui.display_pubkey_and_checksum(issuers)) + print(" - From: " + tui.gen_pubkey_checksum(issuers)) for tx_amount, outputAddress in zip(tx_amounts, outputAddresses): display_sent_tx(outputAddress, tx_amount) print(" - Total: " + str(sum(tx_amounts) / 100)) @@ -472,7 +472,7 @@ def generate_and_send_transaction( def display_sent_tx(outputAddress, amount): print( " - To: ", - tui.display_pubkey_and_checksum(outputAddress), + tui.gen_pubkey_checksum(outputAddress), "\n - Amount: ", amount / 100, ) diff --git a/silkaj/tx_history.py b/silkaj/tx_history.py index 7dca8b00d8fc6b3c3514747c218423d36421e273..1b69842ed21b8a6ac0c2020d5a74bb2642ac96c7 100644 --- a/silkaj/tx_history.py +++ b/silkaj/tx_history.py @@ -28,7 +28,7 @@ from silkaj.crypto_tools import check_pubkey_format, validate_checksum from silkaj.money import amount_in_current_base, get_amount_from_pubkey, get_ud_value from silkaj.network_tools import client_instance from silkaj.tools import get_currency_symbol -from silkaj.tui import display_pubkey_and_checksum +from silkaj.tui import gen_pubkey_checksum @command("history", help="Display transaction history") @@ -63,7 +63,7 @@ def generate_header(pubkey, currency_symbol, ud_value): balance = get_amount_from_pubkey(pubkey) balance_ud = round(balance[1] / ud_value, 2) date = now().format(ALL) - return f'Transactions history from: {idty["uid"]} {display_pubkey_and_checksum(pubkey)}\n\ + return f'Transactions history from: {idty["uid"]} {gen_pubkey_checksum(pubkey)}\n\ Current balance: {balance[1] / 100} {currency_symbol}, {balance_ud} UD {currency_symbol} on {date}\n' @@ -240,10 +240,10 @@ def output_available(condition, comparison, value): def assign_idty_from_pubkey(pubkey, identities, full_pubkey): - idty = display_pubkey_and_checksum(pubkey, short=not full_pubkey) + idty = gen_pubkey_checksum(pubkey, short=not full_pubkey) for identity in identities: if pubkey == identity["pubkey"]: - pubkey_mod = display_pubkey_and_checksum(pubkey, short=not full_pubkey) + pubkey_mod = gen_pubkey_checksum(pubkey, short=not full_pubkey) idty = f'{identity["uid"]} - {pubkey_mod}' return idty diff --git a/silkaj/wot.py b/silkaj/wot.py index 4803c80305a41a465e606746086643da532ca4f8..49d8fcc1867ef5f7d1bcae42e81b1587e389fb77 100644 --- a/silkaj/wot.py +++ b/silkaj/wot.py @@ -26,7 +26,7 @@ from silkaj.blockchain_tools import get_blockchain_parameters from silkaj.constants import DATE from silkaj.crypto_tools import is_pubkey_and_check from silkaj.network_tools import client_instance, exit_on_http_error -from silkaj.tui import display_pubkey_and_checksum +from silkaj.tui import gen_pubkey_checksum def get_sent_certifications(signed, time_first_block, params): @@ -89,7 +89,7 @@ def received_sent_certifications(uid_pubkey): table = tabulate( certifications, headers="keys", tablefmt="orgtbl", stralign="right" ) - txt = f'{identity["uid"]} ({display_pubkey_and_checksum(pubkey, True)}) \ + txt = f'{identity["uid"]} ({gen_pubkey_checksum(pubkey, True)}) \ from block #{identity["meta"]["timestamp"][:15]}…\n\ received {len(certifications["received"])} and \ sent {nbr_sent_certs}/{params["sigStock"]} certifications:\n\ @@ -156,7 +156,7 @@ def id_pubkey_correspondence(uid_pubkey): content = f"Public keys or user id found matching '{uid_pubkey}':\n" for lookup in lookups: for identity in lookup["uids"]: - pubkey_checksum = display_pubkey_and_checksum(lookup["pubkey"]) + pubkey_checksum = gen_pubkey_checksum(lookup["pubkey"]) content += f'\n→ {pubkey_checksum} ↔ {identity["uid"]}' click.echo(content) @@ -179,9 +179,7 @@ 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( - display_pubkey_and_checksum(lookup["pubkey"]) - ) + identities_choices["pubkey"].append(gen_pubkey_checksum(lookup["pubkey"])) identities_choices["uid"].append(identity["uid"]) identities_choices["timestamp"].append( identity["meta"]["timestamp"][:20] + "…" diff --git a/tests/test_idty_tools.py b/tests/test_idty_tools.py index ec2a5ba659152f49becabff8b36a5109992fafde..872d8b3a1abd87674da8929745a0ab3369cc5920 100644 --- a/tests/test_idty_tools.py +++ b/tests/test_idty_tools.py @@ -32,7 +32,7 @@ from patched.idty_tools import ( ) from silkaj import idty_tools from silkaj.constants import ALL, PUBKEY_PATTERN -from silkaj.tui import display_pubkey_and_checksum +from silkaj.tui import gen_pubkey_checksum # used test identities @@ -362,7 +362,7 @@ def test_display_identity(idty, monkeypatch, capsys): None, [ f"Identity document does not match any valid identity.\n\ -uid: {idty1.uid}\npubkey: {display_pubkey_and_checksum(idty1.pubkey)}" +uid: {idty1.uid}\npubkey: {gen_pubkey_checksum(idty1.pubkey)}" ], False, ), @@ -396,7 +396,7 @@ def test_check_many_identities( # identity does not exist if expected == [ f"Identity document does not match any valid identity.\ -\nuid: {idty.uid}\npubkey: {display_pubkey_and_checksum(idty.pubkey)}" +\nuid: {idty.uid}\npubkey: {gen_pubkey_checksum(idty.pubkey)}" ]: with pytest.raises(SystemExit) as pytest_exit: result = idty_tools.check_many_identities(idty) diff --git a/tests/test_membership.py b/tests/test_membership.py index 2643e9dca4e8df42e7e0b30dddb38564f23966ee..72b2dfd04ded78f76e40ef4063d20310ba27f723 100644 --- a/tests/test_membership.py +++ b/tests/test_membership.py @@ -39,7 +39,7 @@ from silkaj.blockchain_tools import get_blockchain_parameters from silkaj.cli import cli from silkaj.constants import DATE from silkaj.network_tools import client_instance -from silkaj.tui import display_pubkey_and_checksum +from silkaj.tui import gen_pubkey_checksum # Values and patches pubkey = "EA7Dsw39ShZg4SpURsrgMaMqrweJPUFPYHwZA8e92e3D" @@ -158,7 +158,7 @@ def test_display_confirmation_table(patched_wot_requirements, monkeypatch, capsy table.append(["Pending membership documents will expire", expiration]) table.append(["User Identifier (UID)", identity_uid]) - table.append(["Public Key", display_pubkey_and_checksum(pubkey)]) + table.append(["Public Key", gen_pubkey_checksum(pubkey)]) table.append(["Block Identity", str(identity_block_id)[:45] + "…"]) diff --git a/tests/test_money.py b/tests/test_money.py index 0b3a6af933f8548e1f003c89898fab2da046c0df..26774e5530ef2bcca52aa4bb5f9d48e532cadb44 100644 --- a/tests/test_money.py +++ b/tests/test_money.py @@ -21,7 +21,7 @@ from silkaj.constants import FAILURE_EXIT_STATUS from silkaj.money import get_sources # had to import from wot to prevent loop dependencies -from silkaj.wot import display_pubkey_and_checksum +from silkaj.wot import gen_pubkey_checksum def test_get_sources(monkeypatch): @@ -125,9 +125,7 @@ def test_balance_errors(): "BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh", ], ) - pubkeyCk = display_pubkey_and_checksum( - "BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh" - ) + pubkeyCk = gen_pubkey_checksum("BFb5yv8z1fowR6Z8mBXTALy5z7gHfMU976WtXhmRsUMh") assert f"ERROR: pubkey {pubkeyCk} was specified many times" in result.output assert result.exit_code == FAILURE_EXIT_STATUS diff --git a/tests/test_revocation.py b/tests/test_revocation.py index 2001318d3eb4ad449a4b0c12a3a16e0a886679b0..956a5d7a700be6887ddadaf6312d5028e2197026 100644 --- a/tests/test_revocation.py +++ b/tests/test_revocation.py @@ -31,7 +31,7 @@ from silkaj import auth, blockchain_tools, idty_tools, revocation, wot from silkaj.cli import cli from silkaj.constants import FAILURE_EXIT_STATUS, SUCCESS_EXIT_STATUS from silkaj.network_tools import client_instance -from silkaj.tui import display_pubkey_and_checksum +from silkaj.tui import gen_pubkey_checksum # Useful function @@ -966,7 +966,7 @@ def test_save_doc(path, rev_1, rev_2, pubkey, capsys, monkeypatch): monkeypatch.setattr(click, "confirm", value=conf_true) revocation.save_doc(path, rev_2.signed_raw(), pubkey) expected_confirm = f"Revocation document file stored into `{path}` \ -for following public key: {display_pubkey_and_checksum(pubkey)}" +for following public key: {gen_pubkey_checksum(pubkey)}" assert expected_confirm in capsys.readouterr().out with open(path) as f: assert f.read() == rev_2.signed_raw() diff --git a/tests/test_tui.py b/tests/test_tui.py index 61861297a77e2b89a15a13e58460d3e536e4e3a7..e4592ad448f3660ca18af47370e6e877f60913eb 100644 --- a/tests/test_tui.py +++ b/tests/test_tui.py @@ -19,7 +19,7 @@ from patched.test_constants import mock_ud_value from patched.wot import patched_is_member from silkaj import wot_tools from silkaj.constants import G1_SYMBOL, SHORT_PUBKEY_SIZE -from silkaj.tui import display_amount, display_pubkey, display_pubkey_and_checksum +from silkaj.tui import display_amount, display_pubkey, gen_pubkey_checksum # display_amount() @@ -50,7 +50,7 @@ def test_display_amount(message, amount, currency_symbol): def test_display_pubkey(message, pubkey, id, monkeypatch): monkeypatch.setattr(wot_tools, "is_member", patched_is_member) - expected = [[f"{message} (pubkey:checksum)", display_pubkey_and_checksum(pubkey)]] + expected = [[f"{message} (pubkey:checksum)", gen_pubkey_checksum(pubkey)]] if id: expected.append([f"{message} (id)", id]) tx = list() @@ -58,18 +58,18 @@ def test_display_pubkey(message, pubkey, id, monkeypatch): assert tx == expected -# display_pubkey_and_checksum +# gen_pubkey_checksum @pytest.mark.parametrize( "pubkey, checksum", [ ("J4c8CARmP9vAFNGtHRuzx14zvxojyRWHW2darguVqjtX", "KAv"), ], ) -def test_display_pubkey_and_checksum(pubkey, checksum): - assert pubkey + ":" + checksum == display_pubkey_and_checksum(pubkey) - assert pubkey[:SHORT_PUBKEY_SIZE] + "…:" + checksum == display_pubkey_and_checksum( +def test_gen_pubkey_checksum(pubkey, checksum): + assert pubkey + ":" + checksum == gen_pubkey_checksum(pubkey) + assert pubkey[:SHORT_PUBKEY_SIZE] + "…:" + checksum == gen_pubkey_checksum( pubkey, short=True ) - assert pubkey[:14] + "…:" + checksum == display_pubkey_and_checksum( + assert pubkey[:14] + "…:" + checksum == gen_pubkey_checksum( pubkey, short=True, length=14 )