wallet.address is not the address used to sign the message
See original GitHub issueHere is the code to use wallet to sign message and have the signature verified:
let privateKey = "0x8d8073c48cd4ba11c9d659dcb31f3523d13874b7b3d6d31bc0271652f9541ac0"; //32bytes and 64hex
let wallet = new ethers.Wallet(privateKey); // wallet address: 0xc95b6B8Ec0Eee5eBF18E3c519DBdafaE17AD568F
//contract deployed
// The hash we wish to sign and verify
let messageHash = ethers.utils.id(1234);
let messageHashBytes = ethers.utils.arrayify(messageHash)
// Sign the binary data
let flatSig = await wallet.signMessage(messageHashBytes); //<<==wallet is used to sign the message
// For Solidity, we need the expanded-format of a signature
let sig = ethers.utils.splitSignature(flatSig);
// Call the verifyHash function
let recovered = await contract.signedMsg(contract.address, sig.v, sig.r, sig.s, 1234); //signedMsg is contract function returns signer information
let recoveredWait = await recovered.wait();
console.log("Address recovered : ", recoveredWait.from == signerAddress); //<<==true
Here is the code for signerAddress
:
let url = "http://localhost:8545";
const provider = new ethers.providers.JsonRpcProvider(url);
const signer = provider.getSigner(); //forJsonRPC
let signerAddress = await signer.getAddress(); //<<==signer address: 0x7FdACa197B9D149F8BA75a6b7bbba8959b157135
Here the wallet is used to sign the message. But why the signer address returned by contract is not the wallet address? What is the relationship between wallet address and signer address?
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
How do I sign a message with my Bitcoin address?
Message signing is simply proving ownership of your crypto address. Please note that the signing option is not available for all types of...
Read more >How to verify your wallet with 'Message Signing' - Anycoin Direct
You can verify your wallet address by signing a message in your wallet. Via this verification process, you essentially prove that you are...
Read more >4. Keys, Addresses, Wallets - Mastering Bitcoin [Book] - O'Reilly
Finally, we will look at special uses of keys: to sign messages, to prove ownership, and to create vanity addresses and paper wallets....
Read more >How to sign a message with a Bitcoin, Litecoin Address
Open sign message, choose Bitcoin address from your wallet and enter the message you want to sign. Once done click “sign message” to...
Read more >What is a Bitcoin Address and How Do You Sign It?
Short Answer: A Bitcoin address is a unique number that “holds” bitcoin currency. You use the address to receive and send bitcoins.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Adding to the response by @zemse:
Proving a transaction was by you; I recently had someone accidentally send me funds, and they were hoping I’d send the funds back. The signed a message with their e-mail address and request, which I was able to verify came from the same address that sent the funds. So I was able to know that the person I was communicating with was the transaction sender and able to send the funds back.
If you try to sign into CryptoKitties website, they make you sign a message, from which they can determine which kitties you own.
You might want signed message signature of a user when:
msg.sender
is the relayer, which the smart contract might be least interested in. So the relayer includes a message that makes enough sense to smart contract and signature on it. You can checkoutEIP-191
.There are definitely plenty of use cases. These are some that just came to mind