nip05: be tolerant with invalid pubkeys in well-known response (skip them).
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"fiatjaf.com/nostr"
|
"fiatjaf.com/nostr"
|
||||||
jsoniter "github.com/json-iterator/go"
|
"github.com/mailru/easyjson"
|
||||||
)
|
)
|
||||||
|
|
||||||
var NIP05_REGEX = regexp.MustCompile(`^(?:([\w.+-]+)@)?([\w_-]+(\.[\w_-]+)+)$`)
|
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()
|
defer res.Body.Close()
|
||||||
|
|
||||||
var result WellKnownResponse
|
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)
|
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")
|
err = errors.New("names[]{pubkey} must be a string")
|
||||||
} else {
|
} else {
|
||||||
data = data[1 : len(data)-1]
|
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)
|
in.AddError(err)
|
||||||
}
|
}
|
||||||
out.Names[key] = pk
|
if pk != nostr.ZeroPK {
|
||||||
|
out.Names[key] = pk
|
||||||
|
}
|
||||||
in.WantComma()
|
in.WantComma()
|
||||||
}
|
}
|
||||||
in.Delim('}')
|
in.Delim('}')
|
||||||
@@ -81,7 +83,7 @@ func easyjsonDecode(in *jlexer.Lexer, out *WellKnownResponse) {
|
|||||||
err = errors.New("relays[pubkey] must be a string")
|
err = errors.New("relays[pubkey] must be a string")
|
||||||
} else {
|
} else {
|
||||||
data = data[1 : len(data)-1]
|
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)
|
in.AddError(err)
|
||||||
}
|
}
|
||||||
@@ -107,7 +109,9 @@ func easyjsonDecode(in *jlexer.Lexer, out *WellKnownResponse) {
|
|||||||
}
|
}
|
||||||
in.Delim(']')
|
in.Delim(']')
|
||||||
}
|
}
|
||||||
out.Relays[key] = relays
|
if key != nostr.ZeroPK {
|
||||||
|
out.Relays[key] = relays
|
||||||
|
}
|
||||||
in.WantComma()
|
in.WantComma()
|
||||||
}
|
}
|
||||||
in.Delim('}')
|
in.Delim('}')
|
||||||
@@ -130,7 +134,7 @@ func easyjsonDecode(in *jlexer.Lexer, out *WellKnownResponse) {
|
|||||||
err = errors.New("nip46[pubkey] must be a string")
|
err = errors.New("nip46[pubkey] must be a string")
|
||||||
} else {
|
} else {
|
||||||
data = data[1 : len(data)-1]
|
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)
|
in.AddError(err)
|
||||||
}
|
}
|
||||||
@@ -158,7 +162,9 @@ func easyjsonDecode(in *jlexer.Lexer, out *WellKnownResponse) {
|
|||||||
}
|
}
|
||||||
in.Delim(']')
|
in.Delim(']')
|
||||||
}
|
}
|
||||||
out.NIP46[key] = bunkers
|
if key != nostr.ZeroPK {
|
||||||
|
out.NIP46[key] = bunkers
|
||||||
|
}
|
||||||
in.WantComma()
|
in.WantComma()
|
||||||
}
|
}
|
||||||
in.Delim('}')
|
in.Delim('}')
|
||||||
|
|||||||
Reference in New Issue
Block a user