25 Commits

Author SHA1 Message Date
db5f71d240 Migrate to pyproject config
Some checks failed
continuous-integration/drone/push Build is failing
2020-07-07 15:31:53 +02:00
53ce07f1c4 Try to install libsodium
All checks were successful
continuous-integration/drone/push Build is passing
2020-06-30 02:08:31 +02:00
86ba86206c Add new release logs and drone file
Some checks failed
continuous-integration/drone/push Build is failing
2020-05-16 18:40:02 +02:00
7245256c84 Add badge 2020-05-16 18:38:51 +02:00
f49769b3c8 Follow Hypercore protocol and reduce boilerplate 2020-05-16 18:38:29 +02:00
e8ed3bdf21 Fix link 2020-02-22 17:13:49 +01:00
95e05b5f7b Fix organisation name 2020-02-22 14:38:00 +01:00
8f0afd7780 Fix mocker usage 2019-12-04 22:50:05 +07:00
284e0ff66b Also configure RTD to use new docs path 2019-11-26 10:40:43 +07:00
4062168814 Use more standard docs folder 2019-11-25 11:20:53 +07:00
f7a5fd0e2a Add github funding file 2019-11-20 09:58:45 +07:00
2db86a5237 Add liberapay link 2019-11-20 09:49:52 +07:00
02163fab81 Add new change log entry 2019-11-14 19:11:50 +07:00
60a0ff1920 Fix keyword argument
Closes https://github.com/datpy/hypercore-crypto/issues/3.
2019-11-14 19:09:19 +07:00
2f73f08030 Fix RTD 2019-11-03 20:13:47 +01:00
303b8c0fc7 Fix docs build 2019-11-03 18:20:50 +01:00
9cf8b7946a Fix Datpy wording 2019-11-03 16:55:39 +01:00
9321539803 New Sphinx theme and better docs 2019-11-03 16:48:32 +01:00
4254c262fe Add funding file 2019-10-09 00:48:03 +02:00
690adc0ab8 Fix license badge 2019-10-08 23:58:14 +02:00
39b3bdf8b7 Add export list 2019-10-06 16:19:18 +02:00
2c50616ab8 Add example and fix links 2019-10-06 16:19:11 +02:00
980a1e8218 Use right license to match original 2019-10-06 16:18:58 +02:00
c579de3af9 Simplify contrib docs 2019-10-06 16:18:50 +02:00
ed47ad09d8 Inline all the tox definitions 2019-10-06 15:14:09 +02:00
32 changed files with 174 additions and 552 deletions

25
.drone.yml Normal file
View File

@ -0,0 +1,25 @@
---
matrix:
include:
- IMAGE: 3.6-stretch
TOXENV: py36
- IMAGE: 3.7-stretch
TOXENV: py37
- IMAGE: 3.8-buster
TOXENV: py38
- IMAGE: 3.8-buster
TOXENV: lint
- IMAGE: 3.8-buster
TOXENV: sort
- IMAGE: 3.8-buster
TOXENV: format
- IMAGE: 3.8-buster
TOXENV: type
pipeline:
build:
image: python:${IMAGE}
commands:
- apt update && apt install -y libsodium-dev
- pip install tox
- tox -e ${TOXENV}

1
.gitignore vendored
View File

@ -9,4 +9,3 @@ __pycache__
build/
dist/
pip-wheel-metadata/
documentation/build/

View File

@ -1,8 +0,0 @@
version: 2
build:
image: latest
sphinx:
configuration: documentation/source/conf.py
fail_on_warning: true

View File

@ -1,31 +0,0 @@
language: python
addons:
apt:
packages:
- libsodium-dev
matrix:
include:
- python: 3.6
env: TOXENV=py36
- python: 3.7
env: TOXENV=py37
- python: 3.7
env: TOXENV=lint
- python: 3.7
env: TOXENV=sort
- python: 3.7
env: TOXENV=format
- python: 3.7
env: TOXENV=type
- python: 3.7
env: TOXENV=docs
- python: 3.7
env: TOXENV=metadata-release
install:
- pip install tox==3.13.2
script:
- tox -v

