0

On the client we are using ethers:

const signingKey = new ethers.utils.SigningKey(privateKey)

const message = Date.now()
const messageBytes = ethers.utils.toUtf8Bytes(String(message))
const messageDigest = ethers.utils.keccak256(messageBytes)
let signature = signingKey.signDigest(messageDigest)

Send message & signature to backend:

signature object:

  // signature Object {
  //   "r": "0x5bd1ed8f608f3b5a9927423a8a4e754325b0de4bd6ab66b6a414d98a471defea",
  //   "recoveryParam": 0,
  //   "s": "0x3560058f8b06eb4614e8588e932986bd7c41dd6552aa41689a0f63bd393fd461",
  //   "v": 27,
  // }

Backend:

const recoverAddress = async (message, signature) => {  
  const messageHash = await web3.eth.accounts.hashMessage(String(message))

  let signatureObject = {
    messageHash: messageHash,
    v: Web3.utils.toHex(signature.v), //27 in hex
    r: String(signature.r),
    s: String(signature.s)
  }

  return web3.eth.accounts.recover(signatureObject)
}

But the returned address does not equal the original wallet address. In fact, it changes every time I run it.

Is it possible even to do this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.