espresso-cash-public icon indicating copy to clipboard operation
espresso-cash-public copied to clipboard

generate only signature with json format tx transaction

Open minemos opened this issue 1 year ago • 2 comments

Is your feature request related to a problem? Please describe.

I am using wallet connect v2 and when transaction sign request received, it give me json format transactions.

{
    "id": 1,
    "jsonrpc": "2.0",
    "method": "solana_signTransaction",
    "params": {
        "feePayer": "AqP3MyNwDP4L1GJKYhzmaAUdrjzpqJUZjahM7kHpgavm",
        "instructions": [{
            "programId": "Vote111111111111111111111111111111111111111",
            "data": "37u9WtQpcm6ULa3VtWDFAWoQc1hUvybPrA3dtx99tgHvvcE7pKRZjuGmn7VX2tC3JmYDYGG7",
            "keys": [{
                "isSigner": true,
                "isWritable": true,
                "pubkey": "AqP3MyNwDP4L1GJKYhzmaAUdrjzpqJUZjahM7kHpgavm"
            }]
        }],
        "recentBlockhash": "2bUz6wu3axM8cDDncLB5chWuZaoscSjnoMD2nVvC1swe",
        "signatures": [{
            "pubkey": "AqP3MyNwDP4L1GJKYhzmaAUdrjzpqJUZjahM7kHpgavm",
            "signature": "2Lb1KQHWfbV3pWMqXZveFWqneSyhH95YsgCENRWnArSkLydjN1M42oB82zSd6BBdGkM9pE6sQLQf1gyBh8KWM2c4"
        }]
    }
}

I have to response signature, but I can't find how to do that.

I tried many things, but noting worked. Still singnature verify Failed

// this cause RangeError (byteOffset): Index out of range: index should be less than 3199: 3199
SignedTx.fromBytes(utf8.encode(jsonEncode(parameters))).toString()
// this cause verify Failed
final instructionsJson = parameters['instructions'] as List<dynamic>;
        final instructions = instructionsJson.map((json) {
          return Instruction(
              programId: Ed25519HDPublicKey.fromBase58(json['programId']),
              accounts: json['key'].runtimeType == List
                  ? (json['key'] as List<Map<String, dynamic>>)
                      .map((e) => AccountMeta(
                          pubKey: Ed25519HDPublicKey.fromBase58(e['pubKey']),
                          isWriteable: e['isWriteable'],
                          isSigner: e['isSigner']))
                      .toList()
                  : [],
              data: ByteArray.fromString(jsonEncode(json['data'])));
        }).toList();

        final message = Message(instructions: instructions);
        final compiledMessage = message.compile(
            recentBlockhash: parameters['recentBlockhash'],
            feePayer: Ed25519HDPublicKey.fromBase58(parameters['feePayer']));

        Signature sign = await wallet.sign(compiledMessage.toByteArray());

Describe the solution you'd like A clear and concise description of what you want to happen.

I want to generate signature from json format transaction

minemos avatar Apr 25 '23 04:04 minemos

Any updates? have the same problem

elvinasn avatar Jan 31 '24 23:01 elvinasn

Hello @minemos @elvinasn! I hope I am not coming late to the party. I'm working on Supporting Solana (along with other chains on WalletConnectFlutterV2 sample wallet and I'm handling your scenario. It's a long shot but in case you are still seeking for help here it is the draft PR https://github.com/WalletConnect/WalletConnectFlutterV2/pull/289/files You'll be interested mainly in example/wallet/lib/dependencies/chains/solana_service.dart

quetool avatar May 21 '24 18:05 quetool