From bb49714e51ba26743158abe503acac0bf992acc5 Mon Sep 17 00:00:00 2001 From: Oleksandr Prudnikov Date: Tue, 30 Apr 2024 14:38:53 +0100 Subject: [PATCH] EVM networks wallet generation logic added --- CHANGELOG.md | 2 ++ aiotx/clients/_evm_base_client.py | 21 +++++++++++++++++++-- setup.py | 2 ++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a70b14b..a81e733 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [0.0.10] +- EVM networks wallet generation logic added ## [0.0.5] - empty (auto pypi testing) diff --git a/aiotx/clients/_evm_base_client.py b/aiotx/clients/_evm_base_client.py index 4a4ef02..d22674f 100644 --- a/aiotx/clients/_evm_base_client.py +++ b/aiotx/clients/_evm_base_client.py @@ -1,10 +1,27 @@ -class AioTxEVMClient: +import secrets +from eth_utils import keccak, encode_hex, to_checksum_address +from eth_keys import keys +class AioTxEVMClient: def __init__(self, node_url): self.node_url = node_url def generate_address(self): - pass + private_key_bytes = secrets.token_bytes(32) + private_key = keys.PrivateKey(private_key_bytes) + public_key_bytes = private_key.public_key.to_bytes() + keccak_digest = keccak(public_key_bytes)[12:] + address = encode_hex(keccak_digest[-20:]) + private_key_hex = private_key.to_hex() + return private_key_hex, to_checksum_address(address) + + + def get_address_from_private_key(self, private_key_hex: str): + private_key = keys.PrivateKey(bytes.fromhex(private_key_hex[2:])) + public_key_bytes = private_key.public_key.to_bytes() + keccak_digest = keccak(public_key_bytes)[12:] + address = encode_hex(keccak_digest[-20:]) + return to_checksum_address(address) def get_balance(self, address): pass diff --git a/setup.py b/setup.py index 9442fdf..a576252 100644 --- a/setup.py +++ b/setup.py @@ -43,6 +43,8 @@ ], install_requires=[ "aiohttp", + "eth_keys", + "eth_utils" ], extras_require={ "test": extras_test,