diff --git a/duniterpy/helpers.py b/duniterpy/helpers.py index 251a53f095f9838880836784e23d3066d93467ad..0baaa2bba895a905f743ea52cfa7356b7e2f822a 100644 --- a/duniterpy/helpers.py +++ b/duniterpy/helpers.py @@ -1,4 +1,5 @@ from typing import Union +from libnacl.encode import hex_decode, hex_encode def ensure_bytes(data: Union[str, bytes]) -> bytes: @@ -39,3 +40,23 @@ def xor_bytes(b1: bytes, b2: bytes) -> bytearray: for i1, i2 in zip(b1, b2): result.append(i1 ^ i2) return result + + +def convert_seedhex_to_seed(seedhex: str) -> bytes: + """ + Convert seedhex to seed + + :param seedhex: seed coded in hexadecimal base + :rtype bytes: + """ + return bytes(hex_decode(seedhex.encode("utf-8"))) + + +def convert_seed_to_seedhex(seed: bytes) -> str: + """ + Convert seed to seedhex + + :param seed: seed + :rtype str: + """ + return hex_encode(seed).decode("utf-8")