go-nostr/nip46/nip46.go

43 lines
876 B
Go
Raw Permalink Normal View History

2024-01-09 16:55:00 -03:00
package nip46
import (
"context"
2024-01-09 16:55:00 -03:00
"encoding/json"
2024-03-01 15:54:28 -03:00
"regexp"
2024-01-09 16:55:00 -03:00
"github.com/nbd-wtf/go-nostr"
)
2024-03-01 15:54:28 -03:00
var BUNKER_REGEX = regexp.MustCompile(`^bunker:\/\/([0-9a-f]{64})\??([?\/\w:.=&%]*)$`)
2024-01-09 16:55:00 -03:00
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)
}
2024-01-09 16:55:00 -03:00
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)
}
2024-01-09 16:55:00 -03:00
type Signer interface {
GetSession(clientPubkey string) (Session, bool)
HandleRequest(context.Context, *nostr.Event) (req Request, resp Response, eventResponse nostr.Event, err error)
2024-01-09 16:55:00 -03:00
}
2024-03-01 15:54:28 -03:00
func IsValidBunkerURL(input string) bool {
return BUNKER_REGEX.MatchString(input)
}