Skip to content

Commit

Permalink
nip42: add external signature validator support
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-dionysos committed Dec 16, 2024
1 parent 7724cf0 commit 0a53b52
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions nip42/nip42.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func parseURL(input string) (*url.URL, error) {

// ValidateAuthEvent checks whether event is a valid NIP-42 event for given challenge and relayURL.
// The result of the validation is encoded in the ok bool.
func ValidateAuthEvent(event *nostr.Event, challenge string, relayURL string) (pubkey string, ok bool) {
func ValidateAuthEvent(event *nostr.Event, challenge string, relayURL string, verifier func(*nostr.Event) (bool, error)) (pubkey string, ok bool) {
if event.Kind != nostr.KindClientAuthentication {
return "", false
}
Expand Down Expand Up @@ -66,7 +66,12 @@ func ValidateAuthEvent(event *nostr.Event, challenge string, relayURL string) (p

// save for last, as it is most expensive operation
// no need to check returned error, since ok == true implies err == nil.
if ok, _ := event.CheckSignature(); !ok {
if verifier == nil {
verifier = func(event *nostr.Event) (bool, error) {
return event.CheckSignature()
}
}
if ok, _ := verifier(event); !ok {
return "", false
}

Expand Down

0 comments on commit 0a53b52

Please sign in to comment.