Regex to validate an npub or pubkey offline?
#asknostr
#nostrdev
Regex to validate an npub or pubkey offline?
#asknostr
#nostrdev
The pubkey would just be a 32-byte hex-encoded string, which will always be 64 hex characters in length since 2 hex characters represents 1 byte.
So, pubkey regex is:
[0-9a-fA-F]{64}
For the npub, I believe that is always a consistent length of npub1 + 58 bech32-encoded characters (not bech32m).
So, npub regex is:
npub1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{58}
Possible that I am wrong about the public length, but I have yet to come across one of a different length.
Also, validating whether the values decode to a valid secp256k1 key is not something that you could do w/ regex.
Not sure why, but on #amethyst, the npub regex in my note is not being rendered in full. There is an odd colon in place of some of the text.
https://nostrcheck.me/media/public/nostrcheck.me_5661105604796675421705423822.webp
Renders fine on #plebstr.