wallet-core icon indicating copy to clipboard operation
wallet-core copied to clipboard

[EVM] Trust Chrome plugin Sign message error.

Open chaichuanfa opened this issue 9 months ago • 0 comments

Describe the bug

Sign raw hex string error, Trust Chrome plugin not decode the message as hex.

To Reproduce

  1. Connect Trust Chrome plugin.
  2. sign a raw hex message, such as await ethereum.request({ method: 'personal_sign', params: ['0xef118d6e46e33a629ee4f53daf4d8d8dc40ce247a3350d74e13fefcf18fa989b', "0x987c798454a752CA2aEfBdec5bB7999f878Fb504"]})
  3. demo code:
import { ethers } from 'ethers';

(async () => {
    // test account
    const mnemonic = 'ribbon awesome cushion sort rack ugly rule valley joke true demand annual';
    const wallet = ethers.Wallet.fromMnemonic(mnemonic);
    const message = '0xef118d6e46e33a629ee4f53daf4d8d8dc40ce247a3350d74e13fefcf18fa989b';
    // Wrong, same result as the trust chrome plugin.
    const wrongSignature = await wallet.signMessage(message);

    // Correct
    const correctSignature = await wallet.signMessage(Buffer.from(message.slice(2), 'hex'));
})();

Expected behavior

When receive the personal_sign params, if the message is raw hex string, wallet need decode the message as hex, and then hash the message follow eip-191.

chaichuanfa avatar May 17 '24 04:05 chaichuanfa