Bitcoin Forum
June 21, 2024, 12:25:16 PM *
News: Voting for pizza day contest
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: derivation path Electrum  (Read 136 times)
Sanka555 (OP)
Member
**
Offline Offline

Activity: 96
Merit: 36


View Profile
September 19, 2021, 04:50:07 PM
 #1

Please tell me which derivation path does electrum use when creating a wallet from the "type of seed phrase-segwit" (12 words)

bitcoin
jackg
Copper Member
Legendary
*
Offline Offline

Activity: 2856
Merit: 3071


https://bit.ly/387FXHi lightning theory


View Profile
September 19, 2021, 05:10:22 PM
 #2

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.
Sanka555 (OP)
Member
**
Offline Offline

Activity: 96
Merit: 36


View Profile
September 19, 2021, 05:16:10 PM
 #3

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 Roll Eyes
ranochigo
Legendary
*
Offline Offline

Activity: 2982
Merit: 4193



View Profile
September 19, 2021, 05:46:40 PM
 #4

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.

█████████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████
█████████████████████████
.
BC.GAME
▄▄░░░▄▀▀▄████████
▄▄▄
██████████████
█████░░▄▄▄▄████████
▄▄▄▄▄▄▄▄▄██▄██████▄▄▄▄████
▄███▄█▄▄██████████▄████▄████
███████████████████████████▀███
▀████▄██▄██▄░░░░▄████████████
▀▀▀█████▄▄▄███████████▀██
███████████████████▀██
███████████████████▄██
▄███████████████████▄██
█████████████████████▀██
██████████████████████▄
.
..CASINO....SPORTS....RACING..
█░░░░░░█░░░░░░█
▀███▀░░▀███▀░░▀███▀
▀░▀░░░░▀░▀░░░░▀░▀
░░░░░░░░░░░░
▀██████████
░░░░░███░░░░
░░█░░░███▄█░░░
░░██▌░░███░▀░░██▌
░█░██░░███░░░█░██
░█▀▀▀█▌░███░░█▀▀▀█▌
▄█▄░░░██▄███▄█▄░░▄██▄
▄███▄
░░░░▀██▄▀


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
Sanka555 (OP)
Member
**
Offline Offline

Activity: 96
Merit: 36


View Profile
September 19, 2021, 06:05:16 PM
 #5

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?
o_e_l_e_o
In memoriam
Legendary
*
Offline Offline

Activity: 2268
Merit: 18588


View Profile
September 19, 2021, 07:14:29 PM
Merited by NotATether (3), Pmalek (2), BlackHatCoiner (2)
 #6

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'.
nc50lc
Legendary
*
Offline Offline

Activity: 2450
Merit: 5724


Self-proclaimed Genius


View Profile
September 20, 2021, 05:38:11 AM
Merited by pooya87 (2), ABCbits (2), Pmalek (2), BlackHatCoiner (2)
 #7

-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).
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

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
Sanka555 (OP)
Member
**
Offline Offline

Activity: 96
Merit: 36


View Profile
September 20, 2021, 10:34:20 AM
 #8

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.
nc50lc
Legendary
*
Offline Offline

Activity: 2450
Merit: 5724


Self-proclaimed Genius


View Profile
September 20, 2021, 12:11:44 PM
 #9

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

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
Sanka555 (OP)
Member
**
Offline Offline

Activity: 96
Merit: 36


View Profile
September 20, 2021, 03:55:58 PM
 #10

thank you very much   Grin it really works Grin
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!