21sats (OP)
Newbie
Offline
Activity: 8
Merit: 10
|
Hello, I've been playing around with Ian Colemans BIP39 tool trying to generate the same associated p2sh-segwit (p2wpkh-p2sh) addresses from a 12 word seed phrase with it that Electrum generated from said seed. My problem is that I just can't get it to work properly, the addresses generated by Ians tool do not match the Electrum derived addresses: https://i.imgur.com/w68rD3d.png https://i.imgur.com/0Wb7Isr.pngWhat I've done to get to this point so far... As Electrum dosen't generate standard seed phrases (12th word isn't a cheksum), to get addresses generated at all, I needed to edit the source code of Ians tool following the Instructions from here: https://bitcointalk.org/index.php?topic=2373020.msg24316954#msg24316954Used the 2017 version of the tool as I don't understand coding at all and the latest release didn't have the same code so I did not know what to replace. Replaced the code in the jsbip39.js file of the 2017 ( 0.2.8 ) release and the tool let me put in the seed without giving me an error: https://i.imgur.com/yINtzxz.pngAddresses didn't match the Electrum derived addresses so I tried with the latest version. Replaced the jsbip39.js file from the latest release with the edited one from 2017 so I was able to generate addresses in the latest version too: https://i.imgur.com/J5vREGP.pngAddresses do match the ones from the older version but not the ones from Electrum. If anyone knows what I am doing wrong or is just generally interested to find out how it would work too, I'd appreciate any solutions or ideas regarding the topic Thanks for reading Link to the online tool: https://iancoleman.io/bip39/Link to the latest source code: https://github.com/iancoleman/bip39/archive/master.zipLink to the 2017 version: https://github.com/iancoleman/bip39/archive/0.2.8.zip
|
|
|
|
|
21sats (OP)
Newbie
Offline
Activity: 8
Merit: 10
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 07, 2020, 02:09:01 PM |
|
I'm aware of the steps to generate p2sh-segwit with Electrum (see second picture). I'll try to rephrase my question/explain what I am trying: I've Generated p2sh-segwit wallet with Electrum. Got a Seed, got addresses. Now I want Ians tool to show me the same addresses Electrum dervied from that seed. [Why am I trying to do this? If the tool is able to derive the correct addresses (Like it normaly does with other address types and the correct settings) I am able to automatically bruteforce the 1-2 missing/wrong written words from a slightly incorrect remembered 12 word seed. But to do this I first need to make sure that Ians Tool and Electrum are deriving the same addresses to a correct seed (the one I created with Electrum just for testing purposes) or the brute force won't work. The address derivation from seed works well with other seed / address types, but I haven't figured out the settings/code changes to make it work with p2sh-segwit addresses.]
|
|
|
|
|
21sats (OP)
Newbie
Offline
Activity: 8
Merit: 10
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 07, 2020, 02:34:09 PM |
|
Quoting for images.
Thanks! ![Smiley](https://bitcointalk.org/Smileys/default/smiley.gif)
|
|
|
|
hosseinimr93
Legendary
Offline
Activity: 2492
Merit: 5543
|
You can easily have a seed phrase generating same p2wpkh-p2sh addresses in Electrum and iancoleman without any need to change the source code. (Maybe I am missing something?) Go to iancoleman. Select BIP49. ![](https://ip.bitcointalk.org/?u=https%3A%2F%2Fi.imgur.com%2Fq09RZiG.jpg&t=665&c=YWVQHAhOPzh74g) Generate a seed. iancoleman will give you some p2wpkh-p2sh addresses. Then go to Electrum. Create a new wallet. Select "Standard Wallet" and then "I already have a seed". Enter the seed phrase generated by iancoleman. Don't forget to click on "options" and check "BIP39". Click on "next" and select "p2wpkh-p2sh" as the "script type". Electrum will give you same addresses.
|
|
|
|
DireWolfM14
Copper Member
Legendary
Offline
Activity: 2254
Merit: 4283
Join the world-leading crypto sportsbook NOW!
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 07, 2020, 03:27:36 PM Last edit: June 07, 2020, 07:55:50 PM by DireWolfM14 |
|
From what I've learned about Electrum, it uses it's own standard to generate seed phrases. Although it may be based on Bip39, it's not 100% compatible with Bip39. I'm not the right guy to divulge the technical details, but I believe Electrum includes a checksum that helps the software determine if the seed is for a legacy wallet, or a native segwit wallet.
The only way I know of to generate p2sh addresses using an Electrum-generated seed is to trick the software into believing it's a Bip39 seed. The more common method for generating p2sh addresses is by using an actual Bip39 seed, like one that was generated by Ian Coleman's tool or a hardware wallet.
|
|
|
|
21sats (OP)
Newbie
Offline
Activity: 8
Merit: 10
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 07, 2020, 03:41:11 PM |
|
You can easily have a seed phrase generating same p2wpkh-p2sh addresses in Electrum and iancoleman without any need to change the source code. (Maybe I am missing something?) Go to iancoleman. Select BIP49. https://i.imgur.com/q09RZiG.jpgGenerate a seed. iancoleman will give you some p2wpkh-p2sh addresses. Then go to Electrum. Create a new wallet. Select "Standard Wallet" and then "I already have a seed". Enter the seed phrase generated by iancoleman. Don't forget to click on "options" and check "BIP39". Click on "next" and select "p2wpkh-p2sh" as the "script type". Electrum will give you same addresses. Yep in this direction it's working properly for me too, Seed generated by Iancoleman shows same addresses when entered in Electrum. But a seed generated by Electrum (non standard mnemonic) entered in iancoleman dosen't show the same addresses. The source code edit is needed because the tool will give "Invalid mnemonic" error if we try to put in the Electrum generated seed.
|
|
|
|
21sats (OP)
Newbie
Offline
Activity: 8
Merit: 10
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 07, 2020, 03:58:45 PM |
|
From what I've learned about Electrum, it uses it's own standard to generate seed phrases. Although it may be based on Bip39, it's not 100% compatible with Bip39. I'm not the right guy to divulge the technical details, but I believe Electrum includes a checksum that helps the software determine if the seed is for a legacy wallet, or a native segwit wallet.
The only way I know of to generated p2sh addresses using an Electrum generated seed is to trick the software into believing it's a Bip39 seed. The more common method for generating p2sh addresses is by using an actual Bip39 seed, like one that was generated by Ian Coleman's tool or a hardware wallet.
Meaning as the IanColeman tool views every seed put into it as a 100% standard BIP39 seed there is no way it will derive the correct addresses from the Electrum seed as it gives wrong information due to its different structure? Edit: Is there a way to show the exact derivation path to a specific address in the Electrum wallet? I know I chose m/49'/0'/0' when generating but im curious if it really ended up beeing this path. Tried wallet.keystore.derivation in the Electrum console but this didn't work.
|
|
|
|
DireWolfM14
Copper Member
Legendary
Offline
Activity: 2254
Merit: 4283
Join the world-leading crypto sportsbook NOW!
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 07, 2020, 05:53:49 PM |
|
Meaning as the IanColeman tool views every seed put into it as a 100% standard BIP39 seed there is no way it will derive the correct addresses from the Electrum seed as it gives wrong information due to its different structure? Correct. Again, I'm not a good technical resource, but as I understand it when Electrum creates a seed the order or selection of specific words creates a checksum for Electrum to use as an additional piece of information for address determination. Other wallets don't include that piece of code, it's specific to Electrum. Edit: Is there a way to show the exact derivation path to a specific address in the Electrum wallet? I know I chose m/49'/0'/0' when generating but im curious if it really ended up beeing this path. Tried wallet.keystore.derivation in the Electrum console but this didn't work.
Not that I know of. The information may exist in the wallet file but I don't know of any way to find that information through the GUI frontend. I'm not aware of any console command that will provide the information either. Another thing to keep in mind, I don't believe Electrum's seed generator will create a seed specific to Bip49 standard, only Bip44 (legacy) and Bip84 (native segwit.)
|
|
|
|
o_e_l_e_o
In memoriam
Legendary
Offline
Activity: 2268
Merit: 18696
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 07, 2020, 06:33:10 PM |
|
Can you clarify first of all how you created the Electrum wallet? Electrum will not allow you to generate a P2WPKH-P2SH wallet - you can only restore such a wallet. Further, you can not restore such a wallet from an Electrum generated seed phrase unless you force the seed through as an invalid BIP39 seed phrase. Are these the steps you took? Was the initial Electrum wallet you create legacy or segwit?
|
|
|
|
21sats (OP)
Newbie
Offline
Activity: 8
Merit: 10
|
Not that I know of. The information may exist in the wallet file but I don't know of any way to find that information through the GUI frontend. I'm not aware of any console command that will provide the information either. Another thing to keep in mind, I don't believe Electrum's seed generator will create a seed specific to Bip49 standard, only Bip44 (legacy) and Bip84 (native segwit.)
Can you clarify first of all how you created the Electrum wallet? Electrum will not allow you to generate a P2WPKH-P2SH wallet - you can only restore such a wallet. Further, you can not restore such a wallet from an Electrum generated seed phrase unless you force the seed through as an invalid BIP39 seed phrase. Are these the steps you took? Was the initial Electrum wallet you create legacy or segwit?
Initial Electrum wallet is segwit. I think I forced it through as an invalid BIP39 seed phrase cause the checksum=failed but I was still able to proceed. Those are the exact steps I took in Electrum: Chose a new wallet name, next. Standard wallet, next. Create a new seed, next. Segwit, next. Copied the generated seed. Aborted the process, restarted electrum. Chose a new wallet name, next. Standard wallet, next. I already have a seed, next. Pasted the seed, clicked options. Check marked BIP39 seed, ok, next. Chose p2sh-segwit(p2wpkh-p2sh), next. Chose Password, done.
|
|
|
|
o_e_l_e_o
In memoriam
Legendary
Offline
Activity: 2268
Merit: 18696
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 07, 2020, 08:17:07 PM |
|
Right. In that case, in the instructions that HCP laid out in the post you linked to ( https://bitcointalk.org/index.php?topic=2373020.msg24316954#msg24316954), you should ignore the second step of changing the word "mnemonic" to "electrum". Since you've done that already, change it back and reload your copy of iancoleman. Enter your Electrum seed, and then select "BIP49" under Derivation Path. The addresses should now match those that show up in your Electrum wallet.
|
|
|
|
DireWolfM14
Copper Member
Legendary
Offline
Activity: 2254
Merit: 4283
Join the world-leading crypto sportsbook NOW!
|
The method you used obviously works, but it's generally not recommended.
If you're going to use this method to store your funds there are some factors of which you should make note. Since you're relying on a specific piece of software to decipher the correct derivation path, it's a good idea to make sure you always have a verified version stored locally. You should also make backups of your wallet files and store them on another device. Another pitfall is if you do lose all your backups and have to restore the wallet from the seed phrase several years from now, are you going to remember the steps you took? You may want to include instructions for yourself and store them with the seed phrase, in case you forget.
If your goal is to have multiple desktop wallets, of different address types, that are all backed-up by one seed, you are probably better off starting with a Bip39 phrase. The advantage is you can always restore it with many desktop clients or hardware wallets, and they'll be able to determine the correct derivation path without all fuss. And of course, that includes Electrum.
|
|
|
|
21sats (OP)
Newbie
Offline
Activity: 8
Merit: 10
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 07, 2020, 08:50:18 PM |
|
Right. In that case, in the instructions that HCP laid out in the post you linked to ( https://bitcointalk.org/index.php?topic=2373020.msg24316954#msg24316954), you should ignore the second step of changing the word "mnemonic" to "electrum". Since you've done that already, change it back and reload your copy of iancoleman. Enter your Electrum seed, and then select "BIP49" under Derivation Path. The addresses should now match those that show up in your Electrum wallet. Wow, worked like a charm! Thanks for the help. High possibility that I won't get the explanation but why did I have to ignore the second step?
|
|
|
|
o_e_l_e_o
In memoriam
Legendary
Offline
Activity: 2268
Merit: 18696
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 07, 2020, 09:32:54 PM |
|
Short answer: Electrum seed phrases and BIP39 seed phrases differ in the way they handle passphrases. Since you are entering the seed phrase as a BIP39 phrase, you use the BIP39 method, which uses the word "mnemonic" rather than the word "electrum". Longer answer: When your seed phrase is used to generate your private keys, the first step is to pass it through a key stretching function called PBKDF2. The PBKDF2 function used has two input parameters. The first input parameter is your seed phrase. The second input parameter for BIP39 seeds is the word "mnemonic" concatenated with your passphrase. You can see this in lines 810 and 811 of the Electrum code here: https://github.com/spesmilo/electrum/blob/9d0bb295e6f55a2bff9f5b6770fa744c16af6e8a/electrum/keystore.py#L810. Conversely, when using Electrum seeds, instead of using the word "mnemonic", it instead uses the word "electrum" concatenated with your passphrase. See line 164 here: https://github.com/spesmilo/electrum/blob/a0b096dcb2292c2826f7beae173c529d335142f0/electrum/mnemonic.py#L164. Even although your seed was generated by Electrum, since we are using it as an (invalid) BIP39 seed we need to follow the BIP39 method. This will hold true even if you don't use a passphrase, as the word "mnemonic" will still be used as an input for PBKDF2, just without any additional characters attached.
I would echo DireWolfM14's warning above, though. This is a very non standard way to generate a wallet, and you could run in to serious problems down the line trying to recover it. If you want a P2WPKH-P2SH wallet in Electrum, then the best method is to generate a BIP39 phrase elsewhere and import it.
|
|
|
|
bartekjagoda
Jr. Member
Offline
Activity: 87
Merit: 5
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 08, 2020, 10:15:42 AM |
|
Short answer: Electrum seed phrases and BIP39 seed phrases differ in the way they handle passphrases. Since you are entering the seed phrase as a BIP39 phrase, you use the BIP39 method, which uses the word "mnemonic" rather than the word "electrum". Longer answer: When your seed phrase is used to generate your private keys, the first step is to pass it through a key stretching function called PBKDF2. The PBKDF2 function used has two input parameters. The first input parameter is your seed phrase. The second input parameter for BIP39 seeds is the word "mnemonic" concatenated with your passphrase. You can see this in lines 810 and 811 of the Electrum code here: https://github.com/spesmilo/electrum/blob/9d0bb295e6f55a2bff9f5b6770fa744c16af6e8a/electrum/keystore.py#L810. Conversely, when using Electrum seeds, instead of using the word "mnemonic", it instead uses the word "electrum" concatenated with your passphrase. See line 164 here: https://github.com/spesmilo/electrum/blob/a0b096dcb2292c2826f7beae173c529d335142f0/electrum/mnemonic.py#L164.
Is this also used together with trezor/ledger passphrases or any other known wallets?
|
Ich liebe Bitcoin
|
|
|
o_e_l_e_o
In memoriam
Legendary
Offline
Activity: 2268
Merit: 18696
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 08, 2020, 10:56:55 AM |
|
Is this also used together with trezor/ledger passphrases or any other known wallets? Trezor and Ledger seed phrases and any optional passphrases follow the standard BIP39 protocol, i.e. using the word "mnemonic". This is also true of pretty much every other hierarchical deterministic wallet which exists these days. Electrum is pretty much the only one which has its own method for generating seed phrases. If you want to read more in depth as to how seed phrases are combined with passphrases to generate your wallet, have a read of this: https://github.com/bitcoinbook/bitcoinbook/blob/develop/ch05.asciidoc#from-mnemonic-to-seed
|
|
|
|
nc50lc
Legendary
Online
Activity: 2506
Merit: 5926
Self-proclaimed Genius
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 08, 2020, 11:05:28 AM |
|
Initial Electrum wallet is segwit. I think I forced it through as an invalid BIP39 seed phrase cause the checksum=failed but I was still able to proceed.
Those are the exact steps I took in Electrum: -snip-
Addresses didn't match the Electrum derived addresses so I tried with the latest version.
Actually, you can use iancoleman without changing the source code. All you need to do is to get your wallet's master private key and click the right options. Follow these steps: - 1. (skip if you have the wallet) Restore your Electrum wallet using the seed and the same steps you've mentioned.
- 2. Open console tab (View->Show Console) and type getmasterprivate().
- 3. Copy the master private key (yprv) and paste to iancoleman's "BIP32 Root Key".
- 4. Select BIP141 tab and select "P2WPKH nested in P2SH" in the 'Script Semantics' drop-down menu.
- 5. Check the addresses, it should be the same as Electrum's.
|
|
|
|
Chikito
Legendary
Offline
Activity: 2478
Merit: 2066
Top Crypto Casino
|
![](https://bitcointalk.org/Themes/custom1/images/post/xx.gif) |
June 08, 2020, 11:42:48 AM |
|
Follow these steps: - 1. (skip if you have the wallet) Restore your Electrum wallet using the seed and the same steps you've mentioned.
- 2. Open console tab (View->Show Console) and type getmasterprivate().
- 3. Copy the master private key (yprv) and paste to iancoleman's "BIP32 Root Key".
- 4. Select BIP141 tab and select "P2WPKH nested in P2SH" in the 'Script Semantics' drop-down menu.
- 5. Check the addresses, it should be the same as Electrum's.
If @21sats used only step 1, he already has native segwit right?, step 4 must be select P2WPKH not P2WPKH nested in P2SHanother way if @21sats select legacy in begining, must be select BIP 32 to same with electrum legacy address
|
|
|
|
|