RootSoft / walletconnect-dart-sdk

Open protocol for connecting dApps to mobile wallets with QR code scanning or deep linking.
MIT License
104 stars 61 forks source link

Rainbow Wallet, Trust Wallet personal_sign not displaying signing message #80

Open 0xM4m4n opened 1 year ago

0xM4m4n commented 1 year ago

When using the connector to call personal_sign, everything works when going to metamask however for any other wallet the message that pops up is in an incorrect format leading to a bad signature: image

full signMessage body:

Future<String> _signMessageWithWalletConnect(String message) async {
    if (walletConnectQRCode?.connector.connected == true) {
      try {
        CommonUtils.printWrapped("Message received");
        CommonUtils.printWrapped(message);
        walletConnectQRCode?.openWalletApp();
        EthereumWalletConnectProvider provider =
            EthereumWalletConnectProvider(walletConnectQRCode!.connector);
        //var signature = await provider.signTypeData(address: _session.accounts[0], typedData: { "data": message });
        var hash = keccakUtf8(message);
        var hashstringHex = bytesToHex(hash, include0x: true);
        final hashString = '0x${bytesToHex(hash).toString()}';
        CommonUtils.printWrapped("Hex string");
        CommonUtils.printWrapped(hashstringHex);
        CommonUtils.printWrapped(hashString);
        var signature = await walletConnectQRCode!.connector.sendCustomRequest(
          method: 'personal_sign',
          params: [hashstringHex, _session.accounts[0]],
        );
       // ive tried sending just  'message' variable and same issue
        // var signature = await provider.personalSign(
        //     message: hashstringHex, address: _session.accounts[0].toString().toLowerCase(), password: "");
        CommonUtils.printWrapped(signature);

        _signature = signature;

        return _signature;
      } catch (exp) {
        CommonUtils.printWrapped("Error while signing transaction");
        CommonUtils.printWrapped(exp.toString());
        throw Exception('Error while signing');
      }
    }
    throw Exception('Wallet not connected');
  }
HaoCherHong commented 1 year ago

@0xM4m4n could you check if this PR fixes the issue https://github.com/RootSoft/walletconnect-dart-sdk/pull/95