fix(login): fixed token verification

This commit is contained in:
dan13ram
2022-09-30 01:44:29 +05:30
committed by Alec LaLonde
parent 474f976912
commit 2fb2595c3c

View File

@@ -1,5 +1,7 @@
import { Contract, providers, utils } from 'ethers';
const WELCOME_MESSAGE = `Welcome to MetaGame Anon 🐙 \n Please sign this message so we know it is you.\n We care about privacy and assure you, we don't harvest your data. Unless you create a Player account, we simply store a token in your browser's local storage. This can be removed by using the disconnect button.\n `;
export async function getSignature(
provider: providers.Web3Provider,
msg: string,
@@ -9,7 +11,7 @@ export async function getSignature(
const signer = provider.getSigner();
const address = await signer.getAddress();
if (!ethereum.request) throw new Error('No `request` On Ethereum Provider');
const signMsg = `Welcome to MetaGame Anon 🐙 \n Please sign this message so we know it is you.\n We care about privacy and assure you, we don't harvest your data. Unless you create a Player account, we simply store a token in your browser's local storage. This can be removed by using the disconnect button.\n ${msg}`;
const signMsg = `${WELCOME_MESSAGE}${msg}`;
let params = [signMsg, address];
if (extraParams) {
@@ -64,6 +66,9 @@ export async function verifySignature(
): Promise<boolean> {
const walletType = await getWalletType(address, provider);
// eslint-disable-next-line no-param-reassign
message = `${WELCOME_MESSAGE}${message}`;
if (walletType === WalletType.EOA) {
const recoveredAddress = utils.verifyMessage(message, signature);
return address === recoveredAddress;