Skip to content

Commit

Permalink
moved from pysha to hashlib (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
idan-orbs authored Oct 1, 2023
1 parent 3dd307a commit 2e1fc4d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
13 changes: 7 additions & 6 deletions setup/generate_wallet.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/usr/bin/python3
import argparse
import json
import hashlib
from secrets import token_bytes

from coincurve import PublicKey
from eth_keys import keys
from eth_utils import to_checksum_address
from sha3 import keccak_256


def store_keys(dest_path, addr, private_key):
Expand All @@ -20,9 +19,9 @@ def store_keys(dest_path, addr, private_key):

def generate_keys(dest_path):
# https://github.com/pcaversaccio/ethereum-key-generation-python
private_key = keccak_256(token_bytes(32)).digest()
private_key = hashlib.sha3_256(token_bytes(32)).digest()
public_key = PublicKey.from_valid_secret(private_key).format(compressed=False)[1:]
addr = keccak_256(public_key).digest()[-20:].hex()
addr = hashlib.sha3_256(public_key).digest()[-20:].hex()

store_keys(dest_path, to_checksum_address(addr), private_key.hex())

Expand All @@ -32,8 +31,10 @@ def import_key(dest_path, private_key):
if isinstance(private_key, str):
private_key = bytes.fromhex(private_key[2:] if private_key.startswith('0x') else private_key)

private_key = keys.PrivateKey(private_key)
store_keys(dest_path, private_key.public_key.to_checksum_address(), str(private_key))
public_key = PublicKey.from_valid_secret(private_key).format(compressed=False)[1:]
addr = hashlib.sha3_256(public_key).digest()[-20:].hex()

store_keys(dest_path, to_checksum_address(addr), private_key.hex())


if __name__ == "__main__":
Expand Down
3 changes: 1 addition & 2 deletions setup/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pysha3==1.0.2
pycryptodome==3.19.0
coincurve==18.0.0
watchdog==2.3.1
eth-keys==0.4.0
eth-utils==2.2.0
python-dotenv==1.0.0

0 comments on commit 2e1fc4d

Please sign in to comment.