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

[enh] #71: add helpers to convert seed into seedhex and vice versa

parent ebb6ee3e
No related branches found
No related tags found
1 merge request!54#71: handle seedhex
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")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment