From 62d31434ddbadff18580826576e1169f539e23f0 Mon Sep 17 00:00:00 2001 From: bndw Date: Fri, 13 Feb 2026 17:48:36 -0800 Subject: feat: add gRPC handler with event validation and publishing Handler implementation: - EventStore interface (consumer-side) - Server with PublishEvent, QueryEvents, CountEvents, PublishBatch - pb.Event <-> nostr.Event conversion helpers - Signature and ID validation using existing nostr package - Canonical JSON generation for storage 9 tests passing --- internal/handler/grpc/convert.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 internal/handler/grpc/convert.go (limited to 'internal/handler/grpc/convert.go') diff --git a/internal/handler/grpc/convert.go b/internal/handler/grpc/convert.go new file mode 100644 index 0000000..19505cd --- /dev/null +++ b/internal/handler/grpc/convert.go @@ -0,0 +1,40 @@ +package grpc + +import ( + pb "northwest.io/nostr-grpc/api/nostr/v1" + "northwest.io/nostr-grpc/internal/nostr" +) + +func NostrToPB(n *nostr.Event) *pb.Event { + tags := make([]*pb.Tag, len(n.Tags)) + for i, tag := range n.Tags { + tags[i] = &pb.Tag{Values: tag} + } + + return &pb.Event{ + Id: n.ID, + Pubkey: n.PubKey, + CreatedAt: n.CreatedAt, + Kind: int32(n.Kind), + Tags: tags, + Content: n.Content, + Sig: n.Sig, + } +} + +func PBToNostr(e *pb.Event) *nostr.Event { + tags := make(nostr.Tags, len(e.Tags)) + for i, tag := range e.Tags { + tags[i] = tag.Values + } + + return &nostr.Event{ + ID: e.Id, + PubKey: e.Pubkey, + CreatedAt: e.CreatedAt, + Kind: int(e.Kind), + Tags: tags, + Content: e.Content, + Sig: e.Sig, + } +} -- cgit v1.2.3