Files
nostrlib/nip46/nip46.go
2025-04-15 00:00:03 -03:00

57 lines
1.0 KiB
Go

package nip46
import (
"context"
"net/url"
"strings"
"fiatjaf.com/nostr"
jsoniter "github.com/json-iterator/go"
)
var json = jsoniter.ConfigFastest
type Request struct {
ID string `json:"id"`
Method string `json:"method"`
Params []string `json:"params"`
}
func (r Request) String() string {
j, _ := json.Marshal(r)
return string(j)
}
type Response struct {
ID string `json:"id"`
Error string `json:"error,omitempty"`
Result string `json:"result,omitempty"`
}
func (r Response) String() string {
j, _ := json.Marshal(r)
return string(j)
}
type Signer interface {
GetSession(client nostr.PubKey) (Session, bool)
HandleRequest(context.Context, *nostr.Event) (req Request, resp Response, eventResponse nostr.Event, err error)
}
func IsValidBunkerURL(input string) bool {
p, err := url.Parse(input)
if err != nil {
return false
}
if p.Scheme != "bunker" {
return false
}
if _, err := nostr.PubKeyFromHex(p.Host); err != nil {
return false
}
if !strings.Contains(p.RawQuery, "relay=") {
return false
}
return true
}