Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.verifyMessage returning incorrect address #2144

Closed
adriandelgg opened this issue Oct 8, 2021 · 4 comments
Closed

.verifyMessage returning incorrect address #2144

adriandelgg opened this issue Oct 8, 2021 · 4 comments

Comments

@adriandelgg
Copy link

I'm using WalletLink to connect the Coinbase Wallet to my front end. I want to sign a message using Ethers.js & then verify it. Whenever I verify it, it sends back a completely different wallet address than the one I signed with. Does anyone know why that's happening?

const walletLink = new Walletlink({
  appName: 'Climate DAO',
  appLogoUrl: 'https://example.com/logo.png',
  darkMode: false
 });

  // // Initialize a Web3 Provider object
const ethereum = walletLink.makeWeb3Provider(ETH_JSONRPC_URL, CHAIN_ID);
const provider = new Web3Provider(ethereum);

const [account] = await ethereum.send('eth_requestAccounts');
const signer = provider.getSigner(
  account
);
// Returns 0x9977593c73566afE015BEfF0a3ea06Cf521763D8
const signerAddress = await signer.getAddress();

const signature = await signer.signMessage('hi');

//Returns 0xB273a7eE4B4cEc95954a6f004C631626a2a2198f
const address = verifyMessage('hi', signature);

Full code here if needed

import Walletlink from 'walletlink';
import { Web3Provider } from '@ethersproject/providers';
import { verifyMessage } from '@ethersproject/wallet';
import { ethers } from 'ethers';

const ETH_JSONRPC_URL = process.env.NEXT_PUBLIC_RINKEBY_API_KEY;
const CHAIN_ID = 3;

const CoinBase = () => {
	async function enableCoinBase() {
		const walletLink = new Walletlink({
			appName: 'Climate DAO',
			appLogoUrl: 'https://example.com/logo.png',
			darkMode: false
		});

		// // Initialize a Web3 Provider object
		const ethereum = walletLink.makeWeb3Provider(ETH_JSONRPC_URL, CHAIN_ID);
		const provider = new Web3Provider(ethereum);

		const [account] = await ethereum.send('eth_requestAccounts');
		const signer = provider.getSigner(
			// '0x9977593c73566afE015BEfF0a3ea06Cf521763D8'
			account
		);
		console.log(signer);
		const signerAddress = await signer.getAddress();
		console.log(signerAddress);
		const coinbaseAddress = '0x9977593c73566afE015BEfF0a3ea06Cf521763D8';
		console.log(signerAddress === coinbaseAddress);

		try {
			// const messageBytes = ethers.utils.arrayify('hi');
			const signature = await signer.signMessage('hi');
			console.log(signature);
			const address = verifyMessage('hi', signature);
			// const addressBytes = verifyMessage(messageBytes, signature);
			console.log(address);
			// console.log(addressBytes);

			console.log(address.toLowerCase() === signerAddress.toLowerCase());
			// console.log(addressBytes.toLowerCase() === signerAddress.toLowerCase());
		} catch (e) {
			console.log(e);
		}
	}

	return <button onClick={enableCoinBase}>Enable Coinbase</button>;
};
@adriandelgg adriandelgg added the investigate Under investigation and may be a bug. label Oct 8, 2021
@zemse
Copy link
Collaborator

zemse commented Oct 8, 2021

Related issues #491 #1840

@adriandelgg
Copy link
Author

Related issues #491 #1840

Thank you! #491 was able to fix my issue.

@ricmoo ricmoo removed the investigate Under investigation and may be a bug. label Oct 20, 2021
@L4ZARIN3
Copy link

I also have this problem, have you found the solution?

@adriandelgg
Copy link
Author

I also have this problem, have you found the solution?

#491 solved my problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants