Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.11", "3.12", "3.13"]

steps:
- name: Checkout code
uses: actions/checkout@v4
uses: actions/checkout@v7
with:
submodules: true
ref: ${{ github.head_ref }}

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python-version }}

Expand Down
12 changes: 8 additions & 4 deletions crypto/identity/bls_private_key.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from btclib.mnemonic import bip39

import sys
import hashlib
import os
import sys
import unicodedata
from os.path import dirname

sys.path.append(os.path.join(dirname(dirname(__file__)), 'thirdparty/bls-signatures/python-impl'))
Expand Down Expand Up @@ -30,7 +30,11 @@ def from_passphrase(cls, passphrase: str):
Returns:
PrivateKey: Private key object
"""
seed = bip39.seed_from_mnemonic(passphrase, '')
mnemonic = unicodedata.normalize('NFKD', passphrase)
if len(mnemonic.split(' ')) not in (12, 15, 18, 21, 24):
raise ValueError('Invalid mnemonic')

seed = hashlib.pbkdf2_hmac('sha512', mnemonic.encode(), b'mnemonic', 2048, 64)

sk = BasicSchemeMPL.key_gen(seed)

Expand Down
65 changes: 16 additions & 49 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,54 +1,21 @@
arkecosystem-crypto==2.0.0
asn1crypto==1.5.1
attrs==23.2.0
base58==2.1.1
beautifulsoup4==4.12.3
binary-helpers==0.0.4
btclib==2023.7.12
btclib_libsecp256k1==0.4.0
cached-property==1.5.2
certifi==2024.7.4
cffi==1.16.0
charset-normalizer==3.3.2
coincurve==20.0.0
commonmark==0.9.1
coverage==7.5.4
cryptography==43.0.0
cytoolz==0.12.3
eth-hash==0.7.0
eth-typing==4.4.0
eth-utils==4.1.1
exceptiongroup==1.2.1
flake8==7.1.0
flake8-import-order==0.18.2
cffi==2.1.1
coincurve==21.0.0
coverage==7.18.0
cryptography==50.0.2
flake8==7.5.0
flake8-import-order==0.19.2
flake8-print==5.0.0
flake8-quotes==3.4.0
idna==3.7
iniconfig==2.0.0
markdown-it-py==3.0.0
iniconfig==2.3.1
mccabe==0.7.0
mdurl==0.1.2
numpy==2.0.1
packaging==24.1
pluggy==1.5.0
py==1.11.0
pycodestyle==2.12.0
pycparser==2.22
pycryptodomex==3.20.0
pyflakes==3.2.0
Pygments==2.18.0
pyparsing==3.1.2
pytest==8.2.2
pytest-cov==5.0.0
PyYAML==6.0.1
requests==2.32.3
rich==13.7.1
scipy==1.14.0
six==1.16.0
soupsieve==2.5
toml==0.10.2
tomli==2.0.1
toolz==0.12.1
tqdm==4.66.4
typing_extensions==4.12.2
urllib3==2.2.2
packaging==26.4
pluggy==1.7.0
pycodestyle==2.15.0
pycparser==3.12
pycryptodomex==3.24.2
pyflakes==4.1.0
pygments==2.21.0
pytest==9.2.0
pytest-cov==7.1.0
3 changes: 0 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[aliases]
test=pytest

[flake8]
max-line-length = 100
application-import-names = crypto
Expand Down
30 changes: 12 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,28 @@
import sys

import setuptools


requires = [
'base58',
'binary-helpers',
'coincurve',
'pycryptodomex',
'btclib==2023.7.12',
'cryptography',
'base58>=2.1.1',
'binary-helpers>=0.0.4',
'coincurve>=21.0.0',
'pycryptodomex>=3.24.2',
'cryptography>=50.0.2',
]

tests_require = [
'flake8>=3.5.0',
'flake8-import-order>=0.17.1',
'flake8-print>=3.1.0',
'flake8-quotes>=1.0.0',
'pytest>=3.6.1',
'pytest-cov>=2.5.1',
'flake8>=7.5.0',
'flake8-import-order>=0.19.2',
'flake8-print>=5.0.0',
'flake8-quotes>=3.4.0',
'pytest>=9.2.0',
'pytest-cov>=7.1.0',
]

extras_require = {
'test': tests_require,
'dev': requires + tests_require
}

setup_requires = ['pytest-runner'] if {'pytest', 'test', 'ptr'}.intersection(sys.argv) else []

setuptools.setup(
name='arkecosystem-crypto',
description='A simple Cryptography Implementation in Python for the Ark Blockchain.',
Expand All @@ -38,8 +33,7 @@
packages=setuptools.find_packages(exclude=['tests', 'tests.*', 'crypto/thirdparty/bls-signatures'])
+ ['crypto/thirdparty/bls-signatures/python-impl'],
include_package_data=True,
python_requires='>=3.11',
install_requires=requires,
extras_require=extras_require,
tests_require=tests_require,
setup_requires=setup_requires,
)
18 changes: 18 additions & 0 deletions tests/identity/test_bls_private_key.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import pytest

from crypto.identity.bls_public_key import BLSPrivateKey


Expand All @@ -12,3 +14,19 @@ def test_many_private_keys_from_passphrase(bls_keys):
private_key = BLSPrivateKey.from_passphrase(bls_private_key['passphrase']).to_hex()

assert private_key == bls_private_key['bls_private_key']


def test_private_key_from_passphrase_without_valid_checksum():
private_key = BLSPrivateKey.from_passphrase(' '.join(['abandon'] * 12)).to_hex()

assert private_key == '2dd802df897c60309cb17a2e0f602827ca6fd3afe9cce050c856c1d46a8e37c0'


@pytest.mark.parametrize('passphrase', [
'this is a top secret passphrase',
' '.join(['abandon'] * 13),
' '.join(['abandon'] * 25),
])
def test_private_key_from_passphrase_with_invalid_word_count(passphrase):
with pytest.raises(ValueError, match='Invalid mnemonic'):
BLSPrivateKey.from_passphrase(passphrase)