From dd6d3c68fbefd085bfe28a2931581aae91abf9aa Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sun, 21 Dec 2025 19:53:24 -0300 Subject: [PATCH] nip05: be tolerant with invalid pubkeys in well-known response (skip them). --- nip05/nip05.go | 4 ++-- nip05/nip05_easyjson.go | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/nip05/nip05.go b/nip05/nip05.go index 727f0f0..79bff7a 100644 --- a/nip05/nip05.go +++ b/nip05/nip05.go @@ -8,7 +8,7 @@ import ( "strings" "fiatjaf.com/nostr" - jsoniter "github.com/json-iterator/go" + "github.com/mailru/easyjson" ) var NIP05_REGEX = regexp.MustCompile(`^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$`) @@ -77,7 +77,7 @@ func Fetch(ctx context.Context, fullname string) (resp WellKnownResponse, name s defer res.Body.Close() var result WellKnownResponse - if err := jsoniter.NewDecoder(res.Body).Decode(&result); err != nil { + if err := easyjson.UnmarshalFromReader(res.Body, &result); err != nil { return resp, name, fmt.Errorf("failed to decode json response: %w", err) } diff --git a/nip05/nip05_easyjson.go b/nip05/nip05_easyjson.go index a94f592..84a2b3f 100644 --- a/nip05/nip05_easyjson.go +++ b/nip05/nip05_easyjson.go @@ -54,11 +54,13 @@ func easyjsonDecode(in *jlexer.Lexer, out *WellKnownResponse) { err = errors.New("names[]{pubkey} must be a string") } else { data = data[1 : len(data)-1] - pk, err = nostr.PubKeyFromHex(unsafe.String(unsafe.SliceData(data), len(data))) + pk, _ = nostr.PubKeyFromHex(unsafe.String(unsafe.SliceData(data), len(data))) } in.AddError(err) } - out.Names[key] = pk + if pk != nostr.ZeroPK { + out.Names[key] = pk + } in.WantComma() } in.Delim('}') @@ -81,7 +83,7 @@ func easyjsonDecode(in *jlexer.Lexer, out *WellKnownResponse) { err = errors.New("relays[pubkey] must be a string") } else { data = data[1 : len(data)-1] - key, err = nostr.PubKeyFromHex(unsafe.String(unsafe.SliceData(data), len(data))) + key, _ = nostr.PubKeyFromHex(unsafe.String(unsafe.SliceData(data), len(data))) } in.AddError(err) } @@ -107,7 +109,9 @@ func easyjsonDecode(in *jlexer.Lexer, out *WellKnownResponse) { } in.Delim(']') } - out.Relays[key] = relays + if key != nostr.ZeroPK { + out.Relays[key] = relays + } in.WantComma() } in.Delim('}') @@ -130,7 +134,7 @@ func easyjsonDecode(in *jlexer.Lexer, out *WellKnownResponse) { err = errors.New("nip46[pubkey] must be a string") } else { data = data[1 : len(data)-1] - key, err = nostr.PubKeyFromHex(unsafe.String(unsafe.SliceData(data), len(data))) + key, _ = nostr.PubKeyFromHex(unsafe.String(unsafe.SliceData(data), len(data))) } in.AddError(err) } @@ -158,7 +162,9 @@ func easyjsonDecode(in *jlexer.Lexer, out *WellKnownResponse) { } in.Delim(']') } - out.NIP46[key] = bunkers + if key != nostr.ZeroPK { + out.NIP46[key] = bunkers + } in.WantComma() } in.Delim('}')