1

Ethers.js Version

6.5.1

Describe the Problem

I was trying to test the encrypt and decrypt feature of ethers.js with the public and private keys from the metamask wallet and built a really simple application that will retrieve the public key and encrypt the user's provided string, then decrypt the encrypted message to see if it will go back to the original message. When I clicked on "Decrypt" after initiating decryption, it throws the error saying the user is denying the decryption action. Screen recording attached.

The full code can be found here too: https://github.com/Eric1015/metamask-encrypt-file-example

Asked the same question here as well: https://github.com/ethers-io/ethers.js/issues/4139, also pending answers.

Code Snippet

Here is the code of how I am decrypting the message:

  const decryptMessage = useCallback(
    async (encryptedMessage: string) => {
      const { provider } = state;
      if (provider == null) return;
      const accounts: string[] = await provider.send('eth_requestAccounts', []);
      return await provider.send('eth_decrypt', [
        encryptedMessage,
        accounts[0],
      ]);
    },
    [state]
  );

The provider inside of the state is created in the following manner and stored as state:

      const { ethereum } = window;

      const provider = new ethers.BrowserProvider(ethereum);

Errors

Error: user rejected action (action="unknown", reason="rejected", info={ "error": { "code": -32603, "data": { "originalError": {  } }, "message": "MetaMask DecryptMessage: User denied message decryption." }, "payload": { "id": 9, "jsonrpc": "2.0", "method": "eth_decrypt", "params": [ "cynO2IeYe/weLFuV3/Ec2hhpxFFg5OU=", "<address>" ] } }, code=ACTION_REJECTED, version=6.5.1)

Environment

Ethereum (mainnet/ropsten/rinkeby/goerli)

Environment (Other)

Sepolia

3
  • hey @Eric did you find a solution to this?
    – Nikos Kyr
    Jun 26 at 11:51
  • 1
    No, on the Github side, there was a reply and he told me that this decrypt function of Metamask is gonna be deprecated, so I decided to seek for a different solution such as using the Lit protocol: developer.litprotocol.com
    – Eric
    Jun 27 at 4:24
  • alright, thanks for the hint regarding Lit protocol. I will take a look
    – Nikos Kyr
    Jun 27 at 8:48

1 Answer 1

1

Got the answer for this question on the Github issue side, please refer to this reply in the Github issue for details: https://github.com/ethers-io/ethers.js/issues/4139#issuecomment-1615971987

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.