Hi there, from my understanding, generating an address will also generating private key assosiated to that address simultaniously
in a way you are correct but it is not a correct statement.
what happens is that when you request a new address your wallet generates a new private key first and then uses that key to derive your public key and then converts that public key to a desired address format that you want.
but, If I generate address using master public key in my server (xpub), where is the private key stored?
things work a little differently in BIP32. what we have here is two things:
- a master private key
- a master public key
the design here is unique and is in a way that you can use your master public key to derive the future public keys without needing the master private key. but this master public key is derived from that master private key so in a way it is still the same as above.
meaning you first created a private key then used that to get the public keys.
so your private key(s) is that master key (xprv)
so now I have electrum wallet, I use my wallet's xpub to generate address in my website.
but how can I sign transaction? using my master private key? (xprv)
you have to have another wallet that contains the master private key so that it can generate the private key corresponding to that address you are spending from so that you can sign a transaction.