From 986b4586eaa87cb9906d02dccb7ad2a7e53d0390 Mon Sep 17 00:00:00 2001 From: nkitlabs Date: Mon, 5 Feb 2024 14:18:23 +0700 Subject: [PATCH] use Crypto.Hash instead of hashlib --- pyband/wallet/public_key.py | 3 ++- tests/cosmos_app_test.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pyband/wallet/public_key.py b/pyband/wallet/public_key.py index a3d73d0..096a7aa 100644 --- a/pyband/wallet/public_key.py +++ b/pyband/wallet/public_key.py @@ -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 @@ -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. diff --git a/tests/cosmos_app_test.py b/tests/cosmos_app_test.py index 327af34..ec4c9c3 100644 --- a/tests/cosmos_app_test.py +++ b/tests/cosmos_app_test.py @@ -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 @@ -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")