onionrblocks/onionrblocks/__init__.py

33 lines
1021 B
Python

from typing import Union
from time import time
import kasten
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', {}),
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):
# Block with anonymous VDF as proof
packed = _packer(block_data, **block_header)
return kasten.generator.KastenMimcGenerator.generate(
packed, rounds)