utils

package
v0.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2026 License: Unlicense Imports: 19 Imported by: 0

Documentation

Overview

Package utils holds small helpers shared across this SDK's NIP and relay packages: event/tag validation, key management, NIP-05/LUD-16 URL helpers, logging, and LNURL decoding. It has no NIP of its own — it exists to avoid duplicating this plumbing in every package that needs it.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTagNotFound  = errors.New("tag not found")
	ErrTagNotUnique = errors.New("multiple tags with the same name found")
)

Functions

func EscapeJSONString

func EscapeJSONString(s string) string

func FindUniqueEventTag

func FindUniqueEventTag(tags [][]string, tagName string) ([]string, error)

func FindUniqueEventTagValue

func FindUniqueEventTagValue(tags [][]string, tagName string) (string, error)

func GetDomainOnly

func GetDomainOnly(id string) string

GetDomainOnly extracts the domain from a NIP-05 or LUD-16 identifier.

func GetFullHTTPURL

func GetFullHTTPURL(r *http.Request) string

GetFullHTTPURL recreates the absolute URL string from an incoming HTTP request to strictly validate exactly what the client signed for NIP-98 matching.

func GetLud16URL

func GetLud16URL(lud16 string) string

GetLud16URL returns the URL to fetch the LNURL-pay JSON for a given LUD-16 identifier.

func GetNip05URL

func GetNip05URL(nip05 string) string

GetNip05URL returns the URL to fetch the NIP-05 JSON for a given identifier.

func GetPublicKey

func GetPublicKey(privKeyHex string) (string, error)

func InitLogger

func InitLogger()

InitLogger points the process-global zerolog logger at a colored console writer. It's a convenience for standalone-binary consumers and must only be called explicitly from a main()/cmd entrypoint -- never from a package init(), which would silently reconfigure global logging state as an import side effect for every consumer of that package.

func IsValidPictureURL

func IsValidPictureURL(u string) bool

IsValidPictureURL performs a basic check to see if a string looks like a valid HTTP or HTTPS URL.

func LookupEventTag

func LookupEventTag(tags [][]string, tagName string) ([][]string, bool)

func MarshalTags

func MarshalTags(tags [][]string) ([]byte, error)

func ParseATag

func ParseATag(tag string) (kind int, pubKey, dValue string, err error)

func RecoverPanic

func RecoverPanic(logger zerolog.Logger)

RecoverPanic recovers a panic in the calling goroutine and logs it with a stack trace through logger. It intentionally does not re-panic or terminate the process: callers defer this specifically to contain a panic to the one goroutine (e.g. a single client session) without taking down the whole embedding application.

func UnmarshalJSON

func UnmarshalJSON(data []byte, v interface{}) error

UnmarshalJSON inlines a simple JSON unmarshaler and handles errors.

func Validate32Key

func Validate32Key(hexStr string) error

func ValidateEventTags

func ValidateEventTags(tags [][]string) error

func ValidateFilterTag

func ValidateFilterTag(name string, vals []string) error

func ValidateFilterTags

func ValidateFilterTags(tags map[string][]string) error

func ValidateIndexableTag

func ValidateIndexableTag(name string) error

func ValidateKind

func ValidateKind(kind int) error

func ValidateLNURL

func ValidateLNURL(lnurlStr string) error

ValidateLNURL decodes a bech32 LNURL string and validates the resulting URL.

func ValidateStrKind

func ValidateStrKind(skind string) (int, error)

func VerifyNip05

func VerifyNip05(r io.Reader, pubkey, nip05 string) bool

VerifyNip05 parses the NIP-05 response and checks if the given pubkey matches the name.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL