Bitcoin Forum

Bitcoin => Electrum => Topic started by: Sanka555 on September 19, 2021, 04:50:07 PM



Title: derivation path Electrum
Post by: Sanka555 on September 19, 2021, 04:50:07 PM
Please tell me which derivation path does electrum use when creating a wallet from the "type of seed phrase-segwit" (12 words)

bitcoin


Title: Re: derivation path Electrum
Post by: jackg on September 19, 2021, 05:10:22 PM
I'm not sure it's possible to reproduce electrum wallets out of electrum's software (unless using it for recovery).

If you want to use another wallet with your electrum mnemonic, you might be better off importing the master private key into the other wallet software.


Title: Re: derivation path Electrum
Post by: Sanka555 on September 19, 2021, 05:16:10 PM
I am using Java.
for example, for seed bip39 in the electrum, the segwit is obtained along the path m/84/0/0
for seed-segwit there should be an equally simple answer

 (44 .... and 49 .... 84...) do not fit ::)


Title: Re: derivation path Electrum
Post by: ranochigo on September 19, 2021, 05:46:40 PM
The derivation path is m/0.

Electrum seeds are not compatible with BIP39. You have to generate the master key differently as you would from a normal BIP39 seed.


Title: Re: derivation path Electrum
Post by: Sanka555 on September 19, 2021, 06:05:16 PM
The derivation path is m/0.

Electrum seeds are not compatible with BIP39. You have to generate the master key differently as you would from a normal BIP39 seed.


thanks a lot. Maybe you know how to do it in Java in this case?


Title: Re: derivation path Electrum
Post by: o_e_l_e_o on September 19, 2021, 07:14:29 PM
for example, for seed bip39 in the electrum, the segwit is obtained along the path m/84/0/0
Correction: m/84'/0'/0'

The ' symbols are important. They signal that that level of the derivation path uses hardened derivation instead of non-hardened derivation. If you miss any one of them out, you will derive completely different private keys and addresses.

The derivation path is m/0.
For segwit in Electrum, it is m/0'.


Title: Re: derivation path Electrum
Post by: nc50lc on September 20, 2021, 05:38:11 AM
-snip- Maybe you know how to do it in Java in this case?
Try to incorporate Electrum's derivation path to the code that you're probably using (This code?: /index.php?topic=5360581.msg57965406#msg57965406 (https://bitcointalk.org/index.php?topic=5360581.msg57965406#msg57965406)).
I'm not a Java programmer but based from what I understand, these few edits should derive the correct keys/addresses of Electrum's P2WPKH:

From:
How can I integrate m / 84 '/ 0' / 0 '/ 0/0 into my code? I just need to get the first 5 addresses. I looked at your program, but there is a whole class forming a complex configuration. Too difficult for a beginner. How can I just hardcode the derivation path into my method?
Code:
-snip-
        DeterministicKey deterministicKey = createMasterPrivateKey(seed, createHmacSha512Digest());
        deterministicKey = HDKeyDerivation.deriveChildKey(deterministicKey, new ChildNumber(84, true));
        deterministicKey = HDKeyDerivation.deriveChildKey(deterministicKey, new ChildNumber(0, true));
        deterministicKey = HDKeyDerivation.deriveChildKey(deterministicKey, new ChildNumber(0, true));
        deterministicKey = HDKeyDerivation.deriveChildKey(deterministicKey, new ChildNumber(0, false));
        for (int i = 0; i <= 5; i++) {
            System.out.println(Address.fromKey(MainNetParams.get(), HDKeyDerivation.deriveChildKey(deterministicKey, new ChildNumber(i, false)), Script.ScriptType.P2WPKH));
        }
-snip-
Into:
Code:
-snip-
        DeterministicKey deterministicKey = createMasterPrivateKey(seed, createHmacSha512Digest());
        deterministicKey = HDKeyDerivation.deriveChildKey(deterministicKey, new ChildNumber(0, true));
        deterministicKey = HDKeyDerivation.deriveChildKey(deterministicKey, new ChildNumber(0, false));
        for (int i = 0; i <= 5; i++) {
            System.out.println(Address.fromKey(MainNetParams.get(), HDKeyDerivation.deriveChildKey(deterministicKey, new ChildNumber(i, false)), Script.ScriptType.P2WPKH));
        }
-snip-
The path in the code is m/0'/0 (from m/84'/0'/0'/0), the extra child key is for the 'external chain' (receiving addresses), change to '1' for internal (change addresses).

But then again, I'm not a Java programmer so the part that I've edited could be wrong   :-\


For the derivation path,
You can actually directly see it in the wallet menu (Wallet->Information):
Refer to these images:
P2WPKH (Native Segwit): m/0'
|
P2PKH (Legacy): m
https://i.imgur.com/JTvtGtK.pnghttps://i.imgur.com/8NbqO0O.png


Title: Re: derivation path Electrum
Post by: Sanka555 on September 20, 2021, 10:34:20 AM
Thanks for your participation. I've already figured out the path. Everything is as you wrote. The problem is apparently in the line.
Quote
DeterministicKey deterministicKey = createMasterPrivateKey(seed, createHmacSha512Digest());

The master key must be generated differently. if the seed is used not bip39 but  "seed-segwit".

The electrum documentation says about this :
Quote
Following BIP39, 2048 iterations of key stretching are added for the generation of the master private key. In terms of hashes, this is equivalent to adding an extra 11 bits of security to the seed (2048=2^11).
https://electrum.readthedocs.io/en/latest/seedphrase.html

But it didn't help me much. If someone knows how to do this, I would be very grateful.


Title: Re: derivation path Electrum
Post by: nc50lc on September 20, 2021, 12:11:44 PM
The master key must be generated differently. if the seed is used not bip39 but  "seed-segwit".
-snip-
I hadn't noticed it but I think you also need to edit another part of PawGo's code to work with Electrum:

From:
Code:
-snip-
    final static byte[] SALT = "mnemonic".getBytes(StandardCharsets.UTF_8);
-snip-
Into:
Code:
-snip-
    final static byte[] SALT = "electrum".getBytes(StandardCharsets.UTF_8);
-snip-

https://github.com/spesmilo/electrum/blob/master/electrum/mnemonic.py#L164 (https://github.com/spesmilo/electrum/blob/master/electrum/mnemonic.py#L164)


Title: Re: derivation path Electrum
Post by: Sanka555 on September 20, 2021, 03:55:58 PM
thank you very much   ;D it really works ;D