Last active
March 21, 2021 16:59
-
-
Save emadflash/ea9c1347513f4f90447ac39147457ec5 to your computer and use it in GitHub Desktop.
Generate ethereum private key, public key and address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os | |
import random | |
import sha3, ecdsa | |
def get_key_w_add(seed=1337): | |
# generate private key | |
random.seed(seed); | |
_private_key = bytes([random.randint(0,255) for i in range(32)]) | |
private_key = sha3.keccak_256(_private_key).digest() | |
# public key <- private key | |
sk = ecdsa.SigningKey.from_string(private_key, curve=ecdsa.SECP256k1) # use SECP256k1 | |
vk = sk.get_verifying_key() | |
public_key = vk.to_string() | |
# addresss <- public key | |
_address = sha3.keccak_256(public_key).digest() | |
address = '0x' + (_address[-20:]).hex() | |
return private_key.hex(), public_key.hex(), address | |
if __name__ == '__main__': | |
priv_key, publ_key, eth_add = get_key_w_add() | |
print("Private key: ", priv_key) | |
print("Public key: ", publ_key) | |
print("Address: ", eth_add) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment