From af0ca4a33d5ee8eb0ffa1fab7a50407a55b3c767 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Mon, 7 Dec 2020 14:54:25 +0000 Subject: [PATCH] work on loading block --- onionrblocks/__init__.py | 43 +--------------------------------------- requirements.in | 2 +- requirements.txt | 6 +++--- tests/test_vdf_block.py | 9 ++++++--- 4 files changed, 11 insertions(+), 49 deletions(-) diff --git a/onionrblocks/__init__.py b/onionrblocks/__init__.py index 9a2b534..8e95948 100644 --- a/onionrblocks/__init__.py +++ b/onionrblocks/__init__.py @@ -6,47 +6,6 @@ import kasten from .types import AnonymousVDFBlockResult +from .create import create_block_anonymous_vdf -def __str_to_bytes(data: str): - try: - return data.encode('utf-8') - except AttributeError: - return data - - -def _packer(block_data: bytes, **kasten_header) -> kasten.main.KastenPacked: - def __get_optional(key, default): - try: - return kasten_header[key] - except KeyError: - return default - # Todo: validate length sanities - return kasten.generator.pack.pack( - block_data, - kasten_header['type'], - kasten_header['encrypt mode'], - __get_optional('signer', b''), - __get_optional('signature', b''), - __get_optional('metadata', None), - int(time()//60 * 60) - ) - - -# Block creation functions handle calling the proof and compiling blocks -# They do not handle sigs or encryption (at least never directly) - -def create_block_anonymous_vdf( - rounds: int, - block_data: Union[str, bytes], - **block_header) -> AnonymousVDFBlockResult: - block_data = __str_to_bytes(block_data) - # Block with anonymous VDF as proof - - packed: kasten.types.KastenPacked = _packer(block_data, **block_header) - kasten_result: kasten.Kasten = \ - kasten.generator.KastenMimcGenerator.generate(packed, rounds) - print('orig packed', packed) - return AnonymousVDFBlockResult( - kasten_result.id, - kasten_result.get_packed()) diff --git a/requirements.in b/requirements.in index adea48d..9ba2d81 100644 --- a/requirements.in +++ b/requirements.in @@ -1 +1 @@ -kasten==0.0.7 \ No newline at end of file +kasten==0.1.0 diff --git a/requirements.txt b/requirements.txt index 57651b2..312780f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,9 +4,9 @@ # # pip-compile --generate-hashes requirements.in # -kasten==0.0.7 \ - --hash=sha256:01edc0ac72a49c851b4fbbc0ec2d2c9c9d9a114c1492c0f5af1b10602de6d82e \ - --hash=sha256:29baf5270b2dda51c8fed14a3d7108bd86e73e34f30ead9c054ce66d478e0c12 \ +kasten==0.1.0 \ + --hash=sha256:21214afc1e61eb32bafdebbedc1856de973a0ac0798c1710787b889c7f9e9899 \ + --hash=sha256:a5d583f383778d256e56f69fa50c3c22e8fb1aa95923ff3d1c8f915e1235418e \ # via -r requirements.in mimcvdf==1.1.0 \ --hash=sha256:97a4ccdebb58352c64c268d2e57ef8817c9fe4ac3dcc922410bfcc72033f344a \ diff --git a/tests/test_vdf_block.py b/tests/test_vdf_block.py index ab7a93a..1b8dd88 100644 --- a/tests/test_vdf_block.py +++ b/tests/test_vdf_block.py @@ -7,15 +7,18 @@ import onionrblocks class TestVDFBlock(unittest.TestCase): - def test_basic(self): + def test_vdf_create(self): rounds = 10**4 data = b'test data' k = onionrblocks.create_block_anonymous_vdf(rounds, data, **{'type': 'test', 'encrypt mode': 0}) raw = k.raw_bytes - id = int.from_bytes(k.hex_checksum, byteorder="big") + id = int.from_bytes(k.dec_checksum, byteorder="big") #print(id, raw) - print(raw) + print(id, raw) kasten.generator.KastenMimcGenerator.validate_id(id, raw, rounds) + self.assertEqual(len(raw), 22) + + def test_vdf_auto_validate_loader unittest.main() \ No newline at end of file