very noob nostr "dev" question here #asknostr

I am using the python nostr-sdk, and the documentation is seriously lacking (or I couldn't find it after some hours which would be bad).

How can I turn a PubKey() object into an npub?

with to_hex() I get the hex version, but I want the npub...

Reply to this note

Please Login to reply.

Discussion

i think the technical term for these encodings is "entities" and i'm gonna clone this repo and search it to see if i can help

https://pypi.org/project/nostr-sdk/

so i looked at this, and the link leads to the rust-nostr

not sure this is the best library to be using, it's not python native for a start... i don't think bech32 encoding is so complex that it benefits that much from an FFI like this one

https://github.com/nostr-protocol/nips/blob/master/19.md

this is the NIP that specifies all of the Bech32 encoded things... nevent and naddr in particular binary encode addresses to relays into a thing that are "relay hints"

https://github.com/davestgermain/aionostr/blob/8ee0c3f1eaee1365eea1df614961bb95b5da0d2d/aionostr/util.py#L7 this seems sorta interesting

yeah, that looks like it might be a better option for you, idk

https://mleku.dev/git/nostr/src/branch/main/bech32encoding/nip19.go is the code i work with for #golang - i haven't touched it, it's the same code as https://github.com/nbd-wtf/go-nostr for nip-19

HTH

You have to use the `to_bech32` method.

The book is not ready, but you can find some example related to keys here: https://rust-nostr.org/nostr/03-keys.html