Skip to content

Commit

Permalink
Add ValidateSignature helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaspanf committed Jul 14, 2024
1 parent ee195f1 commit c179e46
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions utils/input/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c179e46

Please sign in to comment.