|
1 | | -import eth_hash.auto |
| 1 | +import sha3 |
2 | 2 | import hashlib |
3 | 3 | import aiohttp |
4 | 4 | import json |
|
7 | 7 |
|
8 | 8 | from bech32 import bech32_encode, bech32_decode, convertbits |
9 | 9 | from bip32 import BIP32 |
10 | | -from Crypto.Hash import keccak |
11 | | -from Crypto.Hash.keccak import Keccak_Hash |
12 | 10 | from ecdsa import SigningKey, VerifyingKey, SECP256k1, BadSignatureError |
13 | 11 | from ecdsa.util import sigencode_string_canonize |
14 | 12 | from mnemonic import Mnemonic |
|
27 | 25 | DEFAULT_DERIVATION_PATH = "m/44'/60'/0'/0/0" |
28 | 26 |
|
29 | 27 |
|
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 | | - |
38 | 28 | class PrivateKey: |
39 | 29 | """ |
40 | 30 | Class for wrapping SigningKey that is used for signature creation and public key derivation. |
@@ -109,18 +99,8 @@ def sign(self, msg: bytes) -> bytes: |
109 | 99 |
|
110 | 100 | :return: a signature of this private key over the given message |
111 | 101 | """ |
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) |
123 | 102 |
|
| 103 | + return self.signing_key.sign_deterministic(msg, hashfunc=sha3.keccak_256, sigencode=sigencode_string_canonize) |
124 | 104 |
|
125 | 105 | class PublicKey: |
126 | 106 | """ |
@@ -194,7 +174,7 @@ def to_cons_bech32(self) -> str: |
194 | 174 | def to_address(self) -> "Address": |
195 | 175 | """Return address instance from this public key""" |
196 | 176 | pubkey = self.verify_key.to_string("uncompressed") |
197 | | - keccak_hash = keccak.new(digest_bits=256) |
| 177 | + keccak_hash = sha3.keccak_256() |
198 | 178 | keccak_hash.update(pubkey[1:]) |
199 | 179 | addr = keccak_hash.digest()[12:] |
200 | 180 | return Address(addr) |
|
0 commit comments