bool CCryptoKeyStore::AddCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret) { { LOCK(cs_KeyStore); if (!SetCrypted()) return false; mapCryptedKeys[vchPubKey.GetID()] = make_pair(vchPubKey, vchCryptedSecret); } return true; }
void Bip38ToolDialog::on_decryptKeyButton_DEC_clicked() { string strPassphrase = ui->passphraseIn_DEC->text().toStdString(); string strKey = ui->encryptedKeyIn_DEC->text().toStdString(); uint256 privKey; bool fCompressed; if (!BIP38_Decrypt(strPassphrase, strKey, privKey, fCompressed)) { ui->statusLabel_DEC->setStyleSheet("QLabel { color: red; }"); ui->statusLabel_DEC->setText(tr("Failed to decrypt.") + QString(" ") + tr("Please check the key and passphrase and try again.")); return; } key.Set(privKey.begin(), privKey.end(), fCompressed); CPubKey pubKey = key.GetPubKey(); CBitcoinAddress address(pubKey.GetID()); ui->decryptedKeyOut_DEC->setText(QString::fromStdString(CBitcoinSecret(key).ToString())); ui->addressOut_DEC->setText(QString::fromStdString(address.ToString())); }
bool CCryptoKeyStore::AddCryptedKey(const CPubKey &vchPubKey, const std::vector<unsigned char> &vchCryptedSecret) { LOCK(cs_KeyStore); if (!SetCrypted()) { return false; } mapCryptedKeys[vchPubKey.GetID()] = make_pair(vchPubKey, vchCryptedSecret); ImplicitlyLearnRelatedKeyScripts(vchPubKey); return true; }
void CECKey::GetPubKey(CPubKey &pubkey, bool fCompressed) { EC_KEY_set_conv_form(pkey, fCompressed ? POINT_CONVERSION_COMPRESSED : POINT_CONVERSION_UNCOMPRESSED); int nSize = i2o_ECPublicKey(pkey, NULL); assert(nSize); assert(nSize <= 65); unsigned char c[65]; unsigned char *pbegin = c; int nSize2 = i2o_ECPublicKey(pkey, &pbegin); assert(nSize == nSize2); pubkey.Set(&c[0], &c[nSize]); }
Value createwalletuser(const Array& params, bool fHelp) { if (fHelp || (params.size() != 1 && params.size() != 2)) throw runtime_error( "createwalletuser <username> [replacekey]\n" "Create a new key pair for user and add it to wallet\n" "Use sendnewusertransaction to publish it to the network.\n" "Returns key secret (keep it safe)"); EnsureWalletIsUnlocked(); string strUsername = params[0].get_str(); bool replaceKey = false; if (params.size() > 1) replaceKey = params[1].get_bool(); CKeyID keyID; bool keyInWallet = pwalletMain->GetKeyIdFromUsername(strUsername, keyID); if( keyInWallet && !replaceKey ) throw JSONRPCError(RPC_WALLET_INVALID_ACCOUNT_NAME, "Error: this username exists in wallet"); if( !keyInWallet && replaceKey ) throw JSONRPCError(RPC_WALLET_INVALID_ACCOUNT_NAME, "Error: replacekey given but old key not in wallet"); CTransaction txOut; uint256 hashBlock; if( GetTransaction(strUsername, txOut, hashBlock) && !replaceKey ) throw JSONRPCError(RPC_WALLET_INVALID_ACCOUNT_NAME, "Error: this username exists in tx database"); if( replaceKey && !pwalletMain->MoveKeyForReplacement(strUsername) ) throw JSONRPCError(RPC_WALLET_ERROR, "Error: moving key for replacement"); // Generate a new key that is added to wallet CPubKey newKey = pwalletMain->GenerateNewKey(strUsername); keyID = newKey.GetID(); CKey vchSecret; if (!pwalletMain->GetKey(keyID, vchSecret)) throw JSONRPCError(RPC_WALLET_ERROR, "Error: could not obtain just created privkey?!"); return CBitcoinSecret(vchSecret).ToString(); }
BOOST_FOREACH(const COutput& out, vOutputs) { // unselect already spent, very unlikely scenario, this could happen // when selected are spent elsewhere, like rpc or another computer uint256 txhash = out.tx->GetHash(); COutPoint outpt(txhash, out.i); if (model->isSpent(outpt)) { coinControl->UnSelect(outpt); continue; } // Quantity nQuantity++; // Amount nAmount += out.tx->tx->vout[out.i].nValue; // Priority dPriorityInputs += (double)out.tx->tx->vout[out.i].nValue * (out.nDepth+1); // Bytes CTxDestination address; if(ExtractDestination(out.tx->tx->vout[out.i].scriptPubKey, address)) { CPubKey pubkey; CKeyID *keyid = boost::get<CKeyID>(&address); if (keyid && model->getPubKey(*keyid, pubkey)) { nBytesInputs += (pubkey.IsCompressed() ? 148 : 180); if (!pubkey.IsCompressed()) nQuantityUncompressed++; } else nBytesInputs += 148; // in all error cases, simply assume 148 here } else nBytesInputs += 148; // Add inputs to calculate InstantSend Fee later if(coinControl->fUseInstantSend) txDummy.vin.push_back(CTxIn()); }
Value getnewaddress(const Array& params, bool fHelp) { if (fHelp || params.size() > 1) throw runtime_error( "getnewaddress (\"IsMiner\")\n" "\nget a new address\n" "\nArguments:\n" "1. \"IsMiner\" (bool, optional) private key Is used for miner if true will create tow key ,another for miner.\n" "\nExamples:\n" + HelpExampleCli("getnewaddress", "") + HelpExampleCli("getnewaddress", "true") ); EnsureWalletIsUnlocked(); CKey mCkey; mCkey.MakeNewKey(); CKey Minter; bool IsForMiner = false; if (params.size() == 1) { RPCTypeCheck(params, list_of(bool_type)); Minter.MakeNewKey(); IsForMiner = params[0].get_bool(); } CPubKey newKey = mCkey.GetPubKey(); CKeyID keyID = newKey.GetKeyID(); if (IsForMiner) { if (!pwalletMain->AddKey(mCkey, Minter)) throw runtime_error("add key failed "); } else if (!pwalletMain->AddKey(mCkey)) { throw runtime_error("add key failed "); } Object obj; obj.push_back(Pair("addr", keyID.ToAddress())); obj.push_back(Pair("minerpubkey", IsForMiner?Minter.GetPubKey().ToString(): "no" )); return obj; }
bool CCryptoKeyStore::AddKey(const CKey& key) { { LOCK(cs_KeyStore); if (!IsCrypted()) return CBasicKeyStore::AddKey(key); if (IsLocked()) return false; std::vector<unsigned char> vchCryptedSecret; CPubKey vchPubKey = key.GetPubKey(); bool fCompressed; if (!EncryptSecret(vMasterKey, key.GetSecret(fCompressed), vchPubKey.GetHash(), vchCryptedSecret)) return false; if (!AddCryptedKey(key.GetPubKey(), vchCryptedSecret)) return false; } return true; }
bool CCryptoKeyStore::EncryptKeys(CKeyingMaterial& vMasterKeyIn) { LOCK(cs_KeyStore); if (!mapCryptedKeys.empty() || IsCrypted()) return false; fUseCrypto = true; for (KeyMap::value_type& mKey : mapKeys) { const CKey &key = mKey.second; CPubKey vchPubKey = key.GetPubKey(); CKeyingMaterial vchSecret(key.begin(), key.end()); std::vector<unsigned char> vchCryptedSecret; if (!EncryptSecret(vMasterKeyIn, vchSecret, vchPubKey.GetHash(), vchCryptedSecret)) return false; if (!AddCryptedKey(vchPubKey, vchCryptedSecret)) return false; } mapKeys.clear(); return true; }
Value getdefaultuser(const Array& params, bool fHelp) { if (fHelp || params.size() != 0) throw runtime_error( "getdefaultuser\n" "Get default user being used"); EnsureWalletIsUnlocked(); CPubKey vchPubKey = pwalletMain->vchDefaultKey; if( !vchPubKey.IsValid() ) throw JSONRPCError(RPC_WALLET_ERROR, "Error: default user key is invalid"); CKeyID keyID = vchPubKey.GetID(); std::string username; if( !pwalletMain->GetUsernameFromKeyId(keyID, username) ) throw JSONRPCError(RPC_WALLET_ERROR, "Error converting keyID to username"); return username; }
bool CActiveMasternode::Register(CTxIn vin, CService service, CKey keyCollateralAddress, CPubKey pubKeyCollateralAddress, CKey keyMasternode, CPubKey pubKeyMasternode, CScript rewardAddress, int rewardPercentage, std::string &retErrorMessage) { std::string errorMessage; std::vector<unsigned char> vchMasterNodeSignature; std::string strMasterNodeSignMessage; int64_t masterNodeSignatureTime = GetAdjustedTime(); std::string vchPubKey(pubKeyCollateralAddress.begin(), pubKeyCollateralAddress.end()); std::string vchPubKey2(pubKeyMasternode.begin(), pubKeyMasternode.end()); std::string strMessage = service.ToString() + boost::lexical_cast<std::string>(masterNodeSignatureTime) + vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(PROTOCOL_VERSION) + rewardAddress.ToString() + boost::lexical_cast<std::string>(rewardPercentage); if(!darkSendSigner.SignMessage(strMessage, errorMessage, vchMasterNodeSignature, keyCollateralAddress)) { retErrorMessage = "sign message failed: " + errorMessage; LogPrintf("CActiveMasternode::Register() - Error: %s\n", retErrorMessage.c_str()); return false; } if(!darkSendSigner.VerifyMessage(pubKeyCollateralAddress, vchMasterNodeSignature, strMessage, errorMessage)) { retErrorMessage = "Verify message failed: " + errorMessage; LogPrintf("CActiveMasternode::Register() - Error: %s\n", retErrorMessage.c_str()); return false; } CMasternode* pmn = mnodeman.Find(vin); if(pmn == NULL) { LogPrintf("CActiveMasternode::Register() - Adding to masternode list service: %s - vin: %s\n", service.ToString().c_str(), vin.ToString().c_str()); CMasternode mn(service, vin, pubKeyCollateralAddress, vchMasterNodeSignature, masterNodeSignatureTime, pubKeyMasternode, PROTOCOL_VERSION, rewardAddress, rewardPercentage); mn.ChangeNodeStatus(false); mn.UpdateLastSeen(masterNodeSignatureTime); mnodeman.Add(mn); } //send to all peers LogPrintf("CActiveMasternode::Register() - RelayElectionEntry vin = %s\n", vin.ToString().c_str()); mnodeman.RelayMasternodeEntry(vin, service, vchMasterNodeSignature, masterNodeSignatureTime, pubKeyCollateralAddress, pubKeyMasternode, -1, -1, masterNodeSignatureTime, PROTOCOL_VERSION, rewardAddress, rewardPercentage); return true; }
bool MessageModel::getAddressOrPubkey(QString &address, QString &pubkey) const { CBitcoinAddress addressParsed(address.toStdString()); if(addressParsed.IsValid()) { CKeyID destinationAddress; CPubKey destinationKey; addressParsed.GetKeyID(destinationAddress); if (SecureMsgGetStoredKey(destinationAddress, destinationKey) != 0 && SecureMsgGetLocalKey(destinationAddress, destinationKey) != 0) // test if it's a local key return false; address = destinationAddress.ToString().c_str(); pubkey = EncodeBase58(destinationKey.Raw()).c_str(); return true; } return false; }
bool CActiveBlanknode::Register(CTxIn vin, CService service, CKey keyCollateralAddress, CPubKey pubKeyCollateralAddress, CKey keyBlanknode, CPubKey pubKeyBlanknode, CScript donationAddress, int donationPercentage, std::string &retErrorMessage) { std::string errorMessage; std::vector<unsigned char> vchBlankNodeSignature; std::string strBlankNodeSignMessage; int64_t blankNodeSignatureTime = GetAdjustedTime(); std::string vchPubKey(pubKeyCollateralAddress.begin(), pubKeyCollateralAddress.end()); std::string vchPubKey2(pubKeyBlanknode.begin(), pubKeyBlanknode.end()); std::string strMessage = service.ToString() + boost::lexical_cast<std::string>(blankNodeSignatureTime) + vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(PROTOCOL_VERSION) + donationAddress.ToString() + boost::lexical_cast<std::string>(donationPercentage); if(!zeroSendSigner.SignMessage(strMessage, errorMessage, vchBlankNodeSignature, keyCollateralAddress)) { retErrorMessage = "sign message failed: " + errorMessage; LogPrintf("CActiveBlanknode::Register() - Error: %s\n", retErrorMessage.c_str()); return false; } if(!zeroSendSigner.VerifyMessage(pubKeyCollateralAddress, vchBlankNodeSignature, strMessage, errorMessage)) { retErrorMessage = "Verify message failed: " + errorMessage; LogPrintf("CActiveBlanknode::Register() - Error: %s\n", retErrorMessage.c_str()); return false; } CBlanknode* psn = snodeman.Find(vin); if(psn == NULL) { LogPrintf("CActiveBlanknode::Register() - Adding to Blanknode list service: %s - vin: %s\n", service.ToString().c_str(), vin.ToString().c_str()); CBlanknode sn(service, vin, pubKeyCollateralAddress, vchBlankNodeSignature, blankNodeSignatureTime, pubKeyBlanknode, PROTOCOL_VERSION, donationAddress, donationPercentage); sn.UpdateLastSeen(blankNodeSignatureTime); snodeman.Add(sn); } //send to all peers LogPrintf("CActiveBlanknode::Register() - RelayElectionEntry vin = %s\n", vin.ToString().c_str()); snodeman.RelayBlanknodeEntry(vin, service, vchBlankNodeSignature, blankNodeSignatureTime, pubKeyCollateralAddress, pubKeyBlanknode, -1, -1, blankNodeSignatureTime, PROTOCOL_VERSION, donationAddress, donationPercentage); return true; }
static duk_ret_t API__getnewaddress ( duk_context * ctx ) { const char * account; account = duk_require_string ( ctx, 0 ); if (!pwalletMain->IsLocked()) pwalletMain->TopUpKeyPool(); // Generate a new key that is added to wallet CPubKey newKey; if (!pwalletMain->GetKeyFromPool(newKey, false)) duk_error ( ctx, EMEROBOT_ERR_KEYPOOL_RAN_OUT, "Keypool ran out, please call keypoolrefill first" ); CKeyID keyID = newKey.GetID(); pwalletMain->SetAddressBookName ( keyID, account ); duk_push_string ( ctx, CBitcoinAddress(keyID).ToString().c_str() ); return 1; }
void NewAccountDialog::showSyncQr() { WalletModel::UnlockContext ctx(walletModel->requestUnlock()); if (ctx.isValid()) { newAccount = pwalletMain->GenerateNewAccount(ui->newAccountName->text().toStdString(), AccountType::Normal, AccountSubType::Mobi); LOCK(pwalletMain->cs_wallet); { int64_t currentTime = newAccount->getEarliestPossibleCreationTime(); std::string payoutAddress; CReserveKey reservekey(pwalletMain, newAccount, KEYCHAIN_CHANGE); CPubKey vchPubKey; if (!reservekey.GetReservedKey(vchPubKey)) return; payoutAddress = CBitcoinAddress(vchPubKey.GetID()).ToString(); QString qrString = QString::fromStdString("guldensync:" + CBitcoinSecretExt(*newAccount->GetAccountMasterPrivKey()).ToString(QString::number(currentTime).toStdString(), payoutAddress)); ui->scanQRCode->setCode(qrString); disconnect(this, SLOT(showSyncQr())); } } }
bool CCryptoKeyStore::EncryptKeys(CKeyingMaterial& vMasterKeyIn) { { LOCK(cs_KeyStore); if (!mapCryptedKeys.empty() || IsCrypted()) return false; fUseCrypto = true; BOOST_FOREACH(KeyMap::value_type& mKey, mapKeys) { CKey key; if (!key.SetSecret(mKey.second.first, mKey.second.second)) return false; const CPubKey vchPubKey = key.GetPubKey(); std::vector<unsigned char> vchCryptedSecret; bool fCompressed; if (!EncryptSecret(vMasterKeyIn, key.GetSecret(fCompressed), vchPubKey.GetHash(), vchCryptedSecret)) return false; if (!AddCryptedKey(vchPubKey, vchCryptedSecret)) return false; } mapKeys.clear(); }
bool CMasternodeBroadcast::Create(CTxIn txin, CService service, CKey keyCollateralAddressNew, CPubKey pubKeyCollateralAddressNew, CKey keyMasternodeNew, CPubKey pubKeyMasternodeNew, std::string& strErrorRet, CMasternodeBroadcast& mnbRet) { // wait for reindex and/or import to finish if (fImporting || fReindex) return false; LogPrint("masternode", "CMasternodeBroadcast::Create -- pubKeyCollateralAddressNew = %s, pubKeyMasternodeNew.GetID() = %s\n", CBitcoinAddress(pubKeyCollateralAddressNew.GetID()).ToString(), pubKeyMasternodeNew.GetID().ToString()); CMasternodePing mnp(txin); if (!mnp.Sign(keyMasternodeNew, pubKeyMasternodeNew)) { strErrorRet = strprintf("Failed to sign ping, masternode=%s", txin.prevout.ToStringShort()); LogPrintf("CMasternodeBroadcast::Create -- %s\n", strErrorRet); mnbRet = CMasternodeBroadcast(); return false; } mnbRet = CMasternodeBroadcast(service, txin, pubKeyCollateralAddressNew, pubKeyMasternodeNew, PROTOCOL_VERSION); if (!mnbRet.IsValidNetAddr()) { strErrorRet = strprintf("Invalid IP address, masternode=%s", txin.prevout.ToStringShort()); LogPrintf("CMasternodeBroadcast::Create -- %s\n", strErrorRet); mnbRet = CMasternodeBroadcast(); return false; } mnbRet.lastPing = mnp; if (!mnbRet.Sign(keyCollateralAddressNew)) { strErrorRet = strprintf("Failed to sign broadcast, masternode=%s", txin.prevout.ToStringShort()); LogPrintf("CMasternodeBroadcast::Create -- %s\n", strErrorRet); mnbRet = CMasternodeBroadcast(); return false; } return true; }
void CBasicKeyStore::ImplicitlyLearnRelatedKeyScripts(const CPubKey& pubkey) { AssertLockHeld(cs_KeyStore); CKeyID key_id = pubkey.GetID(); // We must actually know about this key already. assert(HaveKey(key_id) || mapWatchKeys.count(key_id)); // This adds the redeemscripts necessary to detect P2WPKH and P2SH-P2WPKH // outputs. Technically P2WPKH outputs don't have a redeemscript to be // spent. However, our current IsMine logic requires the corresponding // P2SH-P2WPKH redeemscript to be present in the wallet in order to accept // payment even to P2WPKH outputs. // Also note that having superfluous scripts in the keystore never hurts. // They're only used to guide recursion in signing and IsMine logic - if // a script is present but we can't do anything with it, it has no effect. // "Implicitly" refers to fact that scripts are derived automatically from // existing keys, and are present in memory, even without being explicitly // loaded (e.g. from a file). if (pubkey.IsCompressed()) { CScript script = GetScriptForDestination(WitnessV0KeyHash(key_id)); // This does not use AddCScript, as it may be overridden. CScriptID id(script); mapScripts[id] = std::move(script); } }
static bool ExtractPubKey(const CScript &dest, CPubKey& pubKeyOut) { //TODO: Use Solver to extract this? CScript::const_iterator pc = dest.begin(); opcodetype opcode; std::vector<unsigned char> vch; if (!dest.GetOp(pc, opcode, vch) || vch.size() < 33 || vch.size() > 65) return false; pubKeyOut = CPubKey(vch); if (!pubKeyOut.IsFullyValid()) return false; if (!dest.GetOp(pc, opcode, vch) || opcode != OP_CHECKSIG || dest.GetOp(pc, opcode, vch)) return false; return true; }
BOOST_FOREACH(const COutput& out, vOutputs) { // Quantity nQuantity++; // Amount nAmount += out.tx->vout[out.i].nValue; // Priority dPriorityInputs += (double)out.tx->vout[out.i].nValue * (out.nDepth+1); // Bytes CTxDestination address; if(ExtractDestination(out.tx->vout[out.i].scriptPubKey, address)) { CPubKey pubkey; CKeyID *keyid = boost::get< CKeyID >(&address); if (keyid && model->getPubKey(*keyid, pubkey)) nBytesInputs += (pubkey.IsCompressed() ? 148 : 180); else nBytesInputs += 148; // in all error cases, simply assume 148 here } else nBytesInputs += 148; }
static bool CreateSig(const BaseSignatureCreator& creator, SignatureData& sigdata, const SigningProvider& provider, std::vector<unsigned char>& sig_out, const CPubKey& pubkey, const CScript& scriptcode, SigVersion sigversion) { CKeyID keyid = pubkey.GetID(); const auto it = sigdata.signatures.find(keyid); if (it != sigdata.signatures.end()) { sig_out = it->second.second; return true; } sigdata.misc_pubkeys.emplace(keyid, pubkey); if (creator.CreateSig(provider, sig_out, keyid, scriptcode, sigversion)) { auto i = sigdata.signatures.emplace(keyid, SigPair(pubkey, sig_out)); assert(i.second); return true; } return false; }
Value verifymessage(const Array& params, bool fHelp) { if (fHelp || params.size() != 3) throw runtime_error( "verifymessage <username> <signature> <message>\n" "Verify a signed message"); string strUsername = params[0].get_str(); string strSign = params[1].get_str(); string strMessage = params[2].get_str(); CPubKey pubkey; { CKeyID keyID; if( pwalletMain->GetKeyIdFromUsername(strUsername, keyID) ) { if( !pwalletMain->GetPubKey(keyID, pubkey) ) throw JSONRPCError(RPC_WALLET_INVALID_ACCOUNT_NAME, "Error: failed to read pubkey from wallet"); } } if( !pubkey.IsValid() ) { CTransaction txOut; uint256 hashBlock; if( !GetTransaction(strUsername, txOut, hashBlock) ) throw JSONRPCError(RPC_WALLET_INVALID_ACCOUNT_NAME, "Error: this username does not exist in tx database"); std::vector< std::vector<unsigned char> > vData; if( !txOut.pubKey.ExtractPushData(vData) || vData.size() < 1 ) throw JSONRPCError(RPC_INTERNAL_ERROR, "Error: error extracting pubkey from tx"); pubkey = CPubKey(vData[0]); if( !pubkey.IsValid() ) throw JSONRPCError(RPC_INTERNAL_ERROR, "Error: invalid pubkey data from tx"); } bool fInvalid = false; vector<unsigned char> vchSig = DecodeBase64(strSign.c_str(), &fInvalid); if (fInvalid) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Malformed base64 encoding"); CHashWriter ss(SER_GETHASH, 0); ss << strMessageMagic; ss << strMessage; CPubKey pubkeyRec; if (!pubkeyRec.RecoverCompact(ss.GetHash(), vchSig)) return false; return (pubkeyRec.GetID() == pubkey.GetID()); }
bool CCryptoKeyStore::AddKeyPubKey(const CKey& key, const CPubKey &pubkey) { { LOCK(cs_KeyStore); if (!IsCrypted()) return CBasicKeyStore::AddKeyPubKey(key, pubkey); if (IsLocked()) return false; std::vector<unsigned char> vchCryptedSecret; CKeyingMaterial vchSecret(key.begin(), key.end()); if (!EncryptSecret(vMasterKey, vchSecret, pubkey.GetHash(), vchCryptedSecret)) return false; // -- NOTE: this is CWallet::AddCryptedKey if (!AddCryptedKey(pubkey, vchCryptedSecret)) return false; } return true; }
static bool GetPubKey(const SigningProvider& provider, SignatureData& sigdata, const CKeyID& address, CPubKey& pubkey) { if (provider.GetPubKey(address, pubkey)) { sigdata.misc_pubkeys.emplace(pubkey.GetID(), pubkey); return true; } // Look for pubkey in all partial sigs const auto it = sigdata.signatures.find(address); if (it != sigdata.signatures.end()) { pubkey = it->second.first; return true; } // Look for pubkey in pubkey list const auto& pk_it = sigdata.misc_pubkeys.find(address); if (pk_it != sigdata.misc_pubkeys.end()) { pubkey = pk_it->second; return true; } return false; }
bool CAccountHD::AddKeyPubKey(int64_t HDKeyIndex, const CPubKey &pubkey, int keyChain) { if(keyChain == KEYCHAIN_EXTERNAL) return externalKeyStore.AddKeyPubKey(HDKeyIndex, pubkey); else { // Add public key with null private key - we later write the private key IFF it is used in a witnessing operation if (IsPoW2Witness()) { CKey nullKey; //fixme: (2.1) This is possibly a bit inefficient - see if it can be sped up. if(!internalKeyStore.HaveKey(pubkey.GetID())) { if(!internalKeyStore.AddKeyPubKey(nullKey, pubkey)) { throw std::runtime_error("CAccountHD::AddKeyPubKey failed to store witness key."); } } } return internalKeyStore.AddKeyPubKey(HDKeyIndex, pubkey); } }
bool CHashSigner::VerifyHash(const uint256& hash, const CPubKey pubkey, const std::vector<unsigned char>& vchSig, std::string& strErrorRet) { CPubKey pubkeyFromSig; if(!pubkeyFromSig.RecoverCompact(hash, vchSig)) { strErrorRet = "Error recovering public key."; return false; } if(pubkeyFromSig.GetID() != pubkey.GetID()) { strErrorRet = strprintf("Keys don't match: pubkey=%s, pubkeyFromSig=%s, hash=%s, vchSig=%s", pubkey.GetID().ToString(), pubkeyFromSig.GetID().ToString(), hash.ToString(), EncodeBase64(&vchSig[0], vchSig.size())); return false; } return true; }
bool CGovernanceObject::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode) { std::string strError; std::string strMessage = GetSignatureMessage(); LOCK(cs); if(!CMessageSigner::SignMessage(strMessage, vchSig, keyMasternode)) { LogPrintf("CGovernanceObject::Sign -- SignMessage() failed\n"); return false; } if(!CMessageSigner::VerifyMessage(pubKeyMasternode, vchSig, strMessage, strError)) { LogPrintf("CGovernanceObject::Sign -- VerifyMessage() failed, error: %s\n", strError); return false; } LogPrint("gobject", "CGovernanceObject::Sign -- pubkey id = %s, vin = %s\n", pubKeyMasternode.GetID().ToString(), vinMasternode.prevout.ToStringShort()); return true; }
bool CommunicationProtocol::unwindMessageAndParticipants( CMessage const & _message , CMessage & _originalMessage , int64_t const _time , CPubKey const & _pubKey , std::set< CPubKey > & _participants ) { if ( _time < _message.m_header.m_time ) { // this should be serviced in special way // clock of nodes may be not synchronized // return false; } if ( _message.m_header.m_payloadKind != CPayloadKind::IntroductionReq ) { uint256 messageHash = Hash( &_message.m_payload.front(), &_message.m_payload.back() ); if ( !_pubKey.Verify(messageHash, _message.m_header.m_signedHash ) ) return false; } _participants.insert( _pubKey ); if( _message.m_header.m_prevKey.IsValid() ) { CMessage message; readPayload( _message.m_payload, message ); return unwindMessageAndParticipants( message, _originalMessage, _message.m_header.m_time, _message.m_header.m_prevKey, _participants ); } _originalMessage = _message; //_payload =*(Payload *)_message.m_payload; return true; }
CScript GetScriptForRawPubKey(const CPubKey& pubKey) { return CScript() << std::vector<unsigned char>(pubKey.begin(), pubKey.end()) << OP_CHECKSIG; }
bool CBasicKeyStore::AddKeyPubKey(const CKey& key, const CPubKey &pubkey) { LOCK(cs_KeyStore); mapKeys[pubkey.GetID()] = key; return true; }