Added some NIP-42 functionality to the client (relay.go) (#38)

This commit is contained in:
barkyq
2023-01-16 06:27:11 -05:00
committed by GitHub
parent 9775016bf1
commit 87b6280299
5 changed files with 139 additions and 24 deletions

View File

@ -7,6 +7,23 @@ import (
"github.com/nbd-wtf/go-nostr"
)
// CreateUnsignedAuthEvent creates an event which should be sent via an "AUTH" command.
// If the authentication succeeds, the user will be authenticated as pubkey.
func CreateUnsignedAuthEvent(challenge, pubkey, relayURL string) nostr.Event {
return nostr.Event{
PubKey: pubkey,
CreatedAt: time.Now(),
Kind: 22242,
Tags: nostr.Tags{
nostr.Tag{"relay", relayURL},
nostr.Tag{"challenge", challenge},
},
Content: "",
}
}
// 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) {
if ok, _ := event.CheckSignature(); ok == false {
return "", false