Skip to content

Commit 72b2f8a

Browse files
author
abel
committed
Merge branch 'fix/remove_pysha3_dependency' of https://github.com/InjectiveLabs/sdk-python into fix/remove_pysha3_dependency
2 parents 7ddb66d + c89af2a commit 72b2f8a

File tree

1 file changed

+3
-23
lines changed

1 file changed

+3
-23
lines changed

pyinjective/wallet.py

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import eth_hash.auto
1+
import sha3
22
import hashlib
33
import aiohttp
44
import json
@@ -7,8 +7,6 @@
77

88
from bech32 import bech32_encode, bech32_decode, convertbits
99
from bip32 import BIP32
10-
from Crypto.Hash import keccak
11-
from Crypto.Hash.keccak import Keccak_Hash
1210
from ecdsa import SigningKey, VerifyingKey, SECP256k1, BadSignatureError
1311
from ecdsa.util import sigencode_string_canonize
1412
from mnemonic import Mnemonic
@@ -27,14 +25,6 @@
2725
DEFAULT_DERIVATION_PATH = "m/44'/60'/0'/0/0"
2826

2927

30-
class Keccak_Hash_With_Copy(Keccak_Hash):
31-
# We need to create a version of Keccak_Hash that responds to `copy`
32-
# This is a requirement from the ecdsa library
33-
34-
def copy(self):
35-
return self.new(data=self.digest())
36-
37-
3828
class PrivateKey:
3929
"""
4030
Class for wrapping SigningKey that is used for signature creation and public key derivation.
@@ -109,18 +99,8 @@ def sign(self, msg: bytes) -> bytes:
10999
110100
:return: a signature of this private key over the given message
111101
"""
112-
# return self.signing_key.sign_deterministic(msg, hashfunc=hashlib.sha256, sigencode=sigencode_string_canonize)
113-
# keccak_function = functools.partial(keccak.new, digest_bits=256)
114-
def keccak_creation(data=None):
115-
# Create a 256 bits keccak hash
116-
keccak_hash = Keccak_Hash_With_Copy(data=data, digest_bytes=32, update_after_digest=False)
117-
return keccak_hash
118-
119-
#return self.signing_key.sign_deterministic(msg, hashfunc=sha3.keccak_256, sigencode=sigencode_string_canonize)
120-
hash = eth_hash.auto.keccak
121-
digest = eth_hash.auto.keccak(msg)
122-
return self.signing_key.sign_digest_deterministic(digest, hashfunc=hash, sigencode=sigencode_string_canonize)
123102

103+
return self.signing_key.sign_deterministic(msg, hashfunc=sha3.keccak_256, sigencode=sigencode_string_canonize)
124104

125105
class PublicKey:
126106
"""
@@ -194,7 +174,7 @@ def to_cons_bech32(self) -> str:
194174
def to_address(self) -> "Address":
195175
"""Return address instance from this public key"""
196176
pubkey = self.verify_key.to_string("uncompressed")
197-
keccak_hash = keccak.new(digest_bits=256)
177+
keccak_hash = sha3.keccak_256()
198178
keccak_hash.update(pubkey[1:])
199179
addr = keccak_hash.digest()[12:]
200180
return Address(addr)

0 commit comments

Comments
 (0)