Metamask: solidity cannot verify ethers.js signed data (signTypedData)

Metamask Error: Verifying Signed Data with Ether.js Sigtypeddata

When using the ethers.js library to sign and and code data as a signed typed dates, solidity’s metamask may encounter an error that prevents it from verifying the signed data. In this article, We’ll Explore the Issue and Provide a Possible Solution.

The issue:

The error typically occurs when attempting to verify the signed data using metamask’s verify function on theSigtypeddates Property Returned by Ethers.js. The Problem Lies in How Solidity’s Sigtypeddates function interacts with the ethers.js library and theverify method.

Sign TypeDates Functionality

When you call Sigtypeddates on your data, it creates a signature of the input data using the signer’s private key. However, when verifying this signed data in Metamask Using Verify, the Library Expects to Receive the Original Unaltered Input Data As An Argument.

ethers.js sign type dates

The Signtypeddata function is designed to create and verify a signature of the input data without altering it. To use Sigtypeddates with ethers.js, you need to create a signed version of your input data that can be verified by the library.

For Example:

`Javascript

Const Domain = {

Name: ‘OG-NFT’,

Version: ‘1’

};

Constations = {

// …

};

// Create a Signed Version of the Data Using Ethers.js Sigtypeddata

Constatature = Await ethers.sigtypeddata (

{

type,

Value: {

OG_NFT: {…} // Replace With Your Actual Input Data

}

},

‘0x …’ // Replace with your private key

);

// create a signed type dates from the signed data

Const Sigtypeddata = Ethers.Signer.Sigtypeddata (Signature, Domain);

`

In This Example, We First Create A Signature Object Using Ethers.js’sSigtypeddata "function. We then use this signature to create a typed data object, which is used for verification.

Metamask Verification Issue

Now that you have the signed type dates object in place, you can attempt to verify it in metamask. However, As Mentioned Earlier, Metamask'sVerifyfunction expects the original unaltered input data as an argument.

To fix this issue, you need to create a new typed data object with the same property and value as your original input data. In other words, you need to recreation the original input data using ethers.js.

Javascript

// Create a new Typed Data Object From the Signed Type Dates

const verification = ethers.signer.verifyyTyped (

Sigtyped dates,

Domain,

{Type: ‘Unverify’} // Replace with Your Private Key

);

// Verify the Typed Data Using Metamask’s Verify Function

await metamask.verify (verification);

`

In this example, we create a new verification 'object by calling ethers.js's verifyTypedfunction on the signed typing dates. We then pass the original input data (domain) and a verification key (which can be obtained using ethers.js).

By recreation the original input data using ethers.js, you should now be able to verify the signed data in metamask.

Conclusion

In this article, we've explored the issue of verifying signed typed dates using metamask with ethers.js. By understanding How Solidity'sSigtypeddates` function interacts with ethers.js and creating a new typed data object from the signed data, you should be able to resolve the error and verify your signed data in metamask.

ETHEREUM CGMINER FREEZES INTERVALS

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *