3


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",
        },

    },

}

type Message struct {
    Users []string
    Amounts []string
    User string
    Nonce string
    Deadline string
}


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
}

I use the function Sign ,but report an error data '[0x111da67948Ef5Ed1f82D707B8cd7e3B1DFa87AEa]' doesn't match type 'address[]' ,can someone show me a demo,thanks

1 Answer 1

0

try changing the array type to []interface{}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.