Unverified Commit b2b14e6c authored by Natsu Kagami's avatar Natsu Kagami Committed by GitHub

signer/core: EIP-712 encoded data should not reject a Domain without a ChainId (#21306)

* Do not check for a non-nil ChainId

* Add encoding test
parent 290d6bd9
......@@ -965,11 +965,7 @@ func isPrimitiveTypeValid(primitiveType string) bool {
// validate checks if the given domain is valid, i.e. contains at least
// the minimum viable keys and values
func (domain *TypedDataDomain) validate() error {
if domain.ChainId == nil {
return errors.New("chainId must be specified according to EIP-155")
}
if len(domain.Name) == 0 && len(domain.Version) == 0 && len(domain.VerifyingContract) == 0 && len(domain.Salt) == 0 {
if domain.ChainId == nil && len(domain.Name) == 0 && len(domain.Version) == 0 && len(domain.VerifyingContract) == 0 && len(domain.Salt) == 0 {
return errors.New("domain is undefined")
}
......
......@@ -245,6 +245,10 @@ func TestDomainChainId(t *testing.T) {
if _, ok := withoutChainID.Domain.Map()["chainId"]; ok {
t.Errorf("Expected the chainId key to not be present in the domain map")
}
// should encode successfully
if _, err := withoutChainID.HashStruct("EIP712Domain", withoutChainID.Domain.Map()); err != nil {
t.Errorf("Expected the typedData to encode the domain successfully, got %v", err)
}
withChainID := core.TypedData{
Types: core.Types{
"EIP712Domain": []core.Type{
......@@ -261,6 +265,10 @@ func TestDomainChainId(t *testing.T) {
if _, ok := withChainID.Domain.Map()["chainId"]; !ok {
t.Errorf("Expected the chainId key be present in the domain map")
}
// should encode successfully
if _, err := withChainID.HashStruct("EIP712Domain", withChainID.Domain.Map()); err != nil {
t.Errorf("Expected the typedData to encode the domain successfully, got %v", err)
}
}
func TestHashStruct(t *testing.T) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment