From 8583f564e156d17046c949c526da91b9a9f2019d Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Mon, 30 Nov 2026 17:49:45 +0000 Subject: [PATCH 1/2] refactor: derive bls seed without btclib --- crypto/identity/bls_private_key.py | 12 ++++++++---- tests/identity/test_bls_private_key.py | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/crypto/identity/bls_private_key.py b/crypto/identity/bls_private_key.py index 0e56c03e..cecd5009 100644 --- a/crypto/identity/bls_private_key.py +++ b/crypto/identity/bls_private_key.py @@ -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')) @@ -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) diff --git a/tests/identity/test_bls_private_key.py b/tests/identity/test_bls_private_key.py index e4076001..6522196c 100644 --- a/tests/identity/test_bls_private_key.py +++ b/tests/identity/test_bls_private_key.py @@ -1,3 +1,5 @@ +import pytest + from crypto.identity.bls_public_key import BLSPrivateKey @@ -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) From a0c671495ec0e018149e5b091f19375f47ce8c9f Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Mon, 30 Nov 2026 17:49:45 +0000 Subject: [PATCH 2/2] chore: update dependencies --- .github/workflows/test.yml | 6 ++-- requirements.txt | 65 ++++++++++---------------------------- setup.cfg | 3 -- setup.py | 30 +++++++----------- 4 files changed, 31 insertions(+), 73 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 99c4d2fa..050fb038 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 }} diff --git a/requirements.txt b/requirements.txt index 433db20b..52d77f39 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/setup.cfg b/setup.cfg index 3a6687a9..3ee7b291 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,3 @@ -[aliases] -test=pytest - [flake8] max-line-length = 100 application-import-names = crypto diff --git a/setup.py b/setup.py index 9569f281..c4daccd7 100644 --- a/setup.py +++ b/setup.py @@ -1,24 +1,21 @@ -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 = { @@ -26,8 +23,6 @@ '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.', @@ -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, )