diff --git a/duniterpy/key/ascii_armor.py b/duniterpy/key/ascii_armor.py index bd942bd211604db9531e78a5881dc2292942c510..b959c875d8060b626cbded5073fe23ddae068220 100644 --- a/duniterpy/key/ascii_armor.py +++ b/duniterpy/key/ascii_armor.py @@ -33,7 +33,7 @@ HEADER_PREFIX = "-----" DASH_ESCAPE_PREFIX = "\x2D\x20" # Version field value -VERSION_FIELD_VALUE = "Python Libnacl " + libnacl_version +VERSION_FIELD_VALUE = f"Python Libnacl {libnacl_version}" # Parser cursor status ON_MESSAGE_FIELDS = 1 @@ -108,25 +108,18 @@ class AsciiArmor: message = message.rstrip("\n\r") + "\n" # create block with headers - ascii_armor_block = """{begin_message_header} -""".format( - begin_message_header=BEGIN_MESSAGE_HEADER - ) + ascii_armor_block = f"{BEGIN_MESSAGE_HEADER}\n" # if encrypted message... if pubkey: # add encrypted message fields - ascii_armor_block += """{version_field} -""".format( - version_field=AsciiArmor._get_version_field() - ) + version_field = AsciiArmor._get_version_field() + ascii_armor_block += f"{version_field}\n" # add message comment if specified if message_comment: - ascii_armor_block += """{comment_field} -""".format( - comment_field=AsciiArmor._get_comment_field(message_comment) - ) + comment_field = AsciiArmor._get_comment_field(message_comment) + ascii_armor_block += f"{comment_field}\n" # blank line separator ascii_armor_block += "\n" @@ -137,10 +130,7 @@ class AsciiArmor: base64_encrypted_message = base64.b64encode( pubkey_instance.encrypt_seal(message) ) # type: bytes - ascii_armor_block += """{base64_encrypted_message} -""".format( - base64_encrypted_message=base64_encrypted_message.decode("utf-8") - ) + ascii_armor_block += f'{base64_encrypted_message.decode("utf-8")}\n' else: # remove trailing spaces message = AsciiArmor._remove_trailing_spaces(message) @@ -249,27 +239,16 @@ class AsciiArmor: """ base64_signature = base64.b64encode(signing_key.signature(message)) - block = """{begin_signature_header} -{version_field} -""".format( - begin_signature_header=BEGIN_SIGNATURE_HEADER, - version_field=AsciiArmor._get_version_field(), - ) + version_field = AsciiArmor._get_version_field() + block = f"{BEGIN_SIGNATURE_HEADER}\n{version_field}\n" # add message comment if specified if comment: - block += """{comment_field} -""".format( - comment_field=AsciiArmor._get_comment_field(comment) - ) + comment_field = AsciiArmor._get_comment_field(comment) + block += f"{comment_field}\n" # blank line separator - block += "\n" - - block += """{base64_signature} -""".format( - base64_signature=base64_signature.decode("utf-8") - ) + block += f'\n{base64_signature.decode("utf-8")}\n' if close_block: block += END_SIGNATURE_HEADER diff --git a/duniterpy/key/signing_key.py b/duniterpy/key/signing_key.py index 84fa05d9b666b2f6e3d1f42a733e8e8de63c63dc..ccad9f035e7f0673db20d5008d2f8ec053ed1b19 100644 --- a/duniterpy/key/signing_key.py +++ b/duniterpy/key/signing_key.py @@ -210,20 +210,14 @@ class SigningKey(libnacl.sign.Signer): # base58 encode keys base58_signing_key = Base58Encoder.encode(self.sk) - base58_public_key = self.pubkey # save file + content = f"Type: PubSec\n\ +Version: {version}\n\ +pub: {self.pubkey}\n\ +sec: {base58_signing_key}" with open(path, "w") as fh: - fh.write( - """Type: PubSec -Version: {version} -pub: {pubkey} -sec: {signkey}""".format( - version=version, - pubkey=base58_public_key, - signkey=base58_signing_key, - ) - ) + fh.write(content) @staticmethod def from_wif_or_ewif_file( @@ -339,14 +333,11 @@ sec: {signkey}""".format( # base58 encode key and checksum wif_key = Base58Encoder.encode(seed_fi + checksum) + content = f"Type: WIF\n\ +Version: {version}\n\ +Data: {wif_key}" with open(path, "w") as fh: - fh.write( - """Type: WIF -Version: {version} -Data: {data}""".format( - version=version, data=wif_key - ) - ) + fh.write(content) @staticmethod def from_ewif_file(path: str, password: str) -> SigningKeyType: @@ -472,14 +463,11 @@ Data: {data}""".format( ewif_key = Base58Encoder.encode(seed_bytes + checksum) # save file + content = f"Type: EWIF\n\ +Version: {version}\n\ +Data: {ewif_key}" with open(path, "w") as fh: - fh.write( - """Type: EWIF -Version: {version} -Data: {data}""".format( - version=version, data=ewif_key - ) - ) + fh.write(content) @classmethod def from_ssb_file(cls: Type[SigningKeyType], path: str) -> SigningKeyType: