<p>You can obtain the extended private key with different derivation paths from a mnemonic using the NodeJS libraries: <code>bitcoinjs-lib@3.3.2</code> <code>bip39</code> and <code>bs58check</code>. From the extended private key you can generate all the child private keys necessary to import or recover your wallet.</p>
<p>bitcoinjs-lib@3.3.2 was last stable version that included the HDNode prototype. Newer versions break out the HD functions and requires more imports.</p>
<p>Basically you start with the mnemonic and you convert it to an HD seed.</p>
<pre class="lang-js prettyprint-override"><code>let mnemonicInput = &quot;bacon bacon bacon bacon bacon bacon bacon bacon bacon bacon bacon abandon&quot;;
let seedHex = bip39.mnemonicToSeedSync(mnemonicInput).toString('hex');
</code></pre>
<p>Once you have the hex seed then you designate your derivation path.</p>
<pre class="lang-js prettyprint-override"><code>let root = bitcoin.HDNode.fromSeedHex(seedHex);
let acct = root.derivePath(&quot;m/&quot;+deriv+&quot;'/0'/&quot;+account+&quot;'&quot;);
//this example acct uses hardened derivation paths (note the apostrophes which are safer than unhardened paths). You will need to remove the apostrophes in order to access an unhardened path
let xprv = acct.toBase58();
</code></pre>
<p>From here you will want to convert to proper x, y or zpub which can be done using Jameson Lopps conversion script.</p>
<p>All together it could look like this:</p>
<pre class="lang-js prettyprint-override"><code>let bitcoin = require(&quot;bitcoinjs-lib&quot;);//use version @3.3.2 for access to HDNode
let bip39 = require('bip39');
let b58 = require('bs58check');

let mnemonicInput = &quot;bacon bacon bacon bacon bacon bacon bacon bacon bacon bacon bacon abandon&quot;;
let seedHex = bip39.mnemonicToSeedSync(mnemonicInput).toString('hex');

console.log(seedToXprv(seedHex,44,0));
//xprv9yqbv4K6SV9NR7kyGBJbbynFvWdf5FUXV4QCNJQe78jAAqT3GE44kuyygmUyYpMmY31Z7mDudrpk3LpHyqv4xSFuRiXpBw1ZdtmrD2aeJQL

console.log(seedToXprv(seedHex,49,0));
//yprvAJeXovoVVRmXGCh1rsQDjWR2U2MmCY2SexU9Hofbrzhx5oA8xtSrXoqLemv1gYF3bR5z8Cy8HdBrM8MMAA7rQrgRXBLuZY7npxwtemrVjMc

console.log(seedToXprv(seedHex,84,0));
//zprvAccUoAVGQCPGinCJAuCtfFogLzXDvuqFBnGnRbwEAJczSo7KC74FV1X9dd5sCHRb4osqYQrj6DeRBkTwejHSDf2U7pxWTjqiqGqsPTj2Jo8


function seedToXprv(seed, deriv, account){
   var root = bitcoin.HDNode.fromSeedHex(seed);
   var acct = root.derivePath(&quot;m/&quot;+deriv+&quot;'/0'/&quot;+account+&quot;'&quot;);
   var xprv = acct.toBase58();
   var outprv = xprv;
    if(deriv==84){
       var zprv = convertXpub(xprv,&quot;zprv&quot;);
       outprv = zprv;
       } else if (deriv==49)
       {
           var yprv = convertXpub(xprv,&quot;yprv&quot;);   
           outprv = yprv;
       }
       return outprv;
}

function convertXpub(xpub,target){
    //source xpub conversion script https://github.com/jlopp/xpub-converter/blob/master/js/xpubConvert.js
    const prefixes = new Map(
  [
    ['xpub', '0488b21e'],
    ['ypub', '049d7cb2'],
    ['Ypub', '0295b43f'],
    ['zpub', '04b24746'],
    ['Zpub', '02aa7ed3'],
    ['tpub', '043587cf'],
    ['upub', '044a5262'],
    ['Upub', '024289ef'],
    ['vpub', '045f1cf6'],
    ['Vpub', '02575483'],
    ['xprv', '0488ade4'],
    ['yprv', '049d7878'],
    ['zprv', '04b2430c']
  ]
  );
    
  xpub = xpub.trim();

  try {
    var data = b58.decode(xpub);
    data = data.slice(4);
    data = Buffer.concat([Buffer.from(prefixes.get(target),'hex'), data]);
    return b58.encode(data);
  } catch (err) {
    return &quot;Invalid extended key! Please double check that you didn't accidentally paste extra data.&quot;;
  }    
}
</code></pre>

CC BY-SA 4.0
2023-04-19T01:08:16.303Z
2023-05-15T15:40:12.177Z
2023-05-15T15:40:12.177Z
m1xolyd1an
<p>I only have the seed phrase. When I enter the seed phrase into, for example, Exodus or Trust Wallet, I can fully recover my Bitcoin in seconds. But how to do this using Python or Node.js?</p>

<wallet><python><mnemonic-seed><seed><nodejs>
How to get the derivation path of a multi-wallet seed phrase?
FledDev
# How to get the derivation path of a multi-wallet seed phrase?

(Asked by: username_0 on 2023-04-18)

I only have the seed phrase. When I enter the seed phrase into, for example, Exodus or Trust Wallet, I can fully recover my Bitcoin in seconds. But how to do this using Python or Node.js?

**Tags:** wallet, python, mnemonic-seed, seed, nodejs


---

## 1 answers

### Answer by username_1 on 2023-04-19. Score: 3

You can obtain the extended private key with different derivation paths from a mnemonic using the NodeJS libraries: `bitcoinjs-lib@3.3.2` `bip39` and `bs58check`. From the extended private key you can generate all the child private keys necessary to import or recover your wallet.

bitcoinjs-lib@3.3.2 was last stable version that included the HDNode prototype. Newer versions break out the HD functions and requires more imports.

Basically you start with the mnemonic and you convert it to an HD seed.

```js
let mnemonicInput = "bacon bacon bacon bacon bacon bacon bacon bacon bacon bacon bacon abandon";
let seedHex = bip39.mnemonicToSeedSync(mnemonicInput).toString('hex');

```

Once you have the hex seed then you designate your derivation path.

```js
let root = bitcoin.HDNode.fromSeedHex(seedHex);
let acct = root.derivePath("m/"+deriv+"'/0'/"+account+"'");
//this example acct uses hardened derivation paths (note the apostrophes which are safer than unhardened paths). You will need to remove the apostrophes in order to access an unhardened path
let xprv = acct.toBase58();

```

From here you will want to convert to proper x, y or zpub which can be done using Jameson Lopps conversion script.

All together it could look like this:

```js
let bitcoin = require("bitcoinjs-lib");//use version @3.3.2 for access to HDNode
let bip39 = require('bip39');
let b58 = require('bs58check');

let mnemonicInput = "bacon bacon bacon bacon bacon bacon bacon bacon bacon bacon bacon abandon";
let seedHex = bip39.mnemonicToSeedSync(mnemonicInput).toString('hex');

console.log(seedToXprv(seedHex,44,0));
//xprv9yqbv4K6SV9NR7kyGBJbbynFvWdf5FUXV4QCNJQe78jAAqT3GE44kuyygmUyYpMmY31Z7mDudrpk3LpHyqv4xSFuRiXpBw1ZdtmrD2aeJQL

console.log(seedToXprv(seedHex,49,0));
//yprvAJeXovoVVRmXGCh1rsQDjWR2U2MmCY2SexU9Hofbrzhx5oA8xtSrXoqLemv1gYF3bR5z8Cy8HdBrM8MMAA7rQrgRXBLuZY7npxwtemrVjMc

console.log(seedToXprv(seedHex,84,0));
//zprvAccUoAVGQCPGinCJAuCtfFogLzXDvuqFBnGnRbwEAJczSo7KC74FV1X9dd5sCHRb4osqYQrj6DeRBkTwejHSDf2U7pxWTjqiqGqsPTj2Jo8

function seedToXprv(seed, deriv, account){
   var root = bitcoin.HDNode.fromSeedHex(seed);
   var acct = root.derivePath("m/"+deriv+"'/0'/"+account+"'");
   var xprv = acct.toBase58();
   var outprv = xprv;
    if(deriv==84){
       var zprv = convertXpub(xprv,"zprv");
       outprv = zprv;
       } else if (deriv==49)
       {
           var yprv = convertXpub(xprv,"yprv");   
           outprv = yprv;
       }
       return outprv;
}

function convertXpub(xpub,target){
    //source xpub conversion script https://github.com/jlopp/xpub-converter/blob/master/js/xpubConvert.js
    const prefixes = new Map(
  [
    ['xpub', '0488b21e'],
    ['ypub', '049d7cb2'],
    ['Ypub', '0295b43f'],
    ['zpub', '04b24746'],
    ['Zpub', '02aa7ed3'],
    ['tpub', '043587cf'],
    ['upub', '044a5262'],
    ['Upub', '024289ef'],
    ['vpub', '045f1cf6'],
    ['Vpub', '02575483'],
    ['xprv', '0488ade4'],
    ['yprv', '049d7878'],
    ['zprv', '04b2430c']
  ]
  );
    
  xpub = xpub.trim();

  try {
    var data = b58.decode(xpub);
    data = data.slice(4);
    data = Buffer.concat([Buffer.from(prefixes.get(target),'hex'), data]);
    return b58.encode(data);
  } catch (err) {
    return "Invalid extended key! Please double check that you didn't accidentally paste extra data.";
  }    
}

```


---

