0

I have been looking for an easy way to get the public key of my ethereum wallet

From reading a bit on how ethereum wallets work, I understand that a Wallet Address in ethereum is actually derived from the public key (an address is the last 20 bytes of a keccak-256 hash of the public key), but it is in fact NOT the public key itself

therefore my question,

"What is the simplest way to get my ethereum public key, provided i know my private key"

any help is greatly appreciated !

0

1 Answer 1

0

Figured it out !

thanks to Timur's article and also the ecies and ecdsa libraries

here's the python code sample

from ecies.utils import generate_eth_key, generate_key
from ecies import encrypt, decrypt
import codecs
import ecdsa

private_key = 'abcd1234' # your ethereum private key

pr_key_bytes = codecs.decode(private_key,'hex')

pb_key = ecdsa.SigningKey.from_string(pr_key_bytes,curve=ecdsa.SECP256k1).verifying_key

pb_key_bytes = pb_key.to_string()

privK = private_key

pubK = pb_key_bytes.hex()

# to prove that we found the correct public key, which corresponds to the aforesaid private key

data = b'abc' # convert the data to byte form, since the encrypt function only accepts byte encoded data as a parameter

enc = encrypt(pubK, data)

decrypt(privK, enc) # decrypting with private key should give b'abc' as answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.