compile-time check for json.Marshaler and json.Unmarshaler.

This commit is contained in:
fiatjaf
2025-10-24 00:18:02 -03:00
parent 588e415440
commit e4bbebdd8f
2 changed files with 12 additions and 0 deletions
+6
View File
@@ -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) {