Skip to content

Commit

Permalink
OpenSSL <3.0 ripemd160 bugfix (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntwrkrcrt authored Aug 3, 2024
1 parent ea07705 commit 4ffd9ec
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ mnemonic==0.20
protobuf==4.22.1
safe-pysha3==1.0.3;python_version>='3.9'
pysha3==1.0.2;python_version<'3.9'
pycryptodome==3.20.0
5 changes: 4 additions & 1 deletion src/mospy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from mnemonic import Mnemonic
from sha3 import keccak_256
import binascii
from Crypto.Hash.RIPEMD160 import new as ripemd160_new


def seed_to_private_key(seed, derivation_path, passphrase: str = ""):
Expand All @@ -26,7 +27,9 @@ def privkey_to_pubkey(privkey: bytes, raw: bool = False) -> bytes:

def pubkey_to_address(pubkey: bytes, *, hrp: str) -> str:
s = hashlib.new("sha256", pubkey).digest()
r = hashlib.new("ripemd160", s).digest()
ripemd160 = ripemd160_new()
ripemd160.update(s)
r = ripemd160.digest()
five_bit_r = bech32.convertbits(r, 8, 5)
assert five_bit_r is not None, "Unsuccessful bech32.convertbits call"
return bech32.bech32_encode(hrp, five_bit_r)
Expand Down

0 comments on commit 4ffd9ec

Please sign in to comment.