diff --git a/signer/core/apitypes/types.go b/signer/core/apitypes/types.go index b56931c1d18b..bdf85c8ac323 100644 --- a/signer/core/apitypes/types.go +++ b/signer/core/apitypes/types.go @@ -498,8 +498,15 @@ func (typedData *TypedData) encodeArrayValue(encValue interface{}, encType strin arrayBuffer := new(bytes.Buffer) parsedType := strings.Split(encType, "[")[0] + for _, item := range arrayValue { - if reflect.TypeOf(item).Kind() == reflect.Slice || + if parsedType == "bytes" { + bytesValue, err := typedData.EncodePrimitiveValue(parsedType, item, depth) + if err != nil { + return nil, err + } + arrayBuffer.Write(bytesValue) + } else if reflect.TypeOf(item).Kind() == reflect.Slice || reflect.TypeOf(item).Kind() == reflect.Array { encodedData, err := typedData.encodeArrayValue(item, parsedType, depth+1) if err != nil { diff --git a/signer/core/apitypes/types_test.go b/signer/core/apitypes/types_test.go index 22bbeba19ec4..81ecd6a14c2c 100644 --- a/signer/core/apitypes/types_test.go +++ b/signer/core/apitypes/types_test.go @@ -22,6 +22,7 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto/kzg4844" "github.com/holiman/uint256" @@ -233,3 +234,36 @@ func TestType_TypeName(t *testing.T) { } } } + +func TestEncodeNestedBytesArray(t *testing.T) { + typedData := TypedData{ + Types: Types{ + "EIP712Domain": []Type{ + {Name: "name", Type: "string"}, + {Name: "version", Type: "string"}, + }, + "Test": []Type{ + {Name: "data", Type: "bytes[]"}, + }, + }, + PrimaryType: "Test", + Domain: TypedDataDomain{ + Name: "TestDomain", + Version: "1", + }, + Message: map[string]interface{}{ + "data": []interface{}{ + hexutil.MustDecode("0x1234"), + hexutil.MustDecode("0x5678"), + }, + }, + } + + hash, _, err := TypedDataAndHash(typedData) + if err != nil { + t.Fatalf("Failed to hash struct with nested bytes array: %v", err) + } + if hash == nil { + t.Error("Hash is nil") + } +}