2

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.

0

2 Answers 2

2

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.

0
0

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.

1
  • 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?
    – hakusaro
    Feb 12, 2018 at 22:40

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