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
- 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.