From c179e4612ca5b7048cdbcacce81da712a04ffc83 Mon Sep 17 00:00:00 2001 From: thomaspanf Date: Sun, 14 Jul 2024 15:54:48 -0700 Subject: [PATCH] Add ValidateSignature helper function --- utils/input/validation.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/utils/input/validation.go b/utils/input/validation.go index fa67d82..94b8782 100644 --- a/utils/input/validation.go +++ b/utils/input/validation.go @@ -83,6 +83,18 @@ func ValidateAddress(name, value string) (common.Address, error) { return common.HexToAddress(value), nil } +// Validate an EIP-712 signature +func ValidateSignature(name, signature string) (string, error) { + if len(signature) != 132 || signature[:2] != "0x" { + return "", fmt.Errorf("Invalid %s, '%s'\n", name, signature) + } + signatureTruncated := signature[2:] + if !regexp.MustCompile("^[A-Fa-f0-9]+$").MatchString(signatureTruncated) { + return "", fmt.Errorf("Invalid %s, '%s'\n", name, signature) + } + return signature, nil +} + // Validate a wei amount func ValidateWeiAmount(name, value string) (*big.Int, error) { val := new(big.Int)