What I am wrong using only Bitcoin code?
I move source code from key_tests.cpp :
....................
CPubKey pubkey1 = key1. GetPubKey();
CPubKey pubkey2 = key2. GetPubKey();
CPubKey pubkey1C = key1C.GetPubKey();
CPubKey pubkey2C = key2C.GetPubKey();
BOOST_CHECK(key1.VerifyPubKey(pubkey1));
BOOST_CHECK(!key1.VerifyPubKey(pubkey1C));
BOOST_CHECK(!key1.VerifyPubKey(pubkey2));
BOOST_CHECK(!key1.VerifyPubKey(pubkey2C));
....................
and it is OK, but my code:
vector vch;
hashFromString("3f74be6a1fbd15a5e1101c48e7e31b7777c68fb125f143587d19e1e1c157575c", vch);
uint256 hashMsgMy(vch);
CPubKey rkeymy;
std::vector csignmy;
hashFromStringLE("304502205d2cb95368167baa75ff86a36827a732ac1ab4ea5c9f53ebebf1c2ae738cc9db0221009cbec84f5941c7a85a76ef4c617b66a0c52e66e9ec5e8374480521d57a588eb701", csignmy);
BOOST_CHECK(rkeymy.RecoverCompact (hashMsgMy, csignmy));
string str = hashToStringLE(rkeymy.data(), 65);
cout << str <
should be key (33 bytes) 026795b2f312bf34204cd314d06b165ca8bb56702eb5ff27b57acfd7c8051e75d8
but is ff0000007d5671f4de5e3d054859e06f20919cc3d882220266c7a16014560000160000000000000
04d32a26014560000a0f9bcdbff7e0000000000000000000000
Maybe trash in - trash out, hash is bad or signature is bad, but
why in result is so zeros, even if we get first 33 bytes from 65 bytes
note: string str = HexStr(rkeymy.begin(), rkeymy.end()); give me empty string, because size is 0, all 65 bytes are trash
because
bool CPubKey::RecoverCompact(const uint256 &hash, const std::vector& vchSig) {
if (vchSig.size() != COMPACT_SIGNATURE_SIZE)
return false;
Must be 65 not 72 bytes, I again must take a look at changing 72 to 65 bytes
---------------
NOW is without old problems
r = 205d2cb95368167baa75ff86a36827a732ac1ab4ea5c9f53ebebf1c2ae738cc9
s = 009cbec84f5941c7a85a76ef4c617b66a0c52e66e9ec5e8374480521d57a588eb7
but key is 0229364d20762e423fb1d93d1fa05150a2d0277f49feaff924405785de9b6abb4d - look ok,
but I want key 026795b2f312bf34204cd314d06b165ca8bb56702eb5ff27b57acfd7c8051e75d8
What I do wrong?
I give one LTC transaction input.
I give script (thus r and s) give key from script to verify
message to recover script I give hash previous transaction, it is ok?
another:
hash Be 57ad3c7b7ce0654e43ecf7477879c167dcfb079614a1f785a5e87b84823f7d47
signature (71 bytes) 304402200f2f95941a847d5f43d241297e98de0da340cdb4232176be61babd7572b641b30220353
ed805ecda266dfc8ebf56c142239030d3e8be432d3590aeeacfdae15b8abc01
key (33 bytes) 025a76dd6561c1da7be001fa3b7aab0c56496be0230d06c5cd28bdec6ca6a71c85
- can't recover
and other can't recover, only can (with other pubkey than derived fro script)
hash Be 3f74be6a1fbd15a5e1101c48e7e31b7777c68fb125f143587d19e1e1c157575c
signature (72 bytes) 304502205d2cb95368167baa75ff86a36827a732ac1ab4ea5c9f53ebebf1c2ae738cc9db0221009
cbec84f5941c7a85a76ef4c617b66a0c52e66e9ec5e8374480521d57a588eb701
WARNING: only first signature has 32+33 int numbers within, else have 32+32 or 33+33, it is possible?
I call:
myRecover("3f74be6a1fbd15a5e1101c48e7e31b7777c68fb125f143587d19e1e1c157575c",
"304502205d2cb95368167baa75ff86a36827a732ac1ab4ea5c9f53ebebf1c2ae738cc9db0221009cbec84f5941c7a85a76ef4c617b66a0c52e66e9ec5e8374480521d57a588eb701");
myRecover("57ad3c7b7ce0654e43ecf7477879c167dcfb079614a1f785a5e87b84823f7d47",
"304402200f2f95941a847d5f43d241297e98de0da340cdb4232176be61babd7572b641b30220353ed805ecda266dfc8ebf56c142239030d3e8be432d3590aeeacfdae15b8abc01");
myRecover("ae18beb79e3f3f61f080a6a6e4ad793f4557b1a4c0f2bd03bbe0f581916ff24a",
"3046022100f4d66692601dca84a67c4115affbce4824d02b602197c03f931ae8d5e41fa50c022100b7926308754801fcaacb0a961ebac249b4e4415185df022dae807b3385067d5401");
where
void myRecover(string hashStr, string signatureStr) {
vector script, signature;
hashFromStringLE(signatureStr.c_str(), signature);
vector rnumber, snumber;
decodeSignature(signature, rnumber, snumber);
printf("%d %d\n", rnumber.size(), snumber.size());
decodeSignature(signature, rnumber, snumber);
string str = hashToStringLE(rnumber);
printf("r = %s\n", str.c_str());
str = hashToStringLE(snumber);
printf("s = %s\n", str.c_str());
vector vchSig = rnumber;
vchSig.insert(vchSig.end(), snumber.begin(), snumber.end());
vector vch;
hashFromString(hashStr.c_str(), vch);
uint256 hashMsgMy(vch);
CPubKey rkeymy;
printf("%d\n", rkeymy.RecoverCompact(hashMsgMy, vchSig));
str = HexStr(rkeymy.begin(), rkeymy.end());
cout << str << endl;
}