<p>The CLI key you generate is not the same as Bip32PrivateKey associated with HD Wallet, the Root key you're considering is green box below - while the CLI key is red one. You can derive from parent key to child, but not the other way round.</p>
<p><a href="https://i.sstatic.net/KjJQv.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/KjJQv.png" alt="enter image description here" /></a></p>

CC BY-SA 4.0
2021-12-06T01:07:50.233Z
2021-12-06T01:07:50.233Z
RdLrT
<p>You can derive a private key from skey CBOR using:</p>
<pre><code>    // Sign with the backend wallet
    const signingKeyHexCBOR = 'THISISYUURKEYCBOR'
    const signingKey = this.S.PrivateKey.from_normal_bytes(Buffer.from(signingKeyHexCBOR,'hex'));

    const vkeyWitness2 = this.S.make_vkey_witness(txHash, signingKey);
    vkeysWitnesses.add(vkeyWitness);
    ```
</code></pre>

CC BY-SA 4.0
2022-02-14T15:17:55.607Z
do you know how to go the other way? Starting from a Bip32PrivateKey to a CBOR string that I can paste into an skey file that can be used to sign a transaction with cardano-cli?
grim_i_am
CC BY-SA 4.0
2022-02-07T16:18:10.367Z
2022-02-07T16:18:10.367Z
Mantas Andriuška
<p>I'm trying to new <code>Cardano.Bip32PrivateKey</code> from string cborHex which in file <code>skey</code> generate by cardano-cli</p>
<pre><code>import * as Cardano from &quot;@emurgo/cardano-serialization-lib-nodejs&quot;;

function genAccountKey(cborHex: string) {
    return Cardano.Bip32PrivateKey.from_bytes(Buffer.from(cborHex, &quot;hex&quot;))
        .derive(harden(1852)) // purpose
        .derive(harden(1815)) // coin type
        .derive(harden(0)); // account #0

}
genAccountKey(&quot;58204022747367deee69f601900e15ddc04fc8024753b6a1539ee2a8bed29832f420&quot;);
</code></pre>
<p>but I got this err <code>(node:87994) UnhandledPromiseRejectionWarning: Invalid Secret Key size</code></p>

CC BY-SA 4.0
2022-01-23T12:40:52.880Z
Is it possible to use .skey(s) and .vkey(s) to construct transactions with the Cardano Serialisation Library? Based on your response it seems as though it is not possible since one cannot backwards derive the necessary privatekeys ...
sweden_chat
CC BY-SA 4.0
2022-01-23T22:24:15.443Z
Welcome aboard.  Your answer isn't an answer but it would make a good question.  Don't forget to check out the [tour] and read some of the pinned messages in the [help/dont-ask]
gRebel
<nami-wallet><cardano-serialization-lib>
How to new Cardano.Bip32PrivateKey from cborHex in file .skey generate by cardano-cli
# How to new Cardano.Bip32PrivateKey from cborHex in file .skey generate by cardano-cli

(Asked by: username_0 on 2021-12-05)

I'm trying to new Cardano.Bip32PrivateKey from string cborHex which in file skey generate by cardano-cli
import * as Cardano from "@emurgo/cardano-serialization-lib-nodejs";

function genAccountKey(cborHex: string) {
    return Cardano.Bip32PrivateKey.from_bytes(Buffer.from(cborHex, "hex"))
        .derive(harden(1852)) // purpose
        .derive(harden(1815)) // coin type
        .derive(harden(0)); // account #0

}
genAccountKey("58204022747367deee69f601900e15ddc04fc8024753b6a1539ee2a8bed29832f420");

but I got this err (node:87994) UnhandledPromiseRejectionWarning: Invalid Secret Key size

**Tags:** nami-wallet, cardano-serialization-lib
> **Comments:**
> **username_1**: Is it possible to use .skey(s) and .vkey(s) to construct transactions with the Cardano Serialisation Library? Based on your response it seems as though it is not possible since one cannot backwards derive the necessary privatekeys ...  
> **username_2**: Welcome aboard.  Your answer isn't an answer but it would make a good question.  Don't forget to check out the [tour] and read some of the pinned messages in the [help/dont-ask]  

---

## 2 answers

### Answer by username_3 on 2021-12-06. Score: 3

The CLI key you generate is not the same as Bip32PrivateKey associated with HD Wallet, the Root key you're considering is green box below - while the CLI key is red one. You can derive from parent key to child, but not the other way round.

[![enter image description here](https://i.sstatic.net/KjJQv.png)](https://i.sstatic.net/KjJQv.png)


---

### Answer by username_4 on 2022-02-07. Score: 1

You can derive a private key from skey CBOR using:
    // Sign with the backend wallet
    const signingKeyHexCBOR = 'THISISYUURKEYCBOR'
    const signingKey = this.S.PrivateKey.from_normal_bytes(Buffer.from(signingKeyHexCBOR,'hex'));

    const vkeyWitness2 = this.S.make_vkey_witness(txHash, signingKey);
    vkeysWitnesses.add(vkeyWitness);
    ```

> **Comments:**
> **username_5**: do you know how to go the other way? Starting from a Bip32PrivateKey to a CBOR string that I can paste into an skey file that can be used to sign a transaction with cardano-cli?  

---

