From 0a53b52ee10539264fa4830d95c844ac813222cc Mon Sep 17 00:00:00 2001 From: Dionysos <75300347+ice-dionysos@users.noreply.github.com> Date: Mon, 16 Dec 2024 10:00:49 +0100 Subject: [PATCH] nip42: add external signature validator support --- nip42/nip42.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/nip42/nip42.go b/nip42/nip42.go index 2c05dbc..104aa2b 100644 --- a/nip42/nip42.go +++ b/nip42/nip42.go @@ -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 } @@ -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 }