Documentation
¶
Overview ¶
Package validation provides event validation services for the ORLY relay. It handles structural validation (hex case, JSON format), cryptographic validation (signature, ID), and protocol validation (timestamp, NIP-70).
Index ¶
- func HasProtectedTag(ev *event.E) bool
- func ValidateLowercaseHexInJSON(msg []byte) string
- type Config
- type ReasonCode
- type Result
- func Blocked(msg string) Result
- func Error(msg string) Result
- func Invalid(msg string) Result
- func OK() Result
- func ValidateEventID(ev *event.E) Result
- func ValidateProtectedTagMatch(ev *event.E, authedPubkey []byte) Result
- func ValidateSignature(ev *event.E) Result
- func ValidateTimestamp(ev *event.E, maxFutureSeconds int64) Result
- type Service
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HasProtectedTag ¶
HasProtectedTag checks if an event has the NIP-70 protected tag.
func ValidateLowercaseHexInJSON ¶
ValidateLowercaseHexInJSON checks that all hex-encoded fields in the raw JSON are lowercase. NIP-01 specifies that hex encoding must be lowercase. This must be called on the raw message BEFORE unmarshaling, since unmarshal converts hex strings to binary and loses case information. Returns an error message if validation fails, or empty string if valid.
Types ¶
type Config ¶
type Config struct {
// MaxFutureSeconds is how far in the future a timestamp can be (default: 3600 = 1 hour)
MaxFutureSeconds int64
}
Config holds configuration for the validation service.
type ReasonCode ¶
type ReasonCode int
ReasonCode identifies the type of validation failure for response formatting.
const ( ReasonNone ReasonCode = iota ReasonBlocked ReasonInvalid ReasonError )
type Result ¶
type Result struct {
Valid bool
Code ReasonCode // For response formatting
Msg string // Human-readable error message
}
Result contains the outcome of a validation check.
func ValidateEventID ¶
ValidateEventID checks that the event ID matches the computed hash.
func ValidateProtectedTagMatch ¶
ValidateProtectedTagMatch checks NIP-70 protected tag requirements. Events with the "-" tag can only be published by users authenticated with the same pubkey as the event author.
func ValidateSignature ¶
ValidateSignature verifies the event signature.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service implements the Validator interface.
func NewWithConfig ¶
NewWithConfig creates a new validation service with the given configuration.
func (*Service) ValidateEvent ¶
ValidateEvent validates an unmarshaled event.
func (*Service) ValidateProtectedTag ¶
ValidateProtectedTag checks NIP-70 protected tag requirements.
type Validator ¶
type Validator interface {
// ValidateRawJSON validates raw message before unmarshaling.
// This catches issues like uppercase hex that are lost after unmarshal.
ValidateRawJSON(msg []byte) Result
// ValidateEvent validates an unmarshaled event.
// Checks ID computation, signature, and timestamp.
ValidateEvent(ev *event.E) Result
// ValidateProtectedTag checks NIP-70 protected tag requirements.
// The authedPubkey is the authenticated pubkey of the connection.
ValidateProtectedTag(ev *event.E, authedPubkey []byte) Result
}
Validator validates events before processing.
Source Files
¶
- hex.go
- protected.go
- signature.go
- timestamp.go
- validation.go