Bitcoin Forum
April 19, 2024, 09:41:18 PM *
News: Latest Bitcoin Core release: 26.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Looking for derivation paths used for different Electrum mnemonic types  (Read 113 times)
Coding Enthusiast (OP)
Legendary
*
Offline Offline

Activity: 1039
Merit: 2783


Bitcoin and C♯ Enthusiast


View Profile WWW
November 06, 2020, 07:54:15 AM
 #1

I just added the recovery option for Electrum mnemonics to The FinderOuter and even though the derivation path could be set manually but it would be simpler if it were set automatically based on mnemonic type selected (or the address type entered).


However I couldn't find what derivation path is used for each mnemonic type above (eg. m/0 for standard) and need help.
I'd appreciate it if you could also include the link to code where it is defined.

Projects List+Suggestion box
Donate: 1Q9s or bc1q
|
|
|
FinderOuter(0.19.1)Ann-git
Denovo(0.7.0)Ann-git
Bitcoin.Net(0.26.0)Ann-git
|
|
|
BitcoinTransactionTool(0.11.0)Ann-git
WatchOnlyBitcoinWallet(3.2.1)Ann-git
SharpPusher(0.12.0)Ann-git
1713562878
Hero Member
*
Offline Offline

Posts: 1713562878

View Profile Personal Message (Offline)

Ignore
1713562878
Reply with quote  #2

1713562878
Report to moderator
Whoever mines the block which ends up containing your transaction will get its fee.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1713562878
Hero Member
*
Offline Offline

Posts: 1713562878

View Profile Personal Message (Offline)

Ignore
1713562878
Reply with quote  #2

1713562878
Report to moderator
HCP
Legendary
*
Offline Offline

Activity: 2086
Merit: 4316

<insert witty quote here>


View Profile
November 06, 2020, 08:05:40 AM
 #2

I think the code you're looking for is here: https://github.com/spesmilo/electrum/blob/1c07777e135d28fffa157019f90ccdaa002b614e/electrum/base_wizard.py#L407

You can see how during the "setup wizard", it is setting up the various derivation paths for each script_type, for each wallet type. The functions being called to "create" the derivation paths are in the bip32.py (normalize_bip32_derivation()) and keystore.py (purpose48_derivation() & bip44_derivation()) code.

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


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
Coding Enthusiast (OP)
Legendary
*
Offline Offline

Activity: 1039
Merit: 2783


Bitcoin and C♯ Enthusiast


View Profile WWW
November 06, 2020, 08:26:42 AM
 #3

The derivation_and_script_type_dialog seems to be called when the wallet is being created using a hardware wallet not from an Electrum seed phrase. That is why path for eg. 'standard', 'legacy (p2pkh)' is being set to m/44'/0'/0' and I know for a fact that it is m/0 for Electrum mnemonics.

Projects List+Suggestion box
Donate: 1Q9s or bc1q
|
|
|
FinderOuter(0.19.1)Ann-git
Denovo(0.7.0)Ann-git
Bitcoin.Net(0.26.0)Ann-git
|
|
|
BitcoinTransactionTool(0.11.0)Ann-git
WatchOnlyBitcoinWallet(3.2.1)Ann-git
SharpPusher(0.12.0)Ann-git
HCP
Legendary
*
Offline Offline

Activity: 2086
Merit: 4316

<insert witty quote here>


View Profile
November 07, 2020, 01:10:25 AM
 #4

The derivation_and_script_type_dialog seems to be called when the wallet is being created using a hardware wallet not from an Electrum seed phrase.
Oh yes, of course... it also uses it when restoring from a BIP39 mnemonic.

Most likely this is because Electrum mnemonics are "versioned"... so the script type is encoded in the mnemonic itself. Electrum reads that, then defaults to using the encoded script_type and appropriate derivation path automatically.