23
CHANGELOG.md Normal file
View File

@ -0,0 +1,23 @@
# hypercore-crypto 0.0.1a5 (UNRELEASED)
# hypercore-crypto 0.0.1a4 (2020-07-07)
- Migration configurations to pyproject
- Follow the Hypercore protocol renaming situation.
- Migrate CI to drone.autonomic.zone
- Migrate to git.autonomic.zone
- Reduce package boilerplate
- Removed RTD documentation
# hypercore-crypto 0.0.1a3 (2019-11-14)
- Use the correct keyword argument when invoking `crypto_generichash`.
# hypercore-crypto 0.0.1a2 (2019-11-03)
- Add a changelog.
- New Sphinx theme.
# hypercore-crypto 0.0.1a1 (2019-10-05)
- The first alpha development release is made!

View File

View File

@ -1,111 +0,0 @@
Introduction
------------
The DatPy community is committed to providing an inclusive, safe, and
collaborative environment for all participants, regardless of their gender,
gender expression, race, ethnicity, religion, sexual orientation, sexual
characteristics, physical appearance, disability, or age. We encourage every
participant to be themselves, and must respect the rights of others. The code
of conduct is a set of guidelines that establishes shared values and ensures
that behaviors that may harm participants are avoided.
The values of the DatPy community are focused on developing both our individual
and collective potential, supporting and empowering the most marginalized,
mutual respect, and an anti-violence approach that favors support and
collaboration among participants and the resolution of conflicts. A code of
conduct helps us co-exist in a more positive way and provides individuals who
are victims of negative behaviors with confidence that they will be supported
by the organization and the DatPy community, who respects and stands behind the
code of conduct.
The DatPy community works towards providing a welcoming environment where
participants are treated with dignity and respect and are free to be
themselves. We encourage all participants to approach the Librehosters network
with an open and positive attitude, engaging constructively with others at all
times.
Respect for Diversity & Inclusion
---------------------------------
We avoid comments, actions or propaganda that encourage discrimination related
to gender, gender expression, race, ethnicity, religion, sexual orientation,
sexual characteristics, physical appearance, disability, or age.
Respect Freedom of Expression
-----------------------------
We support an individual's freedom of expression, and will not make fun of
accents or make unsolicited grammatical corrections. We will strive to better
understand each other by not assuming experiences or beliefs, clarifying
meanings, and making an effort to speak clearly, avoiding jargon and acronyms.
Commitment to Non-Violence
--------------------------
We will not engage in any type of violence or aggression, including verbal
threats or complaints, intimidation, stalking or harassment, whether physically
or psychologically.
Rejection of Sexual Harassment
------------------------------
We understand sexual harassment as unwanted physical contact or insinuation of
a sexual nature, as well as displaying images, drawings or visual
representations of any kind that objectify members of any gender or reinforce
oppression. The only exception is if this is part of a session, workshop and/or
educational experience where showing these images is educational in nature.
Respect for Privacy
-------------------
We safeguard the privacy of the participants. This includes refraining from
posting or publishing information about attendees (including names and
affiliation) unless given clear permission, and avoid any type of unauthorized
video, audio recording, or photography.
Facilitate Participation & Collaboration
----------------------------------------
We work to create an environment that facilitates participation for all
participants. We will not engage in sustained disruption of discussions or
events, interrupt conversations in a way that negatively impacts collaboration,
or engage in toxic behaviours to attract negative attention to a participant.
We Care about the Integrity and Health of the Community
-------------------------------------------------------
We value the health of the community and will not engage in behaviour that can
negatively impact it. This includes contaminating food or drink with drugs, or
inciting or insisting on the consumption of alcohol, psychoactive substances,
etc.
Support Positive Interactions Among Participants
------------------------------------------------
We are committed to engaging constructively with others at all times. We will
not tolerate bullying, including requesting or mobilizing others, either in
person or online, to bully others.
Enforcement
-----------
Overseeing the code of conduct
==============================
The DatPy community, composed of volunteers, oversees the
code of conduct, including addressing all incident reports. Breaking the code
of conduct may result in immediate expulsion from the Librehosters network.
How to Report an Incident
=========================
If you witness an incident or are the victim of one:
1. You can reach out directly via email at lukewm@riseup.net.
Acknowledgements
----------------
This code of conduct is inspired by the [IFF CoC].
[IFF CoC]: https://www.internetfreedomfestival.org/wiki/index.php/Code_of_Conduct

