From 940169828673df9eda412eca2d9f281edf65be7d Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Tue, 7 Jul 2020 14:46:25 -0400 Subject: [PATCH 1/2] Do not check for a non-nil ChainId --- signer/core/signed_data.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/signer/core/signed_data.go b/signer/core/signed_data.go index 26ad0b63ffff..fec464417a92 100644 --- a/signer/core/signed_data.go +++ b/signer/core/signed_data.go @@ -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") } From 59e7546dd5ea6c43392a22e407bfc0e5faf64696 Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Tue, 7 Jul 2020 14:50:49 -0400 Subject: [PATCH 2/2] Add encoding test --- signer/core/signed_data_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/signer/core/signed_data_test.go b/signer/core/signed_data_test.go index e5f478089040..ab5f2cc9627d 100644 --- a/signer/core/signed_data_test.go +++ b/signer/core/signed_data_test.go @@ -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) {