Skip to content

Commit 1c281b7

Browse files
fix prefix oof public key in btc transaction
1 parent 03ca3f0 commit 1c281b7

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

keychain_lib/include/keychain_lib/keychain_commands.hpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,12 @@ struct keychain_command<command_te::sign_trx> : keychain_command_base
565565
s_length++;
566566
s.insert(0, "00");
567567
}
568+
auto pub_key = dev::toPublic(private_key);
569+
std::string prefix;
570+
if (pub_key[dev::Public::size-1]%2)
571+
prefix = "03"; // y - odd
572+
else
573+
prefix = "02"; // y - even
568574
// script_len + signature DER-encoded + pub_key
569575
ss << std::setw(2) << ((int) script_len)
570576
<< std::setw(2) << ((int) pushdata_sig)
@@ -578,7 +584,7 @@ struct keychain_command<command_te::sign_trx> : keychain_command_base
578584
<< s
579585
<< std::setw(2) << ((int) sig_hash_code)
580586
<< std::setw(2) << ((int) pushdata_pubkey)
581-
<< "03"+ dev::toPublic(private_key).hex().substr(0,64);
587+
<< prefix+ pub_key.hex().substr(0,64);
582588
trx += ss.str();
583589
trx += a.end_of_vin;
584590
}

0 commit comments

Comments
 (0)