<p>Maybe this could help,</p>
<p>as <strong>cborHex</strong> is in <strong>hex</strong>, and you can pass a <strong>Uint8Array</strong> (bytes) to initialize a <strong>VRFKeyHash</strong> like in many <em>cardano-serialization-lib</em> objects, in theory you can use <strong>Buffer.from(hexValue,&quot;hex&quot;)</strong>, like this:</p>
<pre><code>CardanoWasm.VRFKeyHash.from_bytes(Buffer.from((JSON.parse(vrfKeyFile).cborHex,&quot;hex&quot;)));
</code></pre>
<p>not tested!</p>

CC BY-SA 4.0
2022-05-12T01:30:01.597Z
2022-05-12T01:30:01.597Z
GameChanger Finance
<p>I have checked that every cborHex on <code>vrf.vkey</code> files starts with the prefix &quot;5820&quot; and every cborHex on <code>vrf.skey</code> files starts with the prefix &quot;5840&quot;. If I remove those prefixes from the conversion, then it works:</p>
<pre><code>CardanoWasm.VRFKeyHash.from_hex(JSON.parse(vrfKeyFile).cborHex.substring(4)));
</code></pre>

CC BY-SA 4.0
2022-05-12T02:56:55.060Z
2022-05-12T02:56:55.060Z
Falcon Stakepool
<p>I'm using <code>cardanocli-js</code> to create both VRF files for running a stake pool: <code>vrf.vkey</code> and <code>vrf.skey</code>:</p>
<pre><code>const vrfKeyAccount = cardanocliJs.nodeKeyGenVRF(&quot;Totem&quot;);
</code></pre>
<p>Then I want to read the <code>vrf.vkey</code> file and convert the <code>cborHex</code> value to <code>VRFKeyHash</code> format, from the Cardano Serialization Lib. For that, I do:</p>
<pre><code>CardanoWasm.VRFKeyHash.from_hex(JSON.parse(vrfKeyFile).cborHex);
</code></pre>
<p>But I'm getting the following error:</p>
<pre><code>/cardano-multiplatform-lib/rust/pkg/package/cardano_multiplatform_lib.js:16780
    throw takeObject(arg0);
    ^
JsValue(&quot;Deserialization failed in VRFKeyHash because: Invalid cbor: expected tuple 'hash length' of length 32 but got length Len(34).&quot;)
(Use `node --trace-uncaught ...` to show where the exception was thrown)
</code></pre>

<cardano-cli><cardano-serialization-lib><private-key><hash>
How to convert from cborHex to VRFKeyHash using both cardanocli-js and cardano-serialization-lib?
# How to convert from cborHex to VRFKeyHash using both cardanocli-js and cardano-serialization-lib?

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

I'm using cardanocli-js to create both VRF files for running a stake pool: vrf.vkey and vrf.skey:
const vrfKeyAccount = cardanocliJs.nodeKeyGenVRF("Totem");

Then I want to read the vrf.vkey file and convert the cborHex value to VRFKeyHash format, from the Cardano Serialization Lib. For that, I do:
CardanoWasm.VRFKeyHash.from_hex(JSON.parse(vrfKeyFile).cborHex);

But I'm getting the following error:
/cardano-multiplatform-lib/rust/pkg/package/cardano_multiplatform_lib.js:16780
    throw takeObject(arg0);
    ^
JsValue("Deserialization failed in VRFKeyHash because: Invalid cbor: expected tuple 'hash length' of length 32 but got length Len(34).")
(Use `node --trace-uncaught ...` to show where the exception was thrown)

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

---

## 2 answers

### Answer by username_0 on 2022-05-12. Score: 0 | Accepted answer

I have checked that every cborHex on vrf.vkey files starts with the prefix "5820" and every cborHex on vrf.skey files starts with the prefix "5840". If I remove those prefixes from the conversion, then it works:
CardanoWasm.VRFKeyHash.from_hex(JSON.parse(vrfKeyFile).cborHex.substring(4)));


---

### Answer by username_1 on 2022-05-12. Score: 0

Maybe this could help,
as cborHex is in hex, and you can pass a Uint8Array (bytes) to initialize a VRFKeyHash like in many cardano-serialization-lib objects, in theory you can use Buffer.from(hexValue,"hex"), like this:
CardanoWasm.VRFKeyHash.from_bytes(Buffer.from((JSON.parse(vrfKeyFile).cborHex,"hex")));

not tested!


---

