<p>Since it's mentioned in CIP-0030 that the key for the header associated with the public key is <code>-2</code>, I spent some time in the debugger and managed to fetch it with this code.</p>
<pre><code>const coseKey = MessageSigning.COSEKey.from_bytes(Buffer.from(key, 'hex'));

const keyHeaderBytes = coseKey.header(MessageSigning.Label.new_int(MessageSigning.Int.new_i32(-2))).as_bytes();
</code></pre>
<p>Not sure if this is the optimal solution but it seems to work. Open to feedback.</p>

CC BY-SA 4.0
2022-07-25T10:07:23.990Z
2022-07-25T10:07:23.990Z
zing
<p>The following <code>(await window.cardano['&lt;wallet&gt;'].enable()).signData('&lt;addr&gt;', '&lt;payload&gt;')</code></p>
<p>Returns an object
<code>{ key: &lt;key&gt;, signature: &lt;sig&gt; }</code></p>
<p>I'm successfully parsing the key to a CoseKey with <code>ermugo/message-signing</code> in node.js, but struggling to pull the header which contains the key. Reading <a href="https://github.com/cardano-foundation/CIPs/tree/master/CIP-0030#apisigndataaddr-address-payload-bytes-promisedatasignature" rel="nofollow noreferrer">CIP-0030</a> I believe it is contained within the headers as <code>x</code>. Could someone explain how I read this in code, please? Thanks for your time.</p>
<p>edit: if there is documentation that explains how to do this please show me the way.</p>

<cardano-serialization-lib><public-key><message-signing>
Read key from cose_key returned in signData()
# Read key from cose_key returned in signData()

(Asked by: username_0 on 2022-07-25)

The following `(await window.cardano[''].enable()).signData('', '')`

Returns an object
`{ key: , signature:  }`

I'm successfully parsing the key to a CoseKey with `ermugo/message-signing` in node.js, but struggling to pull the header which contains the key. Reading [CIP-0030](https://github.com/cardano-foundation/CIPs/tree/master/CIP-0030#apisigndataaddr-address-payload-bytes-promisedatasignature) I believe it is contained within the headers as `x`. Could someone explain how I read this in code, please? Thanks for your time.

edit: if there is documentation that explains how to do this please show me the way.

**Tags:** cardano-serialization-lib, public-key, message-signing

---

## 1 answers

### Answer by username_0 on 2022-07-25. Score: 1

Since it's mentioned in CIP-0030 that the key for the header associated with the public key is -2, I spent some time in the debugger and managed to fetch it with this code.
const coseKey = MessageSigning.COSEKey.from_bytes(Buffer.from(key, 'hex'));

const keyHeaderBytes = coseKey.header(MessageSigning.Label.new_int(MessageSigning.Int.new_i32(-2))).as_bytes();

Not sure if this is the optimal solution but it seems to work. Open to feedback.


---

