Re: Implement NIP-01 in C Language

st 23. 4. 2025 v 7:52 odesílatel Radhitya <radhitya@100indie.org> napsal:

> On 4/22/25 8:29 PM, Melvin Carvalho wrote:
>
> > What do you mean by burdensome?
> Pardon me. It should not 'burdensome', but 'chaotic'.
> > Normally when someone writes a relay they take NIP-01 and try and get
> that
> > working with the different kinds and indexes.
> >
> > Then they look at what other NIPs they want to do.
> >
> > Personally, a minimal relay in C without other NIPs sounds like a great
> > idea on its own.  You might want to run the code through a large language
> > model for review, if you havent already.
> I'm still confused about NIP-01.. I've been trying to figure out and the
> code is a my attempt..
> What do you think about my code in there?
>
> I know the code is not completed.. I missed array inside array..
>
> I'm struggling to understand the concept.
>
> Would you help me?
>


Hi Radhitya,

Thanks for posting — lovely to see someone diving into a Nostr relay in C!

You’ve got the core event struct and JSON generation working, which is a
great start. I had a quick look at the code — a couple of quick thoughts
that might help reduce the chaos as you keep going:

- The `tags` field is in your struct but isn’t serialized yet — NIP-01
expects it to be a JSON array of arrays, like `[["e", "someeventid"], ["p",
"somepubkey"]]`. Worth adding that soon.
- You’ll want to support the main message types (`EVENT`, `REQ`, `CLOSE`) —
even just basic parsing of incoming JSON arrays from the websocket.
- For `id`, NIP-01 specifies that it’s the SHA256 of a raw JSON array of
`[0, pubkey, created_at, kind, tags, content]` — not a stringified version,
but the actual array. Getting that right will help later when you do sig
verification with secp256k1.
- Your `Filter` struct might need tweaking — things like `ids`, `authors`,
and `kinds` should be arrays, not just single values.

And memory cleanup (e.g. freeing `malloc()`s) is worth keeping in mind as
the code grows, though no rush at this early stage.

Overall, looks good — minimal C relays are rare, and I think what you’re
doing could be a great foundation for others to build on.

Keep going! This is already further than most folks get.

Cheers,
Melvin

Received on Wednesday, 23 April 2025 14:35:12 UTC