nip05: be tolerant with invalid pubkeys in well-known response (skip them).
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
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(']')
|
||||
}
|
||||
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(']')
|
||||
}
|
||||
if key != nostr.ZeroPK {
|
||||
out.NIP46[key] = bunkers
|
||||
}
|
||||
in.WantComma()
|
||||
}
|
||||
in.Delim('}')
|
||||
|
||||
Reference in New Issue
Block a user