0

I need to create multiple eip712 signatures, which are not possible to create manually by accepting the metamask popups one by one.

Is there an alternative way of generating these signatures programatically?

Presently i am using the _signTypedData method of Signer object in ethers.js

I tried using eth_signTypedData JSON RPC while following the EIP712 on a infura node

curl -X POST --url https://celo-mainnet.infura.io/v3/895c273d61f4446f99b38bf444fc19f8 --data '{"jsonrpc":"2.0","method":"eth_signTypedData","params":["0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826", {"types":{"EIP712Domain":[{"name":"name","type":"string"},{"name":"version","type":"string"},{"name":"chainId","type":"uint256"},{"name":"verifyingContract","type":"address"}],"Person":[{"name":"name","type":"string"},{"name":"wallet","type":"address"}],"Mail":[{"name":"from","type":"Person"},{"name":"to","type":"Person"},{"name":"contents","type":"string"}]},"primaryType":"Mail","domain":{"name":"Ether Mail","version":"1","chainId":1,"verifyingContract":"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"},"message":{"from":{"name":"Cow","wallet":"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"},"to":{"name":"Bob","wallet":"0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"},"contents":"Hello, Bob!"}}],"id":1}'

but it seems it does not support the use of the eth_signTypedData method.

The following error is displayed on firing the above query:

{"jsonrpc":"2.0","id":1,"error":{"code":-32601,"message":"method 'eth_signTypedData' not found"}}

1 Answer 1

0

Eureka! i got the solution... So what i figured in the way was

  1. The infura, Moralis or any external node incase do not provides the eth_signTypedData method which is expected because it needs a signer
  2. Even running a geth client do not provides with the eth_signTypedData method

I used the metamask's eth-sig-util package, which generates the signatures using the private key of the user.

const {
  signTypedData,
  SignTypedDataVersion,
} = require("@metamask/eth-sig-util");

const domain = {
  name: "REIGNLABS", // contract deploy name
  version: "1", // contract deploy version
  chainId: 5, // env chain id
  verifyingContract: "0x23234234234...",
};

const types = {
  Struct: [
    { name: "id", type: "uint256" },
    { name: "_type", type: "uint256" },
    { name: "_address", type: "address" },
    { name: "_userAddresses", type: "string[]" },
  ],
  EIP712Domain: [
    { name: "name", type: "string" },
    { name: "version", type: "string" },
    { name: "chainId", type: "uint256" },
    { name: "verifyingContract", type: "address" },
  ],
};

const privateKey =
  "zassda21332453asdasd...";// your private key

const obj = {
  id: 1,
  _type: 0,
  _address: "0xsdfdgerfsd...",
  _userAddresses: [
    "0xasdad23asda...",
    "0xjsdasdasdas...",
  ],
};

const signature = signTypedData({
  privateKey,
  data: {
    types,
    primaryType: "Struct",
    domain,
    message: obj,
  },
  version: SignTypedDataVersion.V4,
});

console.log(signature);

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.