The β€œdevelop” branch of nostr-irc now protects you from accidentally posting your nsec private key. I’ll be merging to master once I have some other features updated. All it took was:

```

if re.search(r'nsec[a-z0-9]{32,64}$', user_input):

messages.addstr("\n *** Error: Potential exposure of nsec private key. Message denied.\n\n”)

```

Magic! 🎩πŸͺ„

Reply to this note

Please Login to reply.

Discussion

Ok πŸ˜…πŸ˜‚

I did it for you #[2] πŸ˜‚

πŸ˜‚πŸ˜‚πŸ˜‚

It's great tho

I would love to see all nostr clients implement something similar. A few lines of code allows us client creators to help further protect the users from footguns and malicious actors.

There could be a case made for filtering the regex out of kind 1 events to prevent this at a relay level too, but that's up to the relay operator and their own personal stance on data censorship.

#[0]

Great idea!

But I would not limit the length check, if a single char is added by error the regex fails and you show the key.

I would use 'nsec1[a-z0-9]{16,}'.

PS: Why the final $? I don't use python, perhaps his regex engine has something special.

Great call! I’ll remove the end limit and the $. $ is an anchor that matches the end of the string and it’s not needed for this re search.

Ah in fact, so the same regex use I'm used to.

We have saved a couple of burned keys ;)