Author

Topic: derivation path Electrum (Read 151 times)

member
Activity: 96
Merit: 36
September 20, 2021, 10:55:58 AM
#10
thank you very much   Grin it really works Grin
legendary
Activity: 2618
Merit: 6452
Self-proclaimed Genius
September 20, 2021, 07:11:44 AM
#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
member
Activity: 96
Merit: 36
September 20, 2021, 05: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.
legendary
Activity: 2618
Merit: 6452
Self-proclaimed Genius
September 20, 2021, 12:38:11 AM
#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'
legendary
Activity: 2268
Merit: 18771
September 19, 2021, 02:14:29 PM
#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'.
member
Activity: 96
Merit: 36
September 19, 2021, 01: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?
legendary
Activity: 3038
Merit: 4418
Crypto Swap Exchange
September 19, 2021, 12: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.
member
Activity: 96
Merit: 36
September 19, 2021, 12: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
copper member
Activity: 2856
Merit: 3071
https://bit.ly/387FXHi lightning theory
September 19, 2021, 12: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.
member
Activity: 96
Merit: 36
September 19, 2021, 11:50:07 AM
#1
Please tell me which derivation path does electrum use when creating a wallet from the "type of seed phrase-segwit" (12 words)

bitcoin
Jump to:
© 2020, Bitcointalksearch.org