Adds Makefile + Lint

This commit is contained in:
Carl Beekhuizen 2020-02-18 17:44:32 +01:00
parent 97350c941c
commit c89603e9c4
No known key found for this signature in database
GPG Key ID: 8F29E54F49E7AAB5
10 changed files with 36 additions and 15 deletions

9
.gitignore vendored Normal file
View File

@ -0,0 +1,9 @@
# Eth2 specs:
eth2.0-specs/
# Python testing & linting:
venv/
.pytest_cache
.hypothesis
.mypy_cache
__pycache__

17
Makefile Normal file
View File

@ -0,0 +1,17 @@
clean:
rm -rf eth2.0-specs/
rm -rf venv/
find . -name __pycache__ -exec rm -rf {} \;
find . -name .mypy_cache -exec rm -rf {} \;
find . -name .pytest_cache -exec rm -rf {} \;
install_test:
python3 -m venv venv; . venv/bin/activate; pip3 install -r requirements.txt
test:
. venv/bin/activate; python -m pytest ./src
lint:
. venv/bin/activate; \
flake8 --ignore=E252,W504,W503 --max-line-length=120 ./src \
&& mypy --follow-imports=skip --ignore-missing-imports src

0
src/__init__.py Normal file
View File

View File

View File

@ -1,9 +1,12 @@
from os import walk
from secrets import randbits
from typing import (
List,
Optional,
)
from ..utils.crypto import SHA256
word_lists_path = './src/key_derivation/word_lists/'

0
src/utils/__init__.py Normal file
View File

View File

@ -11,6 +11,7 @@ from Crypto.Cipher import (
AES as _AES
)
def SHA256(x):
return _sha256.new(x).digest()

View File

@ -3,15 +3,6 @@ from ssz import (
Serializable,
)
from utils.typing import (
BLSPubkey,
BLSPrivkey,
BLSSignature,
Domain,
DomainType,
Version,
Root,
)
from utils.constants import (
DOMAIN_DEPOSIT,
GENESIS_FORK_VERSION,
@ -25,14 +16,14 @@ class SigningRoot(Serializable):
]
def compute_domain(domain_type: DomainType=DomainType(DOMAIN_DEPOSIT), fork_version: Version=GENESIS_FORK_VERSION) -> Domain:
def compute_domain(domain_type: bytes=DOMAIN_DEPOSIT, fork_version: bytes=GENESIS_FORK_VERSION) -> bytes:
"""
Return the domain for the ``domain_type`` and ``fork_version``.
"""
return Domain(domain_type + fork_version)
return domain_type + fork_version
def compute_signing_root(ssz_object, domain: Domain) -> Root:
def compute_signing_root(ssz_object: Serializable, domain: bytes) -> bytes:
"""
Return the signing root of an object by calculating the root of the object-domain tree.
"""