mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
Added extra regexp for reference types
This commit is contained in:
parent
159677a873
commit
7bbe49e8d0
2 changed files with 13 additions and 8 deletions
|
|
@ -96,6 +96,7 @@ type TypedDataDomain struct {
|
|||
}
|
||||
|
||||
var typedDataRegexp = regexp.MustCompile(`^((address|bool|bytes|string)|((bytes)([1-9]|[1-2][0-9]|3[0-2]))|((int|uint)(8|16|32|64|128|256)))(\[])?$`)
|
||||
var typedDataReferenceTypeRegexp = regexp.MustCompile(`^[A-Z](\w*)(\[])?$`)
|
||||
|
||||
// Sign receives a request and produces a signature
|
||||
|
||||
|
|
@ -747,15 +748,19 @@ func (types *Types) Validate() error {
|
|||
}
|
||||
firstChar := []rune(typeVal)[0]
|
||||
if unicode.IsUpper(firstChar) {
|
||||
if (*types)[typeVal] == nil {
|
||||
return fmt.Errorf("referenced type '%s' is undefined", typeVal)
|
||||
if (*types)[typeVal] != nil {
|
||||
if !typedDataReferenceTypeRegexp.MatchString(typeVal) {
|
||||
return fmt.Errorf("unknown reference type '%s", typeVal)
|
||||
}
|
||||
} else {
|
||||
return fmt.Errorf("reference type '%s' is undefined", typeVal)
|
||||
}
|
||||
} else {
|
||||
if !typedDataRegexp.MatchString(typeVal) {
|
||||
if (*types)[typeVal] != nil {
|
||||
return fmt.Errorf("referenced type '%s' must be capitalized", typeVal)
|
||||
return fmt.Errorf("reference type '%s' must be capitalized", typeVal)
|
||||
} else {
|
||||
return fmt.Errorf("unknown atomic type '%s'", typeVal)
|
||||
return fmt.Errorf("unknown type '%s'", typeVal)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -463,8 +463,8 @@ func TestMalformedData2(t *testing.T) {
|
|||
|
||||
malformedTypedData.Types["Mail"][2]["type"] = "Blahonga"
|
||||
err = malformedTypedData.Validate()
|
||||
if err == nil || err.Error() != "referenced type 'Blahonga' is undefined" {
|
||||
t.Fatalf("Expected `referenced type 'Blahonga' is undefined`, got %v", err)
|
||||
if err == nil || err.Error() != "reference type 'Blahonga' is undefined" {
|
||||
t.Fatalf("Expected `reference type 'Blahonga' is undefined`, got %v", err)
|
||||
}
|
||||
_, err = malformedTypedData.HashStruct(malformedTypedData.PrimaryType, malformedTypedData.Message)
|
||||
if err == nil || err.Error() != "unrecognized type 'Blahonga'" {
|
||||
|
|
@ -555,8 +555,8 @@ func TestMalformedData3(t *testing.T) {
|
|||
t.Fatalf("unmarshalling failed %v", err)
|
||||
}
|
||||
err = malformedTypedData.Validate()
|
||||
if err == nil || err.Error() != "unknown atomic type 'uint256 ... and now for something completely different'" {
|
||||
t.Fatalf("Expected `unknown atomic type 'uint256 ... and now for something completely different'`, got %v", err)
|
||||
if err == nil || err.Error() != "unknown type 'uint256 ... and now for something completely different'" {
|
||||
t.Fatalf("Expected `unknown type 'uint256 ... and now for something completely different'`, got %v", err)
|
||||
}
|
||||
|
||||
malformedTypedData.Types["EIP712Domain"][2]["type"] = "uint256"
|
||||
|
|
|
|||
Loading…
Reference in a new issue