MetaMask / MetaMask/eth-sig-util

Ether js signedTypeData & metamask sig utils signedTypeData_v4 producing different signature

Open
#236 3 comments 0 reactions 0 assignees View on GitHub
needs-investigation
Dominant language
TypeScript
Stars
583
Forks
228
Avg merge
11h 22m
Merged PRs (30d)
7

Description

```
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

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the signTypedData entry point in @metamask/eth-sig-util and compare it with ethers.Wallet._signTypedData using the provided domain, types, message, and private key. Reproduce both signatures and check recovery with Solidity ECDSA.recover; done means identifying the encoding difference or confirming compatible behavior and documenting or testing the result.

Written by the indexing model from the issue text.

Assessment

Tech stack
solidity, typescript
Domain
cryptography, security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.