mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-07-02 19:43:13 +02:00
Added some NIP-42 functionality to the client (relay.go) (#38)
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user