1 Commits

Author SHA1 Message Date
jay 29ba275293 add individual value validator functions. 2026-04-22 14:20:57 -04:00
+20 -3
View File
@@ -26,15 +26,15 @@ func Validate(e Event) error {
// ValidateStructure checks that all event fields conform to the protocol // ValidateStructure checks that all event fields conform to the protocol
// specification: hex lengths, tag structure, and field formats. // specification: hex lengths, tag structure, and field formats.
func ValidateStructure(e Event) error { func ValidateStructure(e Event) error {
if !isLowerHex(e.PubKey, 64) { if !IsValidKey(e.PubKey) {
return errors.MalformedPubKey return errors.MalformedPubKey
} }
if !isLowerHex(e.ID, 64) { if !IsValidID(e.ID) {
return errors.MalformedID return errors.MalformedID
} }
if !isLowerHex(e.Sig, 128) { if !IsValidSig(e.Sig) {
return errors.MalformedSig return errors.MalformedSig
} }
@@ -63,6 +63,23 @@ func ValidateSignature(e Event) error {
return validateSignatureBytes(idBytes, e.Sig, e.PubKey) return validateSignatureBytes(idBytes, e.Sig, e.PubKey)
} }
// Value validators
// IsValidKey verifies that a public or private key is properly formatted.
func IsValidKey(value string) bool {
return isLowerHex(value, 64)
}
// IsValidKey verifies that an event id is properly formatted.
func IsValidID(value string) bool {
return isLowerHex(value, 64)
}
// IsValidKey verifies that an event signature is properly formatted.
func IsValidSig(value string) bool {
return isLowerHex(value, 128)
}
// Helpers // Helpers
func checkIDMatch(e Event) ([]byte, error) { func checkIDMatch(e Event) ([]byte, error) {