WalletConnectFlutterV2 icon indicating copy to clipboard operation
WalletConnectFlutterV2 copied to clipboard

The signature query obtained after the solana chain sign failed

Open pingko opened this issue 1 year ago • 3 comments

Describe the bug When I listened to the solana_signTransaction method, I signed the message and got the signature. When I called web3Wallet.respondSessionRequest(), there was no error but it prompted "Error: Signature verification failed. Invalid signature for public key [My solana address]. In addition, I could not find this transaction on the solana browser.

To Reproduce Steps to reproduce the behavior:

  1. Process the data when listening to solana_signTransaction. First, base58Decode the saved private key
  2. Get the keypair object and generate the message object
  3. Use Keypair to sign the compiledMessage
  4. Get the signature. After broadcasting it through web3Wallet.respondSessionRequest(), the signature cannot be queried on the blockchain browser. The current dApp page prompts an error message: "Error: Signature verification failed. Invalid signature for public key [My solana address].

Expected behavior Transactions can be queried in the blockchain browser

Reproducible code

Screenshots image

Desktop (please complete the following information): Platform agnostic, doesnt matter which device i test on it allways does the explained issue

Smartphone (please complete the following information): Developing a dApp wallet, Use walletconnectV2Flutter to trade in jito dApp

Additional context

### Tasks

pingko avatar Nov 14 '24 03:11 pingko

use walletconnect_flutter_v2: ^2.4.1

pingko avatar Nov 14 '24 03:11 pingko

Hello @pingko, can you share the code in text format so I can copy/paste it on my side?

Regarding this

In addition, I could not find this transaction on the solana browser.

solana_signTransaction doesn't broadcast the transaction, it only signs it, that's why you don't see it in the explorer. Dapp should use solana_signAndSendTransaction to broadcast it.

quetool avatar Nov 14 '24 08:11 quetool

Hello @quetool ,The code is as follows:

   /// get base58encode seckey from android native code
          String secKeyEncode = await getSignPrivateKey(arguments);
          final secKeyBytes =
              Uint8List.fromList(base58decode(secKeyEncode).sublist(0, 32));
          final keyPair = await Ed25519HDKeyPair.fromPrivateKeyBytes(
            privateKey: secKeyBytes,
          );

          if (keyPair.address != feePayer) {
            debugPrint('address error');
            handleWalletConnectData(response, 'transaction error', topic, false, 'SOL');
            return;
          }

          const encoder = JsonEncoder.withIndent('  ');
          final transaction = encoder.convert(params);
          // Sign the transaction.
          final instructions = instructionsList.map((json) {
            return (json as Map<String, dynamic>).toInstruction();
          }).toList();

          final message = Message(instructions: instructions);
          final compiledMessage = message.compile(
            recentBlockhash: recentBlockHash,
            feePayer: Ed25519HDPublicKey.fromBase58(feePayer),
          );

          final signature = await keyPair.sign(compiledMessage.toByteArray());

          response = response.copyWith(
            result: {
              'signature': signature.toBase58(),
            },
          );
          try {
            await web3Wallet.respondSessionRequest(
              topic: topic,
              response: response,
            );
            print('sign result:${response.result}...$signature');
          } on WalletConnectError catch (error) {
            print('WalletConnectError ${error.message}');
          }

I referred to solanaSignTransaction,However, I did not see the solana_signAndSendTransaction in the solana_service file. In evm_service, I can easily use ethClient.sendTransaction to get signedTx to get the signature. After requesting respondSessionRequest, I can find the signedTx in the blockchain browser.

pingko avatar Nov 14 '24 09:11 pingko