I've noted that the derivation path is stored in the "keystore" within the wallet file as well:
Code: (Native Segwit Electrum wallet)
    "keystore": {
        "derivation": "m/0'",
        "pw_hash_version": 1,
        "root_fingerprint": "da996cc9",
        "seed": "naive goddess they empty super bone friend visit segment person act palm",
        "type": "bip32",
        "xprv": "zprvAaAs87fpU4gB4oxt9ALBFa6rFj5g4ti1GH71qHHVt8hEcj1N7Ct5CmX1nFB94FewoH5Pmy9dCmRjkTCWzYfsNowk6angDwgdKug8QbMLddf",
        "xpub": "zpub6oADXdCiJSEUHJ3MFBsBci3aokvAUMRrdW2cdfh7SUEDVXLWekCKkZqVdVhW2jXUGr5umrchPNxwfdaQjxkc854SGvaG5Qd8rifoCrGQAnx"
    },


Code: (Legacy Electrum wallet)
    "keystore": {
        "derivation": "m",
        "pw_hash_version": 1,
        "root_fingerprint": "65751984",
        "seed": "comfort history avocado badge genre uphold rely evolve soccer beef defy spoon",
        "type": "bip32",
        "xprv": "xprv9s21ZrQH143K4VH6GX2JjtPu9DtUQ5BJF1VUf59Eexcaez3W5QtTRm4YeKMwL1iP9WUkAgRmw63Ls4nwHjPdTiv6sAU1LqzFCHxKJ2dATSw",
        "xpub": "xpub661MyMwAqRbcGyMZNYZK72LdhFixoXu9cER5TTYrDJ9ZXnNecxChyZP2VaconGXsfh6Vof1vn2qFD5GU1Wgi2VkNxU344HNgSsRQLLiFv8b"
    },

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


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
NotATether
Legendary
*
Offline Offline

Activity: 1582
Merit: 6671


bitcoincleanup.com / bitmixlist.org


View Profile WWW
November 07, 2020, 05:11:43 AM
 #5

When someone clicks on the “Restore from seed” option and inputs a BIP39 seed phrase, that’ll restore from derivation paths m/44'/0'/0' for legacy, m/49'/0'/0' for segwit, and m/84'/0'/0' for native segwit, so there are actually three more paths to account for if you’re not just supporting Electrum mnemonics.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
Coding Enthusiast (OP)
Legendary
*
Offline Offline

Activity: 1039
Merit: 2783


Bitcoin and C♯ Enthusiast


View Profile WWW
November 07, 2020, 12:04:45 PM
 #6

I dug around in the code again today and I believe this is where the paths are set:
https://github.com/spesmilo/electrum/blob/1c07777e135d28fffa157019f90ccdaa002b614e/electrum/keystore.py#L984-L1003

Projects List+Suggestion box
Donate: 1Q9s or bc1q
|
|
|
FinderOuter(0.19.1)Ann-git
Denovo(0.7.0)Ann-git
Bitcoin.Net(0.26.0)Ann-git
|
|
|
BitcoinTransactionTool(0.11.0)Ann-git
WatchOnlyBitcoinWallet(3.2.1)Ann-git
SharpPusher(0.12.0)Ann-git
HCP
Legendary
*
Offline Offline

Activity: 2086
Merit: 4316

<insert witty quote here>


View Profile
November 07, 2020, 12:10:13 PM
 #7

Looks good... I would just add that the actual address derivation path most likely has another /0 on the end of those Wink

Might pay to experiment a little with some Electrum seeds and this Electrum compatible fork of Ian Coleman's BIP39 tool: https://github.com/FarCanary/ElectrumSeedTester

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


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
Chikito
Legendary
*
Offline Offline

Activity: 2366
Merit: 2052



View Profile WWW
November 09, 2020, 12:01:18 AM
 #8

When someone clicks on the “Restore from seed” option and inputs a BIP39 seed phrase, that’ll restore from derivation paths m/44'/0'/0' for legacy, m/49'/0'/0' for segwit, and m/84'/0'/0' for native segwit, so there are actually three more paths to account for if you’re not just supporting Electrum mnemonics.
Electrum 4.0.4 already had Detect Existing Accounts button this function for Scanning Common Paths without choosing it manually.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
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!