<p>You can use that key to sign transactions in cardano-serialization lib, but I believe you can't go back to a seed phrase or root key / other key derivations from it.</p>
<p>To use it for signing transactions, you can unwrap and create the PrivateKey like so:</p>
<pre><code>const cbor_hex_key = &quot;582019544c6b8de8e697c6efa3a1ea728559b063f77f52314fcd2fbce3b692c3e99f&quot;;
const unhex = Buffer.from(cbor_hex_key, &quot;hex&quot;);
const decode = cbor.decode(unhex);
const privKey = PrivateKey.from_normal_bytes(decode)
console.log(privKey.to_bech32()) // ed25519_sk1r92yc6udarnf03h05ws75u59txcx8aml2gc5lnf0hn3mdykrax0smqv6uc
</code></pre>
<p><em>(the cbor package for decoding is here: <a href="https://www.npmjs.com/package/cbor" rel="nofollow noreferrer">https://www.npmjs.com/package/cbor</a>, the serialization lib pkg I use from here: <a href="https://www.npmjs.com/package/@emurgo/cardano-serialization-lib-nodejs" rel="nofollow noreferrer">https://www.npmjs.com/package/@emurgo/cardano-serialization-lib-nodejs</a>)</em></p>
<p>If you do need to start from a root key starting with &quot;xprv...&quot;, you can generate an <em>extended key</em> with the CLI using</p>
<blockquote>
<p>cardano-cli address key-gen --extended-key</p>
</blockquote>
<p>and then use that cborHex value in the serialization lib like so <em>(it will be much longer than the one above)</em>:</p>
<pre><code>const cbor_hex_ext_key = &quot;5880a83391da55604678e05489ccb29cee99c238b224b29ef21f98dfd2b121155d5c9dfe7157214cd61c6522aaabb3a5707ae176b220516a51c2cc4f651a3c0dc21c0596b0c11795a9a42cf7ba0014fa402195900813942d66ba3c9b8c175e58fd5ac9e1dfa7008b77af7616ab23a9250374d7c4d39041874cfad9116c204e9b372a&quot;
const ext_unhex = Buffer.from(cbor_hex_ext_key, &quot;hex&quot;);
const ext_uncbor = cbor.decode(ext_unhex);
const ext_key = Bip32PrivateKey.from_128_xprv(ext_uncbor)
console.log(ext_key.to_bech32()) // xprv14qeerkj4vpr83cz538xt988wn8pr3v3yk200y8ucmlftzgg4t4wfmln32us5e4suv53242an54c84ctkkgs9z6j3ctxy7eg68sxuy8xfu806wqytw7hhv94tyw5j2qm56lzd8yzpsax04kg3dssyaxeh9gtrw423
</code></pre>
<p>But from there also you won't be able to go back to a <em>seed phrase</em>, but in case you're coming from a seed phrase <em>(eg generated via &quot;cardano-address recovery-phrase generate&quot;)</em> you can decode it in the lib like so:</p>
<pre><code>const entropy = mnemonicToEntropy(&quot;theme debate amateur pudding young deal wealth bag neck victory language abandon tribe unlock rabbit fix visual spawn broom advice anger foam strong document&quot;);
const root = Bip32PrivateKey.from_bip39_entropy(
    Buffer.from(entropy, 'hex'),
    Buffer.from(''),
  )
console.log(root.to_bech32()); //xprv1xqdaf53cvc8cdnmx6wf0gz3pxq0kk7rfu7sfkac99tadxs2j0prqe3n20emyw8vv7r8435lw2h4lgar2jwzdyfha7facnln0mhw22dlxgpgw38pt0vus0lyq9rs5rnws79x4dswwyklyklvyuyslh65c4ykl0hr4
</code></pre>
<p><em>Good source for all this: <a href="https://github.com/Emurgo/cardano-serialization-lib/blob/4f717ac97bd768168ab273dacd9e43cb6b4aa4ec/doc/getting-started/generating-keys.md" rel="nofollow noreferrer">https://github.com/Emurgo/cardano-serialization-lib/blob/4f717ac97bd768168ab273dacd9e43cb6b4aa4ec/doc/getting-started/generating-keys.md</a>)</em></p>

CC BY-SA 4.0
2022-04-05T07:01:04.007Z
thanks for the comprehensive answer, it confirmed my understanding.
Jingles
CC BY-SA 4.0
2022-04-05T06:40:15.700Z
2022-04-05T06:47:10.393Z
2022-04-05T06:47:10.393Z
sean
<h2>Objective</h2>
<p>To load a private key generated by cardano-cli into cardano-serialization lib</p>
<h2>Details</h2>
<p>Using cardano-cli <code>cardano-cli address key-gen</code>, we get this:</p>
<pre><code>{
    &quot;type&quot;: &quot;PaymentSigningKeyShelley_ed25519&quot;,
    &quot;description&quot;: &quot;Payment Signing Key&quot;,
    &quot;cborHex&quot;: &quot;582099n3n930d9n31b5b102h3vd9csa290c14e0898sn1d278f1939f3e4bed890675a&quot;
}
</code></pre>
<p>Are we able to derive the root key? for example in this format:</p>
<pre><code>xprv17qx9vxm6060qjn5fgazfue9nwyf448w7upk60c3epln82vumg9r9kxzsud9uv5rfscxp382j2aku254zj3qfx9fx39t6hjwtmwq85uunsd8x0st3j66lzf5yn30hwq5n75zeuplepx8vxc502txx09ygjgx06n0p
</code></pre>
<p>or seed phrase? for example:</p>
<pre><code>bawdy identify skin design ... squash elbow aloof plain nerve verse reply near
</code></pre>

<cardano-cli><cardano-serialization-lib><private-key>
Is it possible to get root key from CLI generated private key?
# Is it possible to get root key from CLI generated private key?

(Asked by: username_0 on 2022-04-05)

Objective
To load a private key generated by cardano-cli into cardano-serialization lib
Details
Using cardano-cli cardano-cli address key-gen, we get this:
{
    "type": "PaymentSigningKeyShelley_ed25519",
    "description": "Payment Signing Key",
    "cborHex": "582099n3n930d9n31b5b102h3vd9csa290c14e0898sn1d278f1939f3e4bed890675a"
}

Are we able to derive the root key? for example in this format:
xprv17qx9vxm6060qjn5fgazfue9nwyf448w7upk60c3epln82vumg9r9kxzsud9uv5rfscxp382j2aku254zj3qfx9fx39t6hjwtmwq85uunsd8x0st3j66lzf5yn30hwq5n75zeuplepx8vxc502txx09ygjgx06n0p

or seed phrase? for example:
bawdy identify skin design ... squash elbow aloof plain nerve verse reply near

**Tags:** cardano-cli, cardano-serialization-lib, private-key

---

## 1 answers

### Answer by username_1 on 2022-04-05. Score: 3 | Accepted answer

You can use that key to sign transactions in cardano-serialization lib, but I believe you can't go back to a seed phrase or root key / other key derivations from it.
To use it for signing transactions, you can unwrap and create the PrivateKey like so:
const cbor_hex_key = "582019544c6b8de8e697c6efa3a1ea728559b063f77f52314fcd2fbce3b692c3e99f";
const unhex = Buffer.from(cbor_hex_key, "hex");
const decode = cbor.decode(unhex);
const privKey = PrivateKey.from_normal_bytes(decode)
console.log(privKey.to_bech32()) // ed25519_sk1r92yc6udarnf03h05ws75u59txcx8aml2gc5lnf0hn3mdykrax0smqv6uc

(the cbor package for decoding is here: https://www.npmjs.com/package/cbor, the serialization lib pkg I use from here: https://www.npmjs.com/package/@emurgo/cardano-serialization-lib-nodejs)
If you do need to start from a root key starting with "xprv...", you can generate an extended key with the CLI using

cardano-cli address key-gen --extended-key

and then use that cborHex value in the serialization lib like so (it will be much longer than the one above):
const cbor_hex_ext_key = "5880a83391da55604678e05489ccb29cee99c238b224b29ef21f98dfd2b121155d5c9dfe7157214cd61c6522aaabb3a5707ae176b220516a51c2cc4f651a3c0dc21c0596b0c11795a9a42cf7ba0014fa402195900813942d66ba3c9b8c175e58fd5ac9e1dfa7008b77af7616ab23a9250374d7c4d39041874cfad9116c204e9b372a"
const ext_unhex = Buffer.from(cbor_hex_ext_key, "hex");
const ext_uncbor = cbor.decode(ext_unhex);
const ext_key = Bip32PrivateKey.from_128_xprv(ext_uncbor)
console.log(ext_key.to_bech32()) // xprv14qeerkj4vpr83cz538xt988wn8pr3v3yk200y8ucmlftzgg4t4wfmln32us5e4suv53242an54c84ctkkgs9z6j3ctxy7eg68sxuy8xfu806wqytw7hhv94tyw5j2qm56lzd8yzpsax04kg3dssyaxeh9gtrw423

But from there also you won't be able to go back to a seed phrase, but in case you're coming from a seed phrase (eg generated via "cardano-address recovery-phrase generate") you can decode it in the lib like so:
const entropy = mnemonicToEntropy("theme debate amateur pudding young deal wealth bag neck victory language abandon tribe unlock rabbit fix visual spawn broom advice anger foam strong document");
const root = Bip32PrivateKey.from_bip39_entropy(
    Buffer.from(entropy, 'hex'),
    Buffer.from(''),
  )
console.log(root.to_bech32()); //xprv1xqdaf53cvc8cdnmx6wf0gz3pxq0kk7rfu7sfkac99tadxs2j0prqe3n20emyw8vv7r8435lw2h4lgar2jwzdyfha7facnln0mhw22dlxgpgw38pt0vus0lyq9rs5rnws79x4dswwyklyklvyuyslh65c4ykl0hr4

Good source for all this: https://github.com/Emurgo/cardano-serialization-lib/blob/4f717ac97bd768168ab273dacd9e43cb6b4aa4ec/doc/getting-started/generating-keys.md)

> **Comments:**
> **username_0**: thanks for the comprehensive answer, it confirmed my understanding.  

---

