From e4bbebdd8f9ffae6c0dfa4218f5c5811c476e8b4 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Fri, 24 Oct 2025 00:18:02 -0300 Subject: [PATCH] compile-time check for json.Marshaler and json.Unmarshaler. --- keys.go | 6 ++++++ types.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/keys.go b/keys.go index 3256116..ab7c9b2 100644 --- a/keys.go +++ b/keys.go @@ -3,6 +3,7 @@ package nostr import ( "crypto/rand" "encoding/hex" + stdjson "encoding/json" "fmt" "io" "strings" @@ -65,6 +66,11 @@ var ZeroPK = PubKey{} type PubKey [32]byte +var ( + _ stdjson.Marshaler = PubKey{} + _ stdjson.Unmarshaler = (*PubKey)(nil) +) + func (pk PubKey) String() string { return "pk::" + pk.Hex() } func (pk PubKey) Hex() string { return hex.EncodeToString(pk[:]) } func (pk PubKey) MarshalJSON() ([]byte, error) { diff --git a/types.go b/types.go index 05befc2..6149f97 100644 --- a/types.go +++ b/types.go @@ -2,6 +2,7 @@ package nostr import ( "encoding/hex" + stdjson "encoding/json" "fmt" "unsafe" ) @@ -17,6 +18,11 @@ var ZeroID = ID{} // ID represents an event id type ID [32]byte +var ( + _ stdjson.Marshaler = ID{} + _ stdjson.Unmarshaler = (*ID)(nil) +) + func (id ID) String() string { return "id::" + id.Hex() } func (id ID) Hex() string { return hex.EncodeToString(id[:]) }