How to generate addresses from an ElectrumMnemonic? #11
-
Hello. I need to 1) test seed phrases to see if they are an Electrum-supported seed phrase or not, and 2) if a seed phrase is a valid Electrum mnemonic, generate addresses for it... I've been playing around with this library today, trying to guess how I might achieve these two goals, and I've solved the first one... I'm doing this below, and I see that var seedPhrase = "clock unusual snake renew security believe arrow give wish snack turn height";
var seedPhraseInvalid = "clock unusual snake renew security believe arrow give wish snack turn fit";
var eMnemonic1 = new ElectrumMnemonic(seedPhrase);
var eMnemonic2 = new ElectrumMnemonic(seedPhraseInvalid); // throws an exception However, I can't seem to figure out how to generate addresses for the valid seed phrase above... I generated that seed phrase with Electrum itself, and these are the first three addresses it displays in its UI:
...however, when I try the following (which I've cobbled together by trial and error), I get different addresses (and I've tried various permutations of it, including using eMnemonic1.GetPublicKeys(
BIP0032Path.CreateBip44(
BIP0032Path.CoinType.Bitcoin,
0,
false
),
3
).Select(c => Address.GetP2wpkh(c)) That specific code gives me the following three strings (and of course other permutations result in a different set of three strings), which do all look like valid addresses, but they just don't match what Electrum itself shows...
For what it's worth, Electrum's UI (under the Wallet > Information menu) says it's using Additionally, I'd like to be able to generate the older "legacy" Electrum addresses as well, but I'm still learning about all this, and I'm still not even sure what the difference is between the older and newer versions, etc... Any help would be much appreciated. Tagging @Coding-Enthusiast just in case you don't get a notification of this question otherwise... p.s. And I'm using the version of this library from NuGet, which looks like it's a year old...? Not sure if that makes a difference, but it's version 0.26.0 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Electrum doesn't use BIP44 path (ie.
Denovo/Src/Tests/Bitcoin/ImprovementProposals/BIP0032PathTests.cs Lines 32 to 50 in 419207e
|
Beta Was this translation helpful? Give feedback.
Electrum doesn't use BIP44 path (ie.
m/44'/0'/0
) to derive its child keys; instead it uses its own derivation path that depends on the mnemonic type which for a SegWit type ism/0'/0
.h
is another way of representing hardened indexes in the derivation path. It is the same as'
. You can pass the derivation path as a string toBIP0032Path
constructor with eitherh
,H
or'
and it will parse it. Examples can be found among tests.Denovo/Src/Tests/Bitcoin/ImprovementProposals/BIP0032PathTests.cs
Lines 32 to 50 in 419207e