<p>c-lightning uses <a href="https://github.com/ElementsProject/lightning/blob/bad0ac6ed615107e129458f0d40915847bdddd08/hsmd/hsmd.c#L300-L304" rel="nofollow noreferrer">this code</a> to obtain the node's private key from the <code>hsm_secret</code>.</p>

<p>I've came up with a way to do the same using Python and posted my highly-commented tutorial-like code in <a href="https://gist.github.com/fiatjaf/e3232bef6d59263b439b97b6d04d1bcc" rel="nofollow noreferrer">this gist</a>.</p>

<p>Basically you have to call an <a href="https://en.wikipedia.org/wiki/HKDF" rel="nofollow noreferrer"><code>hkdf</code></a> function with the <code>hsm_secret</code> contents, a salt which will usually be zero, <code>\x00</code>, and the label <code>"nodeid"</code>.</p>

CC BY-SA 4.0
2019-04-04T01:46:17.157Z
2019-04-04T01:46:17.157Z
fiatjaf
<p><code>lightning-cli getinfo</code> outputs my node's id, which is its public key. How can I get its underlying private key?</p>

<private-key><core-lightning>
How to get my c-lightning node's private key?
fiatjaf
# How to get my c-lightning node's private key?

(Asked by: username_0 on 2019-04-04)

`lightning-cli getinfo` outputs my node's id, which is its public key. How can I get its underlying private key?

**Tags:** private-key, core-lightning


---

## 1 answers

### Answer by username_0 on 2019-04-04. Score: 2 | Accepted answer

c-lightning uses [this code](https://github.com/ElementsProject/lightning/blob/bad0ac6ed615107e129458f0d40915847bdddd08/hsmd/hsmd.c#L300-L304) to obtain the node's private key from the `hsm_secret`.

I've came up with a way to do the same using Python and posted my highly-commented tutorial-like code in [this gist](https://gist.github.com/username_0/e3232bef6d59263b439b97b6d04d1bcc).

Basically you have to call an [`hkdf`](https://en.wikipedia.org/wiki/HKDF) function with the `hsm_secret` contents, a salt which will usually be zero, `\x00`, and the label `"nodeid"`.


---

