diff --git a/.travis.yml b/.travis.yml index f558483..1ce50ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,9 +3,9 @@ language: python matrix: include: - python: 3.6 - env: TOXENV=py36-test + env: TOXENV=py36 - python: 3.7 - env: TOXENV=py37-test + env: TOXENV=py37 - python: 3.7 env: TOXENV=lint - python: 3.7 diff --git a/CHANGELOG.rst b/CHANGELOG.rst index fe461b2..cff2059 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,12 @@ +Merkle_Tree_Stream 0.0.1a2 (2019-10-06) +======================================= + +Bug Fixes +--------- + +- MerkleTreeIterator leaf and parent functions now return bytes. + + Merkle_Tree_Stream 0.0.1a1 (2019-08-07) ======================================= diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 0f4fe03..86c7812 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -1,14 +1,10 @@ Get started ----------- -Install `Tox`_ with: +Install `Tox`_. .. _tox: http://tox.readthedocs.io/ -.. code-block:: bash - - $ pip install --user tox - Run tests --------- @@ -40,22 +36,6 @@ Type check source Release Process --------------- -Add a change entry and re-generate the changelog: - .. code-block:: bash - $ towncrier - -Make a new release tag: - -.. code-block:: bash - - $ git tag x.x.x - $ git push --tags - -Then run the release process: - -.. code-block:: bash - - $ tox -e metadata-release $ tox -e release diff --git a/README.rst b/README.rst index 51f1d1c..becd9a9 100644 --- a/README.rst +++ b/README.rst @@ -61,15 +61,42 @@ reference implementation. .. _merkle-tree-stream: https://github.com/mafintosh/merkle-tree-stream .. _Python iterator: https://docs.python.org/3/c-api/iter.html +.. _example: + +.. code-block:: python + + from hashlib import sha256 + from merkle_tree_stream import MerkleTreeIterator + + + def leaf(node, roots=None): + return sha256(node.data).digest() + + def parent(first, second): + sha256 = hashlib.sha256() + sha256.update(first.data) + sha256.update(second.data) + return sha256.digest() + + merkle_iter = MerkleTreeIterator(leaf=leaf, parent=parent) + merkle_iter.write('hello') + merkle_iter.write('hashed') + merkle_iter.write('world') + .. _documentation: Documentation ************* -* https://merkle-tree-stream.readthedocs.io/ +* `merkle-tree-stream.readthedocs.io`_ + +.. _merkle-tree-stream.readthedocs.io: https://merkle-tree-stream.readthedocs.io/ Mirroring ********* -* https://hack.decentral1.se/datpy/merkle-tree-stream (primary) -* https://github.com/datpy/merkle-tree-stream +* `hack.decentral1.se/datpy/merkle-tree-stream`_ +* `github.com/datpy/merkle-tree-stream`_ + +.. _hack.decentral1.se/datpy/merkle-tree-stream: https://hack.decentral1.se/datpy/merkle-tree-stream +.. _github.com/datpy/merkle-tree-stream: https://github.com/datpy/merkle-tree-stream diff --git a/merkle_tree_stream/node.py b/merkle_tree_stream/node.py index 192c92f..3fb1689 100644 --- a/merkle_tree_stream/node.py +++ b/merkle_tree_stream/node.py @@ -23,7 +23,7 @@ class MerkleTreeNode: parent: int size: int data: bytes - hash: Optional[str] = attr.Factory(str) + hash: Optional[bytes] = attr.Factory(bytes) def __attrs_post_init__(self) -> Any: """Initialise the parent index.""" diff --git a/merkle_tree_stream/tree.py b/merkle_tree_stream/tree.py index 547d49e..930af05 100644 --- a/merkle_tree_stream/tree.py +++ b/merkle_tree_stream/tree.py @@ -7,8 +7,6 @@ from flat_tree import FlatTreeAccessor from merkle_tree_stream.node import MerkleTreeNode -Hash = str - EMPTY_DATA = b'' EMPTY_HASH = None @@ -26,8 +24,8 @@ class MerkleTreeIterator: :param roots: The tree roots """ - leaf: Callable[[MerkleTreeNode], Hash] - parent: Callable[[MerkleTreeNode, MerkleTreeNode], Hash] + leaf: Callable[[MerkleTreeNode], bytes] + parent: Callable[[MerkleTreeNode, MerkleTreeNode], bytes] roots: List[MerkleTreeNode] = attr.Factory(list) _position: int = 0 diff --git a/pyproject.toml b/pyproject.toml index 07b72d6..3ccf8ec 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,7 @@ include = '\.pyi?$' [tool.towncrier] directory = "changelog/" filename = "CHANGELOG.rst" -package = "merkle-tree-stream" +package = "merkle_tree_stream" package_dir = "merkle_tree_stream" [[tool.towncrier.type]] diff --git a/setup.cfg b/setup.cfg index c3a210a..a8d051f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -37,7 +37,7 @@ install_requires = [options] use_scm_version = True -python_requires = !=2.7.*, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.* +python_requires = >=3.6 setup_requires = setuptools_scm setuptools_scm_git_archive @@ -47,7 +47,7 @@ packages = find: zip_safe = False install_requires = attrs >= 19.1.0, < 20.0 - flat-tree == 0.0.1a3 # TODO(decentral1se): use bounds when 0.0.1 lands + flat-tree >= 0.0.1a3, < 1.0 [options.packages.find] where = . diff --git a/test/conftest.py b/test/conftest.py index f0fad3a..a70772e 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -6,7 +6,7 @@ import pytest @pytest.fixture def leaf(): def _leaf(node, roots=None): - return hashlib.sha256(node.data).hexdigest() + return hashlib.sha256(node.data).digest() return _leaf @@ -17,6 +17,6 @@ def parent(): sha256 = hashlib.sha256() sha256.update(first.data) sha256.update(second.data) - return sha256.hexdigest() + return sha256.digest() return _parent diff --git a/test/test_tree.py b/test/test_tree.py index 07cb231..6953296 100644 --- a/test/test_tree.py +++ b/test/test_tree.py @@ -17,26 +17,18 @@ def test_hashes(leaf, parent): assert len(merkle_iter) == expected_count assert next(merkle_iter) == MerkleTreeNode( - index=0, - parent=1, - hash=hashlib.sha256(b'a').hexdigest(), - size=1, - data=b'a', + index=0, parent=1, hash=hashlib.sha256(b'a').digest(), size=1, data=b'a' ) assert next(merkle_iter) == MerkleTreeNode( - index=2, - parent=1, - hash=hashlib.sha256(b'b').hexdigest(), - size=1, - data=b'b', + index=2, parent=1, hash=hashlib.sha256(b'b').digest(), size=1, data=b'b' ) hashed = hashlib.sha256(b'a') hashed.update(b'b') assert next(merkle_iter) == MerkleTreeNode( - index=1, parent=3, hash=hashed.hexdigest(), size=2, data=b'' + index=1, parent=3, hash=hashed.digest(), size=2, data=b'' ) with pytest.raises(StopIteration): diff --git a/tox.ini b/tox.ini index 6fe0aac..e2c5b31 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] envlist = - {py36,py37}-test + {py36,py37} lint sort format @@ -17,70 +17,54 @@ deps = pytest pytest-cov pytest-mock -commands = - pytest test/ --cov={toxinidir}/merkle_tree_stream/ --no-cov-on-fail {posargs} +commands = pytest test/ --cov={toxinidir}/merkle_tree_stream/ --no-cov-on-fail {posargs} [testenv:lint] description = lint the source skipdist = True -deps = - flake8 -commands = - flake8 {posargs} merkle_tree_stream/ test/ +deps = flake8 +commands = flake8 {posargs} merkle_tree_stream/ test/ [testenv:sort] description = sort the source skipdist = True -deps = - isort -commands = - isort {posargs:-rc -c} -sp setup.cfg merkle_tree_stream/ test/ +deps = isort +commands = isort {posargs:-rc -c} -sp setup.cfg merkle_tree_stream/ test/ [testenv:format] description = format the source skipdist = True basepython = python3.6 -deps = - black -commands = - black {posargs:--check} merkle_tree_stream/ test/ +deps = black +commands = black {posargs:--check} merkle_tree_stream/ test/ [testenv:type] description = type check the source basepython = python3.7 skipdist = True -deps = - mypy -commands = - mypy merkle_tree_stream/ test/ +deps = mypy +commands = mypy merkle_tree_stream/ test/ [testenv:docs] description = build the documentation skipdist = True -extras = - docs -commands = - python -m setup build_sphinx +extras = docs +commands = python -m setup build_sphinx [testenv:changelog] description = draft the changelog skipdist = True -extras = - changelog -commands = - towncrier --draft +extras = changelog +commands = towncrier --draft [testenv:metadata-release] description = validate the package metadata -deps = - twine -commands = - twine check .tox/dist/* +deps = twine +commands = twine check {toxworkdir}/dist/* [testenv:release] description = make a release -deps = - {[testenv:metadata-release]deps} +deps = {[testenv:metadata-release]deps} commands = python -m setup sdist bdist_wheel twine upload {toxworkdir}/dist/*