const signTypedDataV4Verify = async () => {
const chainId = 1;
const msgParams = {
domain: {
chainId,
name: "Ether Mail",
verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
version: "1",
},
message: {
contents: "Hello, Bob!",
from: {
name: "Cow",
wallets: [
"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
"0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF",
],
},
to: [
{
name: "Bob",
wallets: [
"0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB",
"0xB0BdaBea57B0BDABeA57b0bdABEA57b0BDabEa57",
"0xB0B0b0b0b0b0B000000000000000000000000000",
],
},
],
},
primaryType: "Mail",
types: {
EIP712Domain: [
{ name: "name", type: "string" },
{ name: "version", type: "string" },
{ name: "chainId", type: "uint256" },
{ name: "verifyingContract", type: "address" },
],
Group: [
{ name: "name", type: "string" },
{ name: "members", type: "Person[]" },
],
Mail: [
{ name: "from", type: "Person" },
{ name: "to", type: "Person[]" },
{ name: "contents", type: "string" },
],
Person: [
{ name: "name", type: "string" },
{ name: "wallets", type: "address[]" },
],
},
};
try {
const from = web3.eth.getAccounts();
const sign =
"0xe5d78d669361f4c6e8ee3d4b10122bdd8b5147e1478d3b531722cd8901fff27b6715436fe18013e2acb7a978aba4bab98330d92caf2c6a5ad0525493d5d257111c";
const recoverTypedSignatureV4recoveredAddr = recoverTypedSignature({
data: msgParams,
signature: sign,
version: "V4",
});
const recoveredAddr = recoverTypedSignatureV4;
if (
web3.utils.toChecksumAddress(recoveredAddr.toString()) ===
web3.utils.toChecksumAddress(from[0])
) {
console.log(`Successfully verified signer as ${recoveredAddr}`);
console.log(recoveredAddr);
} else {
console.log(
`Failed to verify signer when comparing ${recoveredAddr} to ${from}`
);
}
} catch (err) {
console.error(err);
}
Bumped by Community user