Skip to content

Commit

Permalink
use Crypto.Hash instead of hashlib
Browse files Browse the repository at this point in the history
  • Loading branch information
nkitlabs committed Feb 5, 2024
1 parent f18688a commit 986b458
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pyband/wallet/public_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Optional

from bech32 import bech32_decode, convertbits, bech32_encode
from Crypto.Hash import RIPEMD160
from ecdsa.curves import SECP256k1
from ecdsa.keys import VerifyingKey, BadSignatureError

Expand Down Expand Up @@ -153,7 +154,7 @@ def to_address(self) -> Address:
"""

hash = hashlib.new("sha256", self.verify_key.to_string("compressed")).digest()
return Address(hashlib.new("ripemd160", hash).digest())
return Address(RIPEMD160.new(hash).digest())

def verify(self, msg: bytes, sig: bytes) -> bool:
"""Verify a signature made from the given message.
Expand Down
3 changes: 2 additions & 1 deletion tests/cosmos_app_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest
from bech32 import bech32_encode, convertbits
from bip32 import BIP32
from Crypto.Hash import RIPEMD160
from ecdsa.curves import SECP256k1
from ecdsa.der import encode_sequence, encode_integer, remove_sequence, remove_integer
from ecdsa.keys import SigningKey
Expand Down Expand Up @@ -88,7 +89,7 @@ def _ins_get_addr_secp256k1(self, p1: int, data: bytes):
)

verifying_key = signing_key.get_verifying_key()
addr = hashlib.new("ripemd160", hashlib.new("sha256", verifying_key.to_string("compressed")).digest()).digest()
addr = RIPEMD160.new(hashlib.new("sha256", verifying_key.to_string("compressed")).digest()).digest()
five_bit_r = convertbits(addr, 8, 5)
return verifying_key.to_string("compressed") + bytes(bech32_encode("band", five_bit_r), "utf-8")

Expand Down

0 comments on commit 986b458

Please sign in to comment.