signer/core, signer/core/apitypes: fix encoding of bytes nested within array
This commit is contained in:
parent
2bf4a8ff73
commit
3490f3083f
|
@ -498,10 +498,19 @@ 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 ||
|
||||
reflect.TypeOf(item).Kind() == reflect.Array {
|
||||
encodedData, err := typedData.encodeArrayValue(item, parsedType, depth+1)
|
||||
var (
|
||||
encodedData hexutil.Bytes
|
||||
err error
|
||||
)
|
||||
if reflect.TypeOf(item).Elem().Kind() == reflect.Uint8 {
|
||||
encodedData, err = typedData.EncodePrimitiveValue(parsedType, item, depth+1)
|
||||
} else {
|
||||
encodedData, err = typedData.encodeArrayValue(item, parsedType, depth+1)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
package core
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/common/math"
|
||||
"github.com/ethereum/go-ethereum/signer/core/apitypes"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var typesStandard = apitypes.Types{
|
||||
"EIP712Domain": {
|
||||
{
|
||||
Name: "name",
|
||||
Type: "string",
|
||||
},
|
||||
{
|
||||
Name: "version",
|
||||
Type: "string",
|
||||
},
|
||||
{
|
||||
Name: "chainId",
|
||||
Type: "uint256",
|
||||
},
|
||||
{
|
||||
Name: "verifyingContract",
|
||||
Type: "address",
|
||||
},
|
||||
},
|
||||
"Val": {
|
||||
{
|
||||
Name: "field",
|
||||
Type: "bytes[][]",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var messageStandard = map[string]interface{}{
|
||||
"field": [][][]byte{{{1}, {2}}, {{3}, {4}}},
|
||||
}
|
||||
|
||||
var domainStandard = apitypes.TypedDataDomain{
|
||||
Name: "Ether Mail",
|
||||
Version: "1",
|
||||
ChainId: math.NewHexOrDecimal256(1),
|
||||
VerifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
|
||||
Salt: "",
|
||||
}
|
||||
|
||||
var typedData = apitypes.TypedData{
|
||||
Types: typesStandard,
|
||||
PrimaryType: "Val",
|
||||
Domain: domainStandard,
|
||||
Message: messageStandard,
|
||||
}
|
||||
|
||||
func TestEncodeDataRecursiveBytes(t *testing.T) {
|
||||
_, err := typedData.EncodeData(typedData.PrimaryType, typedData.Message, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("got err %v", err)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue