title: How to convert TOR v3 private/public keys in Node.js using crypto library
body: <p>I have private/public keys (files <code>hs_ed25519_secret_key</code> and <code>hs_ed25519_public_key</code>) generated by Tor. My goal is to convert them to <a href="https://nodejs.org/api/crypto.html#crypto_class_keyobject" rel="nofollow noreferrer"><code>KeyObject</code></a> in Node.js, but I cannot extract keys from them.</p>
  <p>When I open the file (e.g. <code>hs_ed25519_secret_key</code>), I see this:</p>
  <pre><code>== ed25519v1-secret: type0 ==8����+�Z�Y���DsЄ�_�K���k�h��z�z|�&lt;ʾ'�Q��:������`�D'��
  </code></pre>
  <p>I guess they used <code>base64</code> encoding. So, I tried to open the file with:</p>
  <pre class="lang-js prettyprint-override"><code>import fs from &quot;fs&quot;;
  const publicKey = fs.readFileSync(&quot;./hs_ed25519_secret_key&quot;, &quot;base64&quot;);
  </code></pre>
  <p>and got the following output:</p>
  <pre><code>PT0gZWQyNTUxOXYxLXNlY3JldDogdHlwZTAgPT0AAAAYC++/vXtY77+977+977+9UWlCTGXvv73vv73vv70efu+/ve+/ve+/vVzvv71+JHkyeuq4kFpqHe+/vTDvv73vv71e77+977+9aO+/ve+/vXPnp4ZeBmXvv71T77+977+9Jlfvv73vv73ClO+/ve+/vTYK
  </code></pre>
  <p>How can I extract the private key from it? What is the format?</p>
  <p>The ultimate goal is to implement the following methods:</p>
  <pre class="lang-js prettyprint-override"><code>class TorV3 {
    /**
     * The same result as Tor.getPublicFromSecret(TorV3.readSecretKey(path))
     * @returns KeyObject
     */
    static readPublicKey(path) {}
  
    /**
     * @returns KeyObject
     */
    static readSecretKey(path) {}
  
    /**
     * @returns KeyObject
     */
    static getPublicFromSecret(keyObject) {}
  }
  </code></pre>