Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User metadata raw event #225

Closed
gzuuus opened this issue May 14, 2024 · 7 comments · Fixed by #229
Closed

User metadata raw event #225

gzuuus opened this issue May 14, 2024 · 7 comments · Fixed by #229

Comments

@gzuuus
Copy link
Contributor

gzuuus commented May 14, 2024

I was wondering if it would be possible to get the raw event from the user metadata (kind:0). It would be interesting if fetchUserProfile() or NDKUser had a method that would allow you to access the kind:0, so you could validate the event.

@Sebastix
Copy link
Contributor

@gzuuus You can use the method .rawEvent() on a NDKEvent. The NDKUserProfile is being generated from a NDKEvent afaik. I don't know if this method also works on a NDKUserProfile object..

https://ndk.fyi/docs/classes/NDKEvent.html#rawEvent

@gzuuus
Copy link
Contributor Author

gzuuus commented May 14, 2024

No, I was trying it already 👍

@Sebastix
Copy link
Contributor

An alternative way would be fetching the event directly.

const filter = {
  kinds: [0],
  authors: [user.pubkey]
}
const p = await ndk.fetchEvent(filter)
p.rawEvent()

@gzuuus
Copy link
Contributor Author

gzuuus commented May 14, 2024

Yes of course, the problem with this approach is that it feels a bit convoluted to fetch the event like that and then set NDKUserProfile based on it. It would be so convenient to have it already when you call fetchUserProfile()

@erskingardner
Copy link
Collaborator

@gzuuus sorry it's taken a while.

When NDK fetches events it's validating them (verifying signatures) on the way in the door. Is there some other type of verification that you need to do? The way that NDKUserProfile works, it's already storing all the fields it finds in the event content JSON blob, even if they aren't known fields. So I'm not sure if this would actually be beneficial or just mean that we're storing the same data twice.

@gzuuus
Copy link
Contributor Author

gzuuus commented May 24, 2024

Yes, that's great. In my specific use case, I need the complete Kind0 event to store it in my database. Since the event itself is a signed document by the author, it wouldn't require any extra authentication to be added. What I'm missing is having access to this complete signed event. Ideally, all I would need is the event ID and signature to reconstruct it, but there are several factors that make this approach unreliable in NDK. For instance, fetchUserProfile() maps the profile data into a more standardized structure (which is great and very convenient), but this makes it difficult to reliably reconstruct the event from the available information (using the ID and signature). Ultimately, the benefit is that NDK can be better integrated into more custom solutions that go beyond simply displaying data on the client-side.

What do you think? Can you think of another solution for this, maybe it could be something optional like a prop for fetUserProfile, for example storeEvent: bolean. Let me know what you think, happy to code it.

@gzuuus
Copy link
Contributor Author

gzuuus commented May 24, 2024

Just updated the pr to make store profile event opt-in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants