diff --git a/proofow.py b/proofow.py index 462ff77..e9d9aa2 100644 --- a/proofow.py +++ b/proofow.py @@ -1,5 +1,6 @@ from os import urandom from itertools import count +from base64 import b64encode, b64decode from hashlib import sha256 @@ -28,6 +29,16 @@ class pow_base: hexresult = self._hexdigest(self._base + str(nonce).encode()) return int(hexresult, 16) < self._target + def export(self): + return b64encode(str(self.difficulty).encode() + + b':' + + self.base).decode() + + @classmethod + def load(cls, export): + difficulty, base = b64decode(export.encode()).split(b':', 1) + return cls(int(difficulty), base) + class pow_hashlib_base(pow_base): def _hexdigest(self, data):