#gm #pv my Nostriches. I have a Nostr development question this morning.

When storing nostr public keys in a database should I use the npub or the hex?

also is this missing any hashtags for a question like this? I'm gonna have more and want them to end up in the right place.

#asknostr #plebchain #grownostr

Reply to this note

Please Login to reply.

Discussion

I store the raw bytes, not even hex. Depends on the db you use if it supports this

Using postgres

The npub data should be the same as a uuid. To your database it shouldnt make a difference but according to nip-1 of the protocol it should be HEX.

“pubkey": <32-bytes lowercase hex-encoded public key of the event creator>

https://github.com/nostr-protocol/nips/blob/master/01.md#events-and-signatures

I would imagine a native json db like mongodb or duckdb would have better performance than postgres

Hrmm I just grabbed the stack most familiar with. Node/express postgres.

Believe it or not I've actually never worked with MongoDB. I've done a lot of AWS dynamodb development though are they similar?

Yeah dynamodb is similar to mongodb. Honestly, if you have experience with dynamodb then you should be good.

I find dynamo quirky and a pain to use their api/ db interface

I didn't tag you above because I assumed you were running around a fjord 🥹

Filesystems support raw bytes.

GM Ian, good question! I would think hex but I have no real solid reason to back it up..

Hopeful for more knowledgeable person(s) to chime in!

These hashtags are just fine, but it's also possible that dev questions like this may be best asked in the nostr protocol telegram group? Anyways, I'm not sure on best practices. nostr:npub1v0lxxxxutpvrelsksy8cdhgfux9l6a42hsj2qzquu2zk7vc9qnkszrqj49 nostr:npub1jlrs53pkdfjnts29kveljul2sm0actt6n8dxrrzqcersttvcuv3qdjynqn nostr:npub1l2vyh47mk2p0qlsku7hg0vn29faehy9hy34ygaclpn66ukqp3afqutajft could answer this better than I.

Link to telegram?

Ah yes I'm in there already. This place is packed. 💜✊

Hex, since that allows you to process filters

I was going to say hex and then make functions to convert it if you need to but as others said, raw bytes would be even better.

Sounds like raw bytes (of the hex?) wins. Not a big change but glad I asked.

Good morning my friend

Blessings , Pura vida

I always use hex for everything humans don’t need to interact with; bech32 is just more-human encoding but ultimately you want things in hex

So if building a rest API I would only accept hex keys as the 'id' in a GET request not the npub?

Probably, but the question the is, why are you building a REST API?

Hahahaha Fair question

Nostr won't be the only way to access data. Mainly for visualization And backend admin tool

I always store it in binary form because hex takes 2x more bytes