Skip to content

Problem with ECDSA signatures #1496

Answered by sullof
sullof asked this question in Q&A
Apr 22, 2021 · 1 comments · 4 replies
Discussion options

You must be logged in to vote

I solved it.

I modified the smart contract adding a public function that returns the keccak256 of the abi-encoded params.
This way, the ECDSASign changes as:

  function ECDSASign(ethers, hexPrivateKey, hash) {
    const signingKey = new ethers.utils.SigningKey(hexPrivateKey)
    const signedDigest = signingKey.signDigest(hash)
    return ethers.utils.joinSignature(signedDigest)
  }

I get the hash calling the function in the smart contract as

    hash = await contract.getHash(address, appId, id, timestamp)

instead that using

    const abiEncoded = ethers.utils.defaultAbiCoder.encode(types, values)
    const hash = ethers.utils.keccak256(abiEncoded)

as before.

It is very weird that ether…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@ricmoo
Comment options

@sullof
Comment options

@sullof
Comment options

@sullof
Comment options

Answer selected by sullof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants