pull down to refresh

Hey all, can anybody tell me how to get someone's npub from a pubkey using plain javascript? I am making a client and want a stream of kind one events from a couple of clients, but with the author's info. I know how to extract the pubkey, but don't know how to translate that into finding the corresponding npub and the necessary kind 0 to go with it.
2,000 sats paid
jasonb's bounties
You have to connect to a relay and ask filter for kind zero events of a given npub and then it will send it.
How do you have their pubkey but not their npub? What pubkey do you have? An npub IS a pubkey.
reply
I apologize im on mobile, and have only done this in Python.
Here is documentation for a rust library with javascript bindings: https://rust-nostr.org/nostr/04_00-event.html
It is a work in progress and documentation needs work...
reply
Oh, this looks helpful! Lemme toy around with this.
reply
So, yeah, I can already pull in kind 0 events, but for kind 1 events that I'm just pulling in randomly off of relays, how do I find the kind 0 event associated with the poster of that kind 1 event I have. Wow, that sentence was horrible. I'm not sure how to put it any other way. Maybe this explains why I'm having trouble. The pubkey that I'm getting from these kind 1 events doesn't look like an npub. Is one of them just in hex and I need to convert it?
reply
Yes, its likely just a hex encodiny of the npub.
A key in npub/nsec is for human-readability. In most nostr libraries we convert to hex.
reply
So you have to request the kind 0 for EVERY account you want that info for. 🫤
reply
Can i see your code?
Also, have you asked chatGPT at all?
reply
Here's a deployment too. Right now, as you can see from the code, I've just called up my own user info once on the right. My goal is to have it match the note to the left. I just want to make a feed of content that's all longer notes of subjects excluding nostr and bitcoin. After that, I want to make a uniform zap option of like 3000 or something really large like that. The goal is to incentivize people to start using nostr to write more thought-out notes. I image that creating more normie adoption and ultimately more normie interest in freedom-tech.
As you can see though, I'm still pretty basic on the coding front...
reply
Yeah, actually it's kind of a mess right now BECAUSE of some suggestions I had taken from chatGPT. I'm currently just trying to parse out kind 0 events independently, just to see if I can even do it in a displayable way. My goal is obviously to draw those from the kind 1 events though. Thanks for helping! I'll let you know if I figure it out on my own, but I'd of course appreciate any other suggestions for untangling all of this.
reply
To clarify, what I really just want to do is have a human-readable name and picture to correspond to each post.
reply