ethers.js icon indicating copy to clipboard operation
ethers.js copied to clipboard

Negative values are not allowed when using signer._signTypedData

Open shinthom opened this issue 2 years ago • 0 comments

Ethers Version

5.6.6

Search Terms

negative value, sign

Describe the Problem

I tried to make a signature from Order data. But if the value(amount) is negative(positive value works), the code generates an error.

Code Snippet

const makeOrderSignature = async (
  { sender, priceX18, amount, expiration, nonce },
  { signer, verifyingContract }
) => {
  const domain = {
    name: "Vertex",
    version: "0.0.1",
    chainId: (await ethers.provider.getNetwork()).chainId,
    verifyingContract,
  };

  const types = {
    Order: [
      { name: "sender", type: "bytes32" },
      { name: "priceX18", type: "int128" },
      { name: "amount", type: "int128" },
      { name: "expiration", type: "uint64" },
      { name: "nonce", type: "uint64" },
    ],
  };

  const values = {
    sender,
    priceX18,
    amount,
    expiration,
    nonce,
  };

  return await signer._signTypedData(domain, types, values);
};

const amount = "-28000000000000000000";
const formattedAmount = BigInt(amount).toString();

const makerOrder = {
  sender:
    "0xe7bc6ad267915a757f2a0d75418bee0a2a99419d64656661756c740000000000",
  priceX18: "2005500000000000000000",
  amount: formattedAmount,
  expiration: "13835058056982624834",
  nonce: "1783062198220750950",
};

Contract ABI

No response

Errors

ProviderError: error encoding eip712 struct: "Failed to serialize serde JSON object"
    at HttpProvider.request


### Environment

node.js (v12 or newer), Hardhat

### Environment (Other)

_No response_

shinthom avatar Nov 27 '23 07:11 shinthom