View File

@ -1,45 +0,0 @@
Get started
-----------
Install `Tox`_ with:
.. _tox: http://tox.readthedocs.io/
.. code-block:: bash
$ pip install --user tox
Run tests
---------
.. code-block:: bash
tox -e py37
Lint source
-----------
.. code-block:: bash
tox -e lint
Format source
-------------
.. code-block:: bash
tox -e format
Type check source
-----------------
.. code-block:: bash
tox -e type
Release Process
---------------
.. code-block:: bash
$ tox -e release

View File

@ -1 +0,0 @@
include LICENSE README.rst CHANGELOG.rst

22
README.md Normal file
View File

@ -0,0 +1,22 @@
# hypercore-crypto
[![Build Status](https://drone.autonomic.zone/api/badges/hyperpy/hypercore-crypto/status.svg)](https://drone.autonomic.zone/hyperpy/hypercore-crypto)
## Cryptography primitives for Hypercore
## Install
```sh
$ pip install hypercore-crypto
```
## Example
```python
from hypercore_crypto import data, key_pair
from pysodium import crypto_sign_PUBLICKEYBYTES
public_key, secret_key = key_pair()
assert len(public_key) == crypto_sign_PUBLICKEYBYTES
print(data(b"hello world").hex())
```

View File

@ -1,47 +0,0 @@
.. _header:
****************
hypercore-crypto
****************
.. image:: https://img.shields.io/badge/license-GPL-brightgreen.svg
:target: LICENSE
:alt: Repository license
.. image:: https://badge.fury.io/py/hypercore-crypto.svg
:target: https://badge.fury.io/py/hypercore-crypto
:alt: PyPI package
.. image:: https://travis-ci.com/datpy/hypercore-crypto.svg?branch=master
:target: https://travis-ci.com/datpy/hypercore-crypto
:alt: Travis CI result
.. image:: https://readthedocs.org/projects/hypercore-crypto/badge/?version=latest
:target: https://hypercore-crypto.readthedocs.io/en/latest/
:alt: Documentation status
.. image:: https://img.shields.io/badge/support-maintainers-brightgreen.svg
:target: https://decentral1.se
:alt: Support badge
.. _introduction:
Cryptography primitives for Hypercore
-------------------------------------
Cryptography primitives for `Hypercore`_ (WIP).
.. _Hypercore: https://hypercore.readthedocs.io/en/latest/
.. _documentation:
Documentation
*************
* https://hypercore-crypto.readthedocs.io/
Mirroring
*********
* https://hack.decentral1.se/datpy/hypercore-crypto (primary)
* https://github.com/datpy/hypercore-crypto

View File

@ -1,12 +0,0 @@
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SOURCEDIR = source
BUILDDIR = build
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

View File

@ -1,5 +0,0 @@
*********
Changelog
*********
.. include:: ../../CHANGELOG.rst

View File

@ -1,6 +0,0 @@
.. _code-of-conduct:
Code of Conduct
***************
.. include:: ../../CODE_OF_CONDUCT.rst

View File

@ -1,9 +0,0 @@
author = 'decentral1se'
copyright = '2019, decentral1se'
html_static_path = ['_static']
html_theme = 'alabaster'
master_doc = 'index'
project = 'hypercore-crypto'
templates_path = ['_templates']
extensions = ['sphinx.ext.autodoc', 'sphinx_autodoc_typehints']
autodoc_mock_imports = ['pysodium'] # no libsodium in the RTD environment

View File

@ -1,5 +0,0 @@
**********
Contribute
**********
.. include:: ../../CONTRIBUTING.rst

View File

@ -1,14 +0,0 @@
.. include:: ../../README.rst
:end-before: _documentation
Table of Contents
*****************
.. toctree::
install
modules-api
other-impls
contribute
changelog
code-of-conduct

View File

@ -1,11 +0,0 @@
************
Installation
************
.. code-block:: bash
$ pip install hypercore-crypto
.. note::
This tool only supports Python >= 3.6.

View File

@ -1,8 +0,0 @@
.. _modules_api:
***********
Modules API
***********
.. automodule:: hypercore_crypto.crypto
:members:

View File

@ -1,7 +0,0 @@
.. _other-implementations:
Other Implementations
*********************
* https://github.com/mafintosh/hypercore-crypto
* https://github.com/datcxx/hypercore-crypto

View File

@ -1,9 +1,9 @@
"""hypercore-crypto module."""
from hypercore_crypto.crypto import ( # noqa
from hypercore_crypto.crypto import (
data,
discovery_key,
key_pair,
key_pair, # noqa
leaf,
parent,
random_bytes,
@ -11,14 +11,3 @@ from hypercore_crypto.crypto import ( # noqa
tree,
verify,
)
try:
import pkg_resources
except ImportError:
pass
try:
__version__ = pkg_resources.get_distribution('hypercore_crypto').version
except Exception:
__version__ = 'unknown'

View File

@ -15,11 +15,23 @@ from pysodium import (
randombytes,
)
__all__ = [
"key_pair",
"sign",
"verify",
"data",
"leaf",
"parent",
"tree",
"random_bytes",
"discovery_key",
]
# https://en.wikipedia.org/wiki/Merkle_tree#Second_preimage_attack
LEAF_TYPE = bytes([0])
PARENT_TYPE = bytes([1])
ROOT_TYPE = bytes([2])
HYPERCORE = bytes('hypercore', encoding='utf-8')
HYPERCORE = bytes("hypercore", encoding="utf-8")
def key_pair(seed: Optional[bytes] = None) -> Tuple[bytes, bytes]:
@ -78,7 +90,7 @@ def leaf(leaf: MerkleTreeNode) -> bytes:
def parent(child: MerkleTreeNode, parent: MerkleTreeNode) -> bytes:
if child.index > parent.index:
raise ValueError('Child index is greater than parent?')
raise ValueError("Child index is greater than parent?")
values = [
PARENT_TYPE,
@ -119,7 +131,7 @@ def discovery_key(public_key: bytes) -> bytes:
:param public_key: The public key for hashing
"""
return crypto_generichash(HYPERCORE, key=public_key)
return crypto_generichash(HYPERCORE, k=public_key)
def _to_unsigned_64_int(num: int) -> bytes:
@ -129,7 +141,7 @@ def _to_unsigned_64_int(num: int) -> bytes:
:param num: The integer to be converted
"""
return int(num).to_bytes(8, byteorder='big', signed=False)
return int(num).to_bytes(8, byteorder="big", signed=False)
def _blake2bify(data: Sequence[bytes]) -> bytes:

View File

@ -1,4 +0,0 @@
[mypy]
python_version = 3.7
platform = linux
ignore_missing_imports = True

View File

@ -1,54 +1,77 @@
[build-system]
requires = [
'setuptools>=40.9.0',
'setuptools-scm',
'wheel',
]
build-backend = 'setuptools.build_meta'
requires = ["poetry>=1.0.9,<2.0"]
build-backend = "poetry.masonry.api"
[tool.poetry]
name = "hypercore-crypto"
version = "0.0.1a4"
description = "Cryptography primitives for Hypercore"
authors = ["Decentral1se <hi@decentral1.se>"]
maintainers = ["Decentral1se <hi@decentral1.se>"]
license = "GPLv3"
readme = "README.md"
repository = "https://github.com/hyperpy/hypercore-crypto"
keywords = ["hypercore", "hypercore-protocol"]
[tool.poetry.dependencies]
python = "^3.6"
pysodium = "^0.7.5"
merkle-tree-stream = "^0.0.1-alpha.4"
[tool.poetry.dev-dependencies]
black = "^19.10b0"
flake8 = "^3.8.3"
isort = "^5.0.2"
[tool.black]
line-length = 80
target-version = ['py36', 'py37']
skip-string-normalization = true
target-version = ["py38"]
include = '\.pyi?$'
[tool.towncrier]
directory = 'changelog/'
filename = 'CHANGELOG.rst'
package = 'hypercore-crypto'
package_dir = 'hypercore-crypto'
[tool.isort]
include_trailing_comma = true
known_first_party = "hypercore_crypto"
known_third_party = "pytest"
line_length = 80
multi_line_output = 3
skip = ".venv,.tox"
[[tool.towncrier.type]]
directory = 'removal'
name = 'Removals'
showcontent = true
[tool.tox]
legacy_tox_ini = """
[tox]
envlist =
{py36,py37,py38}
lint
sort
format
type
skip_missing_interpreters = True
isolated_build = True
[[tool.towncrier.type]]
directory = 'deprecation'
name = 'Deprecations'
showcontent = true
[testenv]
deps =
pytest
pytest-cov
pytest-mock
commands = pytest test/ --cov={toxinidir}/hypercore_crypto/ --no-cov-on-fail {posargs}
[[tool.towncrier.type]]
directory = 'feature'
name = 'Features'
showcontent = true
[testenv:lint]
skipdist = True
deps = flake8
commands = flake8 {posargs:--max-line-length 80} hypercore_crypto/ test/
[[tool.towncrier.type]]
directory = 'bugfix'
name = 'Bug Fixes'
showcontent = true
[testenv:sort]
skipdist = True
deps = isort
commands = isort {posargs:-c} -sp setup.cfg hypercore_crypto/ test/
[[tool.towncrier.type]]
directory = 'doc'
name = 'Improved Documentation'
showcontent = true
[testenv:format]
skipdist = True
deps = black
commands = black {posargs:--check} hypercore_crypto/ test/
[[tool.towncrier.type]]
directory = 'trivial'
name = 'Trivial/Internal Changes'
showcontent = true
[[tool.towncrier.type]]
directory = 'announce'
name = 'Project announcements'
showcontent = true
[testenv:type]
skipdist = True
deps = mypy
commands = mypy {posargs:--ignore-missing-imports} hypercore_crypto/ test/
"""

View File

@ -1,63 +0,0 @@
[tool:pytest]
testpaths = test
[flake8]
max-line-length = 80
[isort]
known_first_party = hypercore-crypto
known_third_party = pytest
line_length = 80
multi_line_output = 3
skip = .venv, .tox
include_trailing_comma = True
[metadata]
name = hypercore-crypto
author = decentral1se
author_email = lukewm@riseup.net
maintainer = decentral1se
maintainer_email = lukewm@riseup.net
url = https://hack.decentral1.se/datpy/hypercore-crypto
project_urls =
Source Code = https://hack.decentral1.se/datpy/hypercore-crypto
Documentation = https://hypercore-crypto.readthedocs.io/
Maintainer Support = https://decentral1.se
description = Cryptography primitives for Hypercore
long_description = file: README.rst
license = GPLv3
license_file = LICENSE
classifiers =
Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
[options]
use_scm_version = True
python_requires = >=3.6
setup_requires =
setuptools_scm
setuptools_scm_git_archive
package_dir =
= .
packages = find:
zip_safe = False
install_requires =
pysodium >= 0.7.2, < 0.8
merkle-tree-stream >= 0.0.1a1, < 1.0.0
[options.packages.find]
where = .
[build_sphinx]
all_files = 1
build-dir = documentation/build
source-dir = documentation/source
warning-is-error = True
[options.extras_require]
docs =
sphinx
sphinx-autodoc-typehints >= 1.6.0, < 2.0
changelog =
towncrier <= 19.2.0, < 20.0

View File

@ -1,3 +0,0 @@
from setuptools import setup
setup(use_scm_version=True)

View File

@ -4,13 +4,21 @@ import pytest
from merkle_tree_stream import MerkleTreeNode
from pysodium import crypto_sign_PUBLICKEYBYTES, crypto_sign_SECRETKEYBYTES
from hypercore_crypto import data, key_pair, parent, random_bytes, sign, verify
from hypercore_crypto import (
data,
discovery_key,
key_pair,
parent,
random_bytes,
sign,
verify,
)
def test_key_pair_seed_length():
with pytest.raises(ValueError) as exception:
key_pair(b'world hello')
assert 'must be of length' in str(exception)
key_pair(b"world hello")
assert "must be of length" in str(exception)
def test_key_pair_length():
@ -20,7 +28,7 @@ def test_key_pair_length():
def test_sign():
message = b'hello world'
message = b"hello world"
_, secret_key = key_pair()
signature = sign(message, secret_key)
assert message not in signature
@ -28,7 +36,7 @@ def test_sign():
def test_verify():
message = b'hello world'
message = b"hello world"
public_key, secret_key = key_pair()
signature = sign(message, secret_key)
assert verify(message, signature, public_key)
@ -36,8 +44,8 @@ def test_verify():
def test_data_digest():
assert (
data(b'hello world').hex()
== 'ccfa4259ee7c41e411e5770973a49c5ceffb5272d6a37f2c6f2dac2190f7e2b7'
data(b"hello world").hex()
== "ccfa4259ee7c41e411e5770973a49c5ceffb5272d6a37f2c6f2dac2190f7e2b7"
)
@ -46,7 +54,7 @@ def test_random_bytes():
def test_parent_digest():
_data = b'hello world'
_data = b"hello world"
_parent = parent(
MerkleTreeNode(
index=0, size=11, hash=data(_data), parent=None, data=None
@ -57,5 +65,9 @@ def test_parent_digest():
)
assert (
_parent.hex()
== '43563406adba8b34b133fdca32d0a458c5be769615e01df30e6535ccd3c075f0'
== "43563406adba8b34b133fdca32d0a458c5be769615e01df30e6535ccd3c075f0"
)
def test_discovery_key_generated():
assert discovery_key(random_bytes(32)) is not None

View File

@ -1,9 +0,0 @@
"""Version test module."""
def test_version_fails_gracefully(mocker):
target = 'pkg_resources.get_distribution'
with mocker.patch(target, side_effect=Exception()):
from hypercore_crypto.__init__ import __version__
assert __version__ == 'unknown'

84
tox.ini
View File

@ -1,84 +0,0 @@
[tox]
envlist =
{py36,py37}
lint
sort
format
type
docs
changelog
metadata-release
skip_missing_interpreters = True
isolated_build = True
[testenv]
description = run the unit tests
deps =
pytest
pytest-cov
pytest-mock
commands =
pytest test/ --cov={toxinidir}/hypercore_crypto/ --no-cov-on-fail {posargs}
[testenv:lint]
description = lint the source
skipdist = True
deps =
flake8
commands =
flake8 {posargs} hypercore_crypto/ test/
[testenv:sort]
description = sort the source
skipdist = True
deps =
isort
commands =
isort {posargs:-rc -c} -sp setup.cfg hypercore_crypto/ test/
[testenv:format]
description = format the source
skipdist = True
basepython = python3.7
deps =
black
commands =
black {posargs:--check} hypercore_crypto/ test/
[testenv:type]
description = type check the source
basepython = python3.7
skipdist = True
deps =
mypy
commands =
mypy hypercore_crypto/ test/
[testenv:docs]
description = build the documentation
skipdist = True
extras = docs
commands =
python -m setup build_sphinx
[testenv:changelog]
description = draft the changelog
skipdist = True
extras = changelog
commands =
towncrier --draft
[testenv:metadata-release]
description = validate the package metadata
deps =
twine
commands =
twine check .tox/dist/*
[testenv:release]
description = make a release
deps =
{[testenv:metadata-release]deps}
commands =
python -m setup sdist bdist_wheel
twine upload {toxworkdir}/dist/*