CryptoDrew on Nostr: The pubkey would just be a 32-byte hex-encoded string, which will always be 64 hex ...
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.
Published at
2024-01-16 16:45:46Event JSON
{
"id": "84c70c7672f5a7e03400a490e520b4def12d942f2c46d78df16ec8c52649b39f",
"pubkey": "81e80c46b9bd0b7c564f59864527fa5f1cc94ea68a07f286858984a341b0a2e8",
"created_at": 1705423546,
"kind": 1,
"tags": [
[
"e",
"3f91b67ab871d3a2dd4a3a824b16d81635b6444d626623b0eb0929aa021028ae",
"",
"root"
],
[
"p",
"df67f9a7e41125745cbe7acfbdcd03691780c643df7bad70f5d2108f2d4fc200"
]
],
"content": "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.\n\nSo, pubkey regex is:\n[0-9a-fA-F]{64}\n\nFor the npub, I believe that is always a consistent length of npub1 + 58 bech32-encoded characters (not bech32m).\n\nSo, npub regex is:\nnpub1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]{58}\n\nPossible that I am wrong about the public length, but I have yet to come across one of a different length.\n\nAlso, validating whether the values decode to a valid secp256k1 key is not something that you could do w/ regex.",
"sig": "952f9805a495c3df29e11f72a351db8eaec4bdf65d4ec66b060741f89c813ae1997575c8dbd17b9f5af908ab65dc12ee451a389a2d9e5000b19e178b47f0a07b"
}