Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using NBitcoin, how can I generate Electrum old type HD wallet from private key/seed? #1241

Open
monwazchh opened this issue Dec 6, 2024 · 2 comments

Comments

@monwazchh
Copy link

Hello, I have been using NBitcoin for my projects for a long time and I am very satisfied.

However, I am currently facing a problem.
I am creating an “old” type HD wallet in the Electrum application from a private key or a seed (actually both are the same).
I want to do the same in C#. I tried this with NBitcoin with many different methods but unfortunately I couldn't succeed.
I wonder, can I create Electrum Old HD wallet using NBitcoin?

Note I have tried many classes such as Key Path, Mnemonic, ExtKey but unfortunately I could not generate the same addresses.

Honestly, I have studied Electrum's source code as much as I can understand. The only thing I noticed is that the private key/seed is encrypted with sha256 an extra 100k times and then addresses are generated. I tried this in C# but again it generates different addresses.

Can anyone help me with this?

@monwazchh monwazchh changed the title Using NBitcoin, how can I generate Electrum old type HD wallet from private key? Using NBitcoin, how can I generate Electrum old type HD wallet from private key/seed? Dec 6, 2024
@underctrl
Copy link

I've been trying to do this with NBitcoin as well, and I've resorted to just using this library instead, specifically when I need Electrum-compatible addresses:

https://github.com/Autarkysoft/Denovo

Here's the code I'm using, and I've verified that the addresses generated in both cases are the same addresses Electrum itself produces when I use these same seed phrases in it:

// none of these seed phrases have ever been used (no funds)

// SegWit
var seedPhrase = "clock unusual snake renew security believe arrow give wish snack turn height";
var mnemonic = new ElectrumMnemonic(seedPhrase);

var addresses = mnemonic.GetPublicKeys(
    new BIP0032Path("m/0'/0"),
    5
).Select(c => Address.GetP2wpkh(c));

// Legacy
var legacySeedPhrase = "banner local erosion regular swim learn region trash apart gorilla faculty shop";
var legacyMnemonic = new ElectrumMnemonic(legacySeedPhrase);

var legacyAddresses = legacyMnemonic.GetPublicKeys(
    new BIP0032Path("m/0"),
    5
).Select(c => Address.GetP2pkh(c));

Hope this helps.

@monwazchh
Copy link
Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@underctrl @monwazchh and others