mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-02-02 09:54:29 +00:00
sign/verify test - not working
This commit is contained in:
parent
84f796be7f
commit
b05742d7f9
@ -123,6 +123,44 @@ bool AppInit(int argc, char* argv[])
|
||||
return fRet;
|
||||
}
|
||||
|
||||
static bool TestCreateSpamMsgTx()
|
||||
{
|
||||
CTransaction txNew;
|
||||
|
||||
txNew.message = CScript() << vector<unsigned char>((const unsigned char*)strSpamMessage.data(), (const unsigned char*)strSpamMessage.data() + strSpamMessage.size());
|
||||
|
||||
CKey key;
|
||||
key.MakeNewKey(true);
|
||||
|
||||
// compute message hash and sign it
|
||||
CHashWriter msgHash(SER_GETHASH, PROTOCOL_VERSION);
|
||||
msgHash << txNew.message;
|
||||
// vchSig is sig(hash(message))
|
||||
vector<unsigned char> vchSig;
|
||||
if (!key.Sign(msgHash.GetHash(), vchSig)) {
|
||||
printf("CreateNewBlock: Failed to sign SpamMessage\n");
|
||||
return false;
|
||||
}
|
||||
CScript signedHash = CScript() << vector<unsigned char>((const unsigned char*)vchSig.data(), (const unsigned char*)vchSig.data() + vchSig.size());
|
||||
printf("CreateSpamMsgTx: msg = %s user = %s hash = %s signedhash = %s\n", txNew.message.ToString().c_str(), strSpamUser.c_str(),
|
||||
msgHash.GetHash().ToString().c_str(), signedHash.ToString().c_str() );
|
||||
// add username and signature
|
||||
txNew.userName = CScript() << vector<unsigned char>((const unsigned char*)strSpamUser.data(), (const unsigned char*)strSpamUser.data() + strSpamUser.size());
|
||||
txNew.userName += signedHash;
|
||||
txNew.pubKey.clear(); // pubKey will be updated to include extranonce
|
||||
txNew.nNonce = 0; // no update needed for spamMessage's nonce.
|
||||
|
||||
std::vector< std::vector<unsigned char> > vData;
|
||||
txNew.userName.ExtractPushData(vData);
|
||||
|
||||
CPubKey pubkey( key.GetPubKey() );
|
||||
printf("Verify: %d VerifyComp: %d\n",
|
||||
pubkey.Verify(msgHash.GetHash(),vData[1]),
|
||||
pubkey.VerifyCompact(msgHash.GetHash(),vData[1]));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
extern void GenesisMiner();
|
||||
extern void noui_connect();
|
||||
int main(int argc, char* argv[])
|
||||
@ -137,6 +175,8 @@ int main(int argc, char* argv[])
|
||||
|
||||
fRet = AppInit(argc, argv);
|
||||
|
||||
TestCreateSpamMsgTx();
|
||||
|
||||
if (fRet && fDaemon)
|
||||
return 0;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user