Skip to content

Different signTypedData results between 5.1.0 and 6.0.1 #340

@vvvvvv1vvvvvv

Description

@vvvvvv1vvvvvv

Typed Message

{
  types: {
    SafeTx: [
      { type: "address", name: "to" },
      { type: "uint256", name: "value" },
      { type: "bytes", name: "data" },
      { type: "uint8", name: "operation" },
      { type: "uint256", name: "safeTxGas" },
      { type: "uint256", name: "baseGas" },
      { type: "uint256", name: "gasPrice" },
      { type: "address", name: "gasToken" },
      { type: "address", name: "refundReceiver" },
      { type: "uint256", name: "nonce" },
    ],
    EIP712Domain: [
      { name: "chainId", type: "uint256" },
      { name: "verifyingContract", type: "address" },
    ],
  },
  domain: {
    chainId: "1",
    verifyingContract: "0xb023c11fbcbd0f8d02c85a7cf51a1eab085e6d67",
  },
  primaryType: "SafeTx",
  message: {
    to: "0xf5d5b661f9c3d8b5244f00ef25cf25b61f5a1f7d",
    value: "100000000000000",
    data: "0x",
    operation: "0",
    safeTxGas: "0",
    baseGas: "0",
    gasPrice: "0",
    gasToken: "0x0000000000000000000000000000000000000000",
    refundReceiver: "0x0000000000000000000000000000000000000000",
    nonce: "18",
  },
}

Private Key(empty test address)

7d0ebc17b57137adc429b3f51bf5803fa61e3cd1050e9520d05ed5bcafbcff18

Code example

const utils = require("@metamask/eth-sig-util");

const data = {
  types: {
    SafeTx: [
      { type: "address", name: "to" },
      { type: "uint256", name: "value" },
      { type: "bytes", name: "data" },
      { type: "uint8", name: "operation" },
      { type: "uint256", name: "safeTxGas" },
      { type: "uint256", name: "baseGas" },
      { type: "uint256", name: "gasPrice" },
      { type: "address", name: "gasToken" },
      { type: "address", name: "refundReceiver" },
      { type: "uint256", name: "nonce" },
    ],
    EIP712Domain: [
      { name: "chainId", type: "uint256" },
      { name: "verifyingContract", type: "address" },
    ],
  },
  domain: {
    chainId: "1",
    verifyingContract: "0xb023c11fbcbd0f8d02c85a7cf51a1eab085e6d67",
  },
  primaryType: "SafeTx",
  message: {
    to: "0xf5d5b661f9c3d8b5244f00ef25cf25b61f5a1f7d",
    value: "100000000000000",
    data: "0x",
    operation: "0",
    safeTxGas: "0",
    baseGas: "0",
    gasPrice: "0",
    gasToken: "0x0000000000000000000000000000000000000000",
    refundReceiver: "0x0000000000000000000000000000000000000000",
    nonce: "18",
  },
};

const pk = Buffer.from(
  "7d0ebc17b57137adc429b3f51bf5803fa61e3cd1050e9520d05ed5bcafbcff18",
  "hex"
);

const sig = utils.signTypedData({
  privateKey: pk,
  data,
  version: utils.SignTypedDataVersion.V4,
});

console.log("sig", sig);

Result

in v5.1.0, result is 0xb0e34cee18e7ded5fda0cc248f540e003b676a6a24336121df89ead770357334072f6fb61ceb4d840755a497fa8623e0a7404342f7eee7d439bbdaa5c86fbd321c

in versions later than v6.0.1, result is 0xc197219c9b3b41df23f8d52cb5afe2208437f07527c29fbd49af6665f0ef752c1c17c85f758e625bf09e973bf6122e9794687d7e35e03b6ffff04bed973c3b5b1b

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions