fiatjaf / noscl

Command line client for Nostr.
Other
269 stars 53 forks source link

Bug in Private Key Encoding/Decoding handling #56

Open ajx42 opened 1 year ago

ajx42 commented 1 year ago

It seems the following (pool.SecretKey) expects an encoded key string. Currently, we are decoding the key string before setting it here. https://github.com/fiatjaf/noscl/blob/master/nostr.go#L40-L42

image

It gets fixed with the following patch, i.e. if we set Config.PrivateKey to the raw (encoded) string. https://github.com/ajain365/noscl/commit/f10c434789ec0e0af6a5be73e98bd579263ec38e

A related problem is the following, which the above patch also fixes: showPublicKey is passing the already decoded key to getPubKey: https://github.com/fiatjaf/noscl/blob/master/key.go#L55 There is this older PR that fixes this issue at another place https://github.com/fiatjaf/noscl/pull/50

Currently we get this:

image

I can go ahead and fix it if it's okay. Feel free to assign me. I am trying to learn about this codebase, so happy to help.

PlebeiusGaragicus commented 1 year ago

I'm confused how noscl is storing the private key inside config.json.

{
  "relays": {},
  "following": {},
  "privatekey": "\ufffdnT\ufffd\ufffd3XX\r\ufffd\ufffdLC\ufffd\ufffd\ufffdQz\ufffd\ufffd\ufffd\ufffdA\ufffd={z\ufffd\ufffd\u0016:"
}

This encoding makes no sense to me. It was set via noscl set private d26e5491ab337f58580db8994c43b3a28d517ae1fbf9f341ab3d7b7aa38d163a

I'm missing something.

PlebeiusGaragicus commented 1 year ago

Figured it out - I was using HEAD on this project. I guess the same bug is the reason for this issue.

I just ran noscl using go install github.com/fiatjaf/noscl@latest and it worked fine. config.json is just storing the hex version.