From 0f38930b3c4cdceaab0c1cf3a5a8aa2287579e08 Mon Sep 17 00:00:00 2001
From: Moul <moul@moul.re>
Date: Wed, 16 Jan 2019 17:52:46 +0100
Subject: [PATCH] [enh] #71: add helpers to convert seed into seedhex and vice
 versa

---
 duniterpy/helpers.py | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/duniterpy/helpers.py b/duniterpy/helpers.py
index 251a53f0..0baaa2bb 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")
-- 
GitLab