fix: use ethers.utils.verifyTypedData
to verify signature
This commit is contained in:
parent
4b0d8c50fd
commit
2dfb5a0bc6
@ -8,12 +8,7 @@ import Column from "./components/Column";
|
|||||||
import Header from "./components/Header";
|
import Header from "./components/Header";
|
||||||
import Modal from "./components/Modal";
|
import Modal from "./components/Modal";
|
||||||
import { DEFAULT_MAIN_CHAINS, DEFAULT_TEST_CHAINS } from "./constants";
|
import { DEFAULT_MAIN_CHAINS, DEFAULT_TEST_CHAINS } from "./constants";
|
||||||
import {
|
import { AccountAction, getLocalStorageTestnetFlag, setLocaleStorageTestnetFlag } from "./helpers";
|
||||||
AccountAction,
|
|
||||||
eip712,
|
|
||||||
getLocalStorageTestnetFlag,
|
|
||||||
setLocaleStorageTestnetFlag,
|
|
||||||
} from "./helpers";
|
|
||||||
import Toggle from "./components/Toggle";
|
import Toggle from "./components/Toggle";
|
||||||
import RequestModal from "./modals/RequestModal";
|
import RequestModal from "./modals/RequestModal";
|
||||||
import PairingModal from "./modals/PairingModal";
|
import PairingModal from "./modals/PairingModal";
|
||||||
@ -99,7 +94,40 @@ export default function App() {
|
|||||||
if (!web3Provider) {
|
if (!web3Provider) {
|
||||||
throw new Error("web3Provider not connected");
|
throw new Error("web3Provider not connected");
|
||||||
}
|
}
|
||||||
const message = JSON.stringify(eip712.example);
|
|
||||||
|
const typedData = {
|
||||||
|
types: {
|
||||||
|
Person: [
|
||||||
|
{ name: "name", type: "string" },
|
||||||
|
{ name: "wallet", type: "address" },
|
||||||
|
],
|
||||||
|
Mail: [
|
||||||
|
{ name: "from", type: "Person" },
|
||||||
|
{ name: "to", type: "Person" },
|
||||||
|
{ name: "contents", type: "string" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
primaryType: "Mail",
|
||||||
|
domain: {
|
||||||
|
name: "Ether Mail",
|
||||||
|
version: "1",
|
||||||
|
chainId: 1,
|
||||||
|
verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
|
||||||
|
},
|
||||||
|
message: {
|
||||||
|
from: {
|
||||||
|
name: "Cow",
|
||||||
|
wallet: "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
|
||||||
|
},
|
||||||
|
to: {
|
||||||
|
name: "Bob",
|
||||||
|
wallet: "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB",
|
||||||
|
},
|
||||||
|
contents: "Hello, Bob!",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const message = JSON.stringify(typedData);
|
||||||
|
|
||||||
const address = accounts[0];
|
const address = accounts[0];
|
||||||
|
|
||||||
@ -108,10 +136,13 @@ export default function App() {
|
|||||||
|
|
||||||
// send message
|
// send message
|
||||||
const signature = await web3Provider.send("eth_signTypedData", params);
|
const signature = await web3Provider.send("eth_signTypedData", params);
|
||||||
|
const valid =
|
||||||
|
utils.verifyTypedData(typedData.domain, typedData.types, typedData.message, signature) ===
|
||||||
|
address;
|
||||||
return {
|
return {
|
||||||
method: "eth_signTypedData",
|
method: "eth_signTypedData",
|
||||||
address,
|
address,
|
||||||
valid: true,
|
valid,
|
||||||
result: signature,
|
result: signature,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user