Skip to content

Commit

Permalink
fix: ripemd160 usage (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbarnsley authored Jul 17, 2024
1 parent f55837f commit fa6560a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ dist/
.vscode
.vs
venv
venv/
venv/
.venv/
5 changes: 3 additions & 2 deletions crypto/identity/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from crypto.configuration.network import get_network
from crypto.identity.private_key import PrivateKey

from Cryptodome.Hash import RIPEMD160

def address_from_public_key(public_key, network_version=None):
"""Get an address from a public key
Expand All @@ -23,7 +24,7 @@ def address_from_public_key(public_key, network_version=None):
network = get_network()
network_version = network['version']

ripemd160 = hashlib.new('ripemd160', unhexlify(public_key.encode()))
ripemd160 = RIPEMD160.new(data=unhexlify(public_key.encode()))
seed = write_bit8(network_version) + ripemd160.digest()
return b58encode_check(seed).decode()

Expand All @@ -43,7 +44,7 @@ def address_from_private_key(private_key, network_version=None):
network_version = network['version']

private_key = PrivateKey.from_hex(private_key)
ripemd160 = hashlib.new('ripemd160', unhexlify(private_key.public_key))
ripemd160 = RIPEMD160.new(data=unhexlify(private_key.public_key))
seed = write_bit8(network_version) + ripemd160.digest()
return b58encode_check(seed).decode()

Expand Down
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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
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
exceptiongroup==1.2.1
flake8==7.1.0
Expand All @@ -20,15 +22,19 @@ mccabe==0.7.0
mdurl==0.1.2
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
six==1.16.0
soupsieve==2.5
toml==0.10.2
tomli==2.0.1
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
requires = [
'base58',
'binary-helpers',
'coincurve'
'coincurve',
'pycryptodomex',
]

tests_require = [
Expand Down
3 changes: 0 additions & 3 deletions tests/identity/test_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@
)

def test_address_from_public_key(identity):
pytest.skip(reason="ripemd160 is a legacy hash function")
address = address_from_public_key(identity['data']['public_key'])
assert address == identity['data']['address']


def test_address_from_private_key(identity):
pytest.skip(reason="ripemd160 is a legacy hash function")
address = address_from_private_key(identity['data']['private_key'])
assert address == identity['data']['address']


def test_address_from_passphrase(identity):
pytest.skip(reason="ripemd160 is a legacy hash function")
address = address_from_passphrase(identity['passphrase'])
assert address == identity['data']['address']

Expand Down

0 comments on commit fa6560a

Please sign in to comment.