1

I'm getting Solana transaction signature verification error.

I tried many methods but my result is always same, which is "false"

Below is my code:

let node_client = RpcClient::new("https://api.testnet.solana.com");
let str_sign = String::from("22XnB7pYjqtJXR5NcTR3E8LuA5Lvf7fvZuvbpRvv8u1n5iSApdZiqYu3vXFezZAM9Z7pTHfo7vBX2Nzyc45TcWco");
let signatures = Signature::from_str(&str_sign).unwrap();
println!("{:?}", signatures);
let get_txn = node_client.get_transaction(
    &signatures,
    UiTransactionEncoding::Json,
);

let send = Pubkey::from_str("4ETf86tK7b4W72f27kNLJLgRWi9UfJjgH4koHGUXMFtn").unwrap();
let send1 = Pubkey::from_str("JE9yw76YsXFacrMJEnvVuHmZXYEPSZpjHsW53c6YkYW7").unwrap();

match get_txn.unwrap().transaction.transaction {
    EncodedTransaction::Json(ui_transaction) => {
        // println!("{:?}", ui_transaction.message);
        match ui_transaction.message {
            UiMessage::Raw(raw_msg) => {
                println!("{:?}", raw_msg);
                let ins_test = CompiledInstruction {
                    program_id_index: raw_msg.instructions[0].program_id_index,
                    accounts: raw_msg.instructions[0].accounts.clone(),
                    data: bs58::decode(&raw_msg.instructions[0].data).into_vec().unwrap(),
                };

                let bsdecode = bs58::decode(&raw_msg.instructions[0].data).into_vec().unwrap();

                let bytes = hex::decode("0200000000ca9a3b00000000").unwrap();
                println!("{:?}", bytes);
                println!("{:?}", bsdecode);

                let msg_test = Message::new_with_compiled_instructions(
                    raw_msg.header.num_required_signatures,
                    raw_msg.header.num_readonly_signed_accounts,
                    raw_msg.header.num_readonly_unsigned_accounts,
                    [send, send1].to_vec(),
                    Hash::from_str(&raw_msg.recent_blockhash).unwrap(),
                    [ins_test].to_vec(),
                ).serialize();

                println!("{:?}", msg_test);

                // let msg_test = Message {
                //     header: raw_msg.header,
                //     account_keys: [send, send1].to_vec(),
                //     recent_blockhash: Hash::from_str(&raw_msg.recent_blockhash).unwrap(),
                //     instructions: [ins_test].to_vec(),
                // }.serialize();
                //
                // println!("{:?}", msg_test);

                let okko = signatures.verify(&send.to_bytes(), &msg_test);
                println!("{:?}", okko);
            }
            _ => {
                println!("Transaction MSG is not in JSON format");
            }
        }
    }
    _ => {
        // Handle other cases if needed
        println!("Transaction is not in JSON format");
    }
} }

1 Answer 1

0

code modification to get transaction verification by signature

{
// compile
let mut ins_test: Vec<CompiledInstruction> = Vec::new();
for instruction in raw_msg.instructions {
    let compiled_instruction = CompiledInstruction {
        program_id_index: instruction.program_id_index,
        accounts: instruction.accounts.clone(),
        data: bs58::decode( & instruction.data).into_vec().unwrap(),
    };
    ins_test.push(compiled_instruction); // Add to the vector
}

// account pub key
let accountKey: Vec<Pubkey> = raw_msg.account_keys.iter().map( | x| Pubkey::from_str(x).unwrap()).collect();
let acc_byte = accountKey[0].to_bytes();

// Construct Serialize message
let message = Message::new_with_compiled_instructions(
    raw_msg.header.num_required_signatures,
    raw_msg.header.num_readonly_signed_accounts,
    raw_msg.header.num_readonly_unsigned_accounts,
    accountKey.clone(),
    Hash::from_str( & raw_msg.recent_blockhash).unwrap(),
    ins_test,
).serialize();

// Verify signature
let okko = signatures.verify( & acc_byte, & message);
println!("Signature Verification: {:?}", okko);
}

Your Answer

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

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