2023-08-10 14:32:11 -03:00
|
|
|
package khatru
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-10-03 08:32:07 -03:00
|
|
|
"hash/maphash"
|
2023-08-10 14:32:11 -03:00
|
|
|
"regexp"
|
2023-10-03 08:32:07 -03:00
|
|
|
"unsafe"
|
2023-08-10 14:32:11 -03:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
AUTH_CONTEXT_KEY = iota
|
|
|
|
WS_KEY = iota
|
|
|
|
)
|
|
|
|
|
|
|
|
var nip20prefixmatcher = regexp.MustCompile(`^\w+: `)
|
|
|
|
|
|
|
|
func GetConnection(ctx context.Context) *WebSocket {
|
|
|
|
return ctx.Value(WS_KEY).(*WebSocket)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetAuthed(ctx context.Context) string {
|
|
|
|
authedPubkey := ctx.Value(AUTH_CONTEXT_KEY)
|
|
|
|
if authedPubkey == nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return authedPubkey.(string)
|
|
|
|
}
|
2023-10-03 08:32:07 -03:00
|
|
|
|
|
|
|
func pointerHasher[V any](_ maphash.Seed, k *V) uint64 { return uint64(uintptr(unsafe.Pointer(k))) }
|