var Types = core.Types{
"EIP712Domain": {
{
Name: "name",
Type: "string",
},
{
Name: "version",
Type: "string",
},
{
Name: "chainId",
Type: "uint256",
},
{
Name: "verifyingContract",
Type: "address",
},
},
"Claim": {
{
Name: "users",
Type: "address[]",
},
{
Name: "amounts",
Type: "uint256[]",
},
{
Name: "user",
Type: "address",
},
{
Name: "nonce",
Type: "uint256",
},
{
Name: "deadline",
Type: "uint256",
},
},
}
func Sign(key *ecdsa.PrivateKey, data *core.TypedData) (hexutil.Bytes, error) {
domainSeparator, err := data.HashStruct("EIP712Domain", data.Domain.Map())
if err != nil {
return nil, err
}
typedDataHash, err := data.HashStruct(data.PrimaryType, data.Message)
if err != nil {
return nil, err
}
rawData := []byte(fmt.Sprintf("\x19\x01%s%s", string(domainSeparator), string(typedDataHash)))
dataHash := crypto.Keccak256(rawData)
signature, err := crypto.Sign(dataHash, key)
if err != nil {
return nil, err
}
if signature[64] < 27 {
signature[64] += 27
}
return signature, nil
}
type Message struct {
Users []string
Amounts []string
User string
Nonce string
Deadline string
}
contents := utils.Message{
Users: []string {"0x111da67948Ef5Ed1f82D707B8cd7e3B1DFa87AEa"},
Amounts: []string{"1"},
User: address,
Nonce: nonce,
Deadline: strconv.Itoa(int(duration)),
}
之前签过单个数据类型的比如address,uint256这样的,但是上面这个里面有address[]数组类型的,用下面的方发签名失败,报错data '[0x111da67948Ef5Ed1f82D707B8cd7e3B1DFa87AEa]' doesn't match type 'address[]'
数据类型不匹配,那应该怎么写实匹配的呢