Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ether js signedTypeData & metamask sig utils signedTypeData_v4 producing different signature #236

Open
liho00 opened this issue Mar 22, 2022 · 2 comments

Comments

@liho00
Copy link

liho00 commented Mar 22, 2022

import {
  signTypedData,
} from "@metamask/eth-sig-util";
import { ethers } from "ethers";

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

const types = {
  Test: [
    { name: "Request", type: "string" },
  ],
};
const privateKey = Buffer.from(
  "myprivatekey",
  "hex"
);

Metamask sig utils SignTypedDataVersion.V4, (tested with SignTypedDataVersion.V3 same)

const signature = signTypedData({
  privateKey,
  data: {
    types,
    primaryType: "Test",
    domain,
    message: {
      Request: "This is a request"
    },
  },
  version: SignTypedDataVersion.V4,
});
console.log("Metamask sig utils generated signature", signature); 

Metamask sig utils generated signature 0x93f39c57d7f8de7b033367cb5fa7bb68c6a339b0626c73febc57fdce5a779a8472b365951470ade9857e8bd26a3020e9088c110c931abd188034cbdd1e79f8191c

ether js signTypedData

const wallet = new ethers.Wallet(privateKey);
wallet
  ._signTypedData(domain, types, {
      Request: "This is a request" 
  })
  .then((signature) => {
    console.log("Ether js _signTypedData", signature);
  });

Ether js _signTypedData 0x9655d8635d4826a1c44185acb34f7c86b286e90e70bd260626c8dd112ae8f5f348f75ce387544c1734971f6ae51ad855e98a49c7e56c3a636a90f714378aca0d1c

Is sig utils deprecated, but why both produce different result of signatures? I was confusing on why these both producing different signature, does it possible both lib produce same signature?

or there is some bug over here? because when i using solidity ECDSA.recover i able to recover address from ether js's signature but not sig utils' generated signature

@danfinlay
Copy link
Contributor

Sig util is not deprecated, it represents signing behavior in MetaMask in production today. Will require investigation to identify the deviation.

@wbt
Copy link
Contributor

wbt commented Aug 5, 2022

#106 looks like a likely cause

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants