So I wrote a vanity address generator in c# with the NBitcoin lib. When I use the private key used to generate the address and input it in Mycelium it outputs a different address. This does not occur when working with legacy addresses, so I'm guessing I need something more than just a private key in order to generate a segwit address. Was it a redeem script or something? How can I make sure I get the same address in a wallet when I input the privkey?
var bitcoinPrivateKey = new BitcoinSecret("cPof7e5g6xfgB6AZrc6XVTVwA4efLJurh9kVxa6FRChbr8Jyqaon", Network.TestNet); var legacy_address = bitcoinPrivateKey.GetAddress(ScriptPubKeyType.Legacy); var segwitp2sh_address = bitcoinPrivateKey.GetAddress(ScriptPubKeyType.SegwitP2SH); var nativesegwit_address = bitcoinPrivateKey.GetAddress(ScriptPubKeyType.Segwit); Console.WriteLine("Private Key :" + bitcoinPrivateKey); Console.WriteLine("Legacy Address :" + legacy_address); Console.WriteLine("Segwit-P2SH Address :" + segwitp2sh_address); Console.WriteLine("Bech32 Address :" + nativesegwit_address);
Mycelium testnet bitcoin wallet:
Thanks everyone for the explanation. So yes, only a private key can be enough to generate a bech32 address. The issue in my case seems to be that I was using
var addr = key1.ScriptPubKey.GetWitScriptAddress(net);
Key key1 = new Key();
var secret = new BitcoinSecret(key1, net);
var addr = secret.GetAddress(ScriptPubKeyType.Segwit);
Now the output addresses of mycelium and my program match.