# How wallets and web3 find public key from private key? [duplicate]

How is it possible for wallets like MetaMask or libraries like web3js to find public key by only providing private key? AFAIK this is not possible generally in elliptic curve.

AFAIK this is not possible generally in elliptic curve.

In elliptic-curve cryptography, the public key is derived from the private key, not the other way round. The clue is in the name: the private key is the thing you need to keep secret (or share with something you are sure you can trust, like Metamask).

See this graphical representation of how Ethereum uses EC cryptography to create a public key (and subsequently an address) from a private key.

Here is some math behind it:

``````P = G ⋅ K
``````

Where:

• G - some basic point with two coordinates

``````Gx = 55066263022277343669578718895168534326250603453777594175500187360389116729240
Gy = 32670510020758816978083085130507043184471273380659243275938904335757337482424
G = (Gx, Gy)
``````

• K - private key

• P - public key

After multiplication you will have two coordinates of public key which later should be aligned to 32 byte sets and concatenated.

There is example of implementation of this algorithm in `ethereum/py_ecc`. Have a look.

• Can you explain your magic numbers for Gx and Gy? Or, if you know fully how ECDSA works with secp256k1, can you update your answer to be fully complete (i.e., add the curve parameters) and add the Keccak256 hashing for the final address? Feb 12, 2018 at 22:40