add individual value validator functions.

This commit is contained in:
Jay
2026-04-22 14:20:57 -04:00
parent 747781f5bf
commit 18586a9b18
+20 -3
View File
@@ -26,15 +26,15 @@ func Validate(e Event) error {
// ValidateStructure checks that all event fields conform to the protocol
// specification: hex lengths, tag structure, and field formats.
func ValidateStructure(e Event) error {
if !isLowerHex(e.PubKey, 64) {
if !IsValidKey(e.PubKey) {
return errors.MalformedPubKey
}
if !isLowerHex(e.ID, 64) {
if !IsValidID(e.ID) {
return errors.MalformedID
}
if !isLowerHex(e.Sig, 128) {
if !IsValidSig(e.Sig) {
return errors.MalformedSig
}
@@ -63,6 +63,23 @@ func ValidateSignature(e Event) error {
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
func checkIDMatch(e Event) ([]byte, error